Skip to content

Commit 8ec02e4

Browse files
committed
updating tests
1 parent 7757124 commit 8ec02e4

File tree

6 files changed

+52
-18
lines changed

6 files changed

+52
-18
lines changed

ui/tests/acceptance/job-definition-test.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: BUSL-1.1
44
*/
55

6-
import { click, currentURL } from '@ember/test-helpers';
6+
import { click, currentURL, waitFor } from '@ember/test-helpers';
77
import percySnapshot from '@percy/ember';
88
import { module, test } from 'qunit';
99
import { setupApplicationTest } from 'ember-qunit';
@@ -99,9 +99,12 @@ module('Acceptance | job definition', function (hooks) {
9999

100100
test('when changes are submitted, the site redirects to the job overview page', async function (assert) {
101101
await Definition.edit();
102+
await waitFor('.cm-editor');
102103

103104
const cm = getCodeMirrorInstance(['data-test-editor']);
104-
cm.setValue(`{}`);
105+
cm.dispatch({
106+
changes: { from: 0, to: cm.state.doc.length, insert: '{}' },
107+
});
105108

106109
await click('[data-test-plan]');
107110
await Definition.editor.run();

ui/tests/acceptance/job-dispatch-test.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import setupCodeMirror from 'nomad-ui/tests/helpers/codemirror';
1313
import JobDispatch from 'nomad-ui/tests/pages/jobs/dispatch';
1414
import JobDetail from 'nomad-ui/tests/pages/jobs/detail';
1515
import a11yAudit from 'nomad-ui/tests/helpers/a11y-audit';
16-
import { currentURL } from '@ember/test-helpers';
16+
import { currentURL, waitFor } from '@ember/test-helpers';
1717

1818
const REQUIRED_INDICATOR = '*';
1919

@@ -201,10 +201,21 @@ function moduleForJobDispatch(title, jobFactory) {
201201
}
202202

203203
await JobDispatch.visit({ id: `${job.id}@${namespace.name}` });
204+
await waitFor('.cm-editor');
205+
206+
const cmEditor = document.querySelector('[data-test-payload-editor]');
207+
const cmEditorInstance = cmEditor.editor;
204208

205209
// Fill form.
206210
JobDispatch.metaFields.map((f) => f.field.input('meta value'));
207-
JobDispatch.payload.editor.fillIn('payload');
211+
212+
cmEditorInstance.dispatch({
213+
changes: {
214+
from: 0,
215+
to: cmEditorInstance.state.doc.length,
216+
insert: 'payload',
217+
},
218+
});
208219

209220
const childrenCountBefore = countDispatchChildren();
210221
await JobDispatch.dispatchButton.click();

ui/tests/acceptance/variables-test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
findAll,
1212
typeIn,
1313
visit,
14+
waitFor,
1415
} from '@ember/test-helpers';
1516
import { setupMirage } from 'ember-cli-mirage/test-support';
1617
import { clickToggle, clickOption } from 'nomad-ui/tests/helpers/helios';
@@ -543,24 +544,27 @@ module('Acceptance | variables', function (hooks) {
543544
assert
544545
.dom('.related-entities-hint')
545546
.exists('Shows a hint about related entities by default');
546-
assert.dom('.CodeMirror').doesNotExist();
547+
assert.dom('.cm-editor').doesNotExist();
548+
547549
await typeIn('[data-test-path-input]', 'nomad/job-templates/hello-world');
548550
assert
549551
.dom('.related-entities-hint')
550552
.doesNotExist('Hides the hint when editing a job template variable');
551553
assert
552554
.dom('[data-test-job-template-hint]')
553555
.exists('Shows a hint about job templates');
556+
557+
await waitFor('.cm-editor');
554558
assert
555-
.dom('.CodeMirror')
559+
.dom('.cm-editor')
556560
.exists('Shows a custom editor for job templates');
557561

558562
document.querySelector('[data-test-path-input]').value = ''; // clear current input
559563
await typeIn('[data-test-path-input]', 'hello-world-non-template');
560564
assert
561565
.dom('.related-entities-hint')
562566
.exists('Shows a hint about related entities by default');
563-
assert.dom('.CodeMirror').doesNotExist();
567+
assert.dom('.cm-editor').doesNotExist();
564568
// Reset Token
565569
window.localStorage.nomadTokenSecret = null;
566570
});

ui/tests/integration/components/scale-events-accordion-test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,8 @@ module('Integration | Component | scale-events-accordion', function (hooks) {
163163
await click('[data-test-accordion-toggle]');
164164
assert.ok(find('[data-test-accordion-body]'));
165165

166-
assert.equal(
167-
getCodeMirrorInstance('[data-test-json-viewer]').getValue(),
168-
JSON.stringify(meta, null, 2)
169-
);
166+
const codeValue = find('[data-test-json-viewer]').textContent;
167+
assert.equal(codeValue.replace(/\s+/g, ''), JSON.stringify(meta));
170168
await componentA11yAudit(this.element, assert);
171169
});
172170
});

ui/tests/integration/components/scale-events-chart-test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ module('Integration | Component | scale-events-chart', function (hooks) {
8686
moment(annotation.time).format('MMM DD HH:mm:ss ZZ')
8787
);
8888
assert.equal(find('[data-test-message]').textContent, annotation.message);
89+
90+
const codeValue = find('[data-test-json-viewer]').textContent;
8991
assert.equal(
90-
getCodeMirrorInstance('[data-test-json-viewer]').getValue(),
91-
JSON.stringify(annotation.meta, null, 2)
92+
codeValue.replace(/\s+/g, ''),
93+
JSON.stringify(annotation.meta)
9294
);
9395

9496
await componentA11yAudit(this.element, assert);

ui/tests/integration/components/variable-form-test.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ import { module, test } from 'qunit';
77
import { setupRenderingTest } from 'ember-qunit';
88
import { hbs } from 'ember-cli-htmlbars';
99
import { componentA11yAudit } from 'nomad-ui/tests/helpers/a11y-audit';
10-
import { click, typeIn, find, findAll, render } from '@ember/test-helpers';
10+
import {
11+
click,
12+
typeIn,
13+
find,
14+
findAll,
15+
render,
16+
waitFor,
17+
} from '@ember/test-helpers';
1118
import { setupMirage } from 'ember-cli-mirage/test-support';
1219
import setupCodeMirror from 'nomad-ui/tests/helpers/codemirror';
1320
import { codeFillable, code } from 'nomad-ui/tests/pages/helpers/codemirror';
@@ -422,11 +429,13 @@ module('Integration | Component | variable-form', function (hooks) {
422429
hbs`<VariableForm @model={{this.mockedModel}} @existingVariables={{this.existingVariables}} @view={{this.view}} />`
423430
);
424431
assert.dom('.key-value').exists();
425-
assert.dom('.CodeMirror').doesNotExist();
432+
assert.dom('.cm-editor').doesNotExist();
426433

427434
this.set('view', 'json');
428435
assert.dom('.key-value').doesNotExist();
429-
assert.dom('.CodeMirror').exists();
436+
437+
await waitFor('.cm-editor');
438+
assert.dom('.cm-editor').exists();
430439
});
431440

432441
test('Persists Key/Values table data to JSON', async function (assert) {
@@ -457,8 +466,11 @@ module('Integration | Component | variable-form', function (hooks) {
457466
return acc;
458467
}, {});
459468

469+
let editorElement = document.querySelector('[data-test-json-editor]');
470+
let codeMirrorInstance = editorElement.editor;
471+
460472
assert.equal(
461-
code('.editor-wrapper').get(),
473+
codeMirrorInstance.state.doc.toString(),
462474
JSON.stringify(keyValuesAsJSON, null, 2),
463475
'JSON editor contains the key values, stringified, by default'
464476
);
@@ -472,8 +484,12 @@ module('Integration | Component | variable-form', function (hooks) {
472484

473485
this.set('view', 'json');
474486

487+
await waitFor('.cm-editor');
488+
editorElement = document.querySelector('[data-test-json-editor]');
489+
codeMirrorInstance = editorElement.editor;
490+
475491
assert.ok(
476-
code('[data-test-json-editor]').get().includes('"howdy": "partner"'),
492+
codeMirrorInstance.state.doc.toString().includes('"howdy": "partner"'),
477493
'JSON editor contains the new key value'
478494
);
479495
});

0 commit comments

Comments
 (0)