Skip to content

Commit

Permalink
Acceptance tests for ww and toggle click
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed Jun 30, 2023
1 parent 534bf39 commit 320fea9
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
1 change: 1 addition & 0 deletions ui/app/templates/components/task-log.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
{{keyboard-shortcut label="Toggle word wrap" action=(action "toggleWrap") pattern=(array "w" "w") menuLevel=true }}
checked={{this.wrapped}}
{{on "change" this.toggleWrap}}
data-test-word-wrap-toggle
as |F|>
<F.Label>Word Wrap</F.Label>
</Hds::Form::Toggle::Field>
Expand Down
76 changes: 75 additions & 1 deletion ui/tests/acceptance/task-logs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
*/

/* eslint-disable qunit/require-expect */
import { click, currentURL, findAll } from '@ember/test-helpers';
import {
click,
currentURL,
findAll,
triggerKeyEvent,
} from '@ember/test-helpers';
import { run } from '@ember/runloop';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
Expand Down Expand Up @@ -69,6 +74,75 @@ module('Acceptance | task logs', function (hooks) {
);
});

test('logs can be word-wrapped', async function (assert) {
await TaskLogs.visit({ id: allocation.id, name: task.name });

assert.dom('[data-test-word-wrap-toggle]').isNotChecked();
assert.dom('[data-test-output]').doesNotHaveClass('wrapped');

run.later(() => {
run.cancelTimers();
}, 100);
await click('[data-test-word-wrap-toggle]');
assert.dom('[data-test-word-wrap-toggle]').isChecked();
assert.dom('[data-test-output]').hasClass('wrapped');

run.later(() => {
run.cancelTimers();
}, 100);
await click('[data-test-word-wrap-toggle]');
assert.dom('[data-test-word-wrap-toggle]').isNotChecked();
assert.dom('[data-test-output]').doesNotHaveClass('wrapped');

window.localStorage.clear();
});

test('logs in sidebar can be word-wrapped', async function (assert) {
await TaskLogs.visitParentJob({
id: job.id,
allocationId: allocation.id,
name: task.name,
});

run.later(() => {
run.cancelTimers();
}, 500);

const taskRow = [
...findAll('.task-sub-row').filter((row) => {
return row.textContent.includes(task.name);
}),
][0];

await click(taskRow.querySelector('button.logs-sidebar-trigger'));

assert.dom('[data-test-word-wrap-toggle]').isNotChecked();
assert.dom('[data-test-output]').doesNotHaveClass('wrapped');

run.later(() => {
run.cancelTimers();
}, 500);

// type "ww" to trigger word wrap
const W_KEY = 87;
triggerKeyEvent('.sidebar', 'keydown', W_KEY);
await triggerKeyEvent('.sidebar', 'keydown', W_KEY);

assert.dom('[data-test-word-wrap-toggle]').isChecked();
assert.dom('[data-test-output]').hasClass('wrapped');

run.later(() => {
run.cancelTimers();
}, 100);

triggerKeyEvent('.sidebar', 'keydown', W_KEY);
await triggerKeyEvent('.sidebar', 'keydown', W_KEY);
assert.dom('[data-test-word-wrap-toggle]').isNotChecked();
assert.dom('[data-test-output]').doesNotHaveClass('wrapped');

window.localStorage.clear();
});

test('logs are accessible in a sidebar context', async function (assert) {
await TaskLogs.visitParentJob({
id: job.id,
Expand Down

0 comments on commit 320fea9

Please sign in to comment.