Skip to content

Commit

Permalink
ui: apply new qunit linting rules to tests
Browse files Browse the repository at this point in the history
Async tests should use  in integrations tests.
Acceptance tests are using Mirage and can't use
since we can't know the number of assertions.
  • Loading branch information
ChaiWithJai committed Jan 20, 2022
1 parent 8c600ac commit 2032813
Show file tree
Hide file tree
Showing 90 changed files with 369 additions and 31 deletions.
3 changes: 3 additions & 0 deletions ui/tests/acceptance/allocation-detail-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable qunit/require-expect */
/* Mirage fixtures are random so we can't expect a set number of assertions */
import { run } from '@ember/runloop';
import { currentURL } from '@ember/test-helpers';
import { assign } from '@ember/polyfills';
Expand Down Expand Up @@ -207,6 +209,7 @@ module('Acceptance | allocation detail', function(hooks) {

await Allocation.tasks.objectAt(0).clickLink();

// Make sure the allocation is pending in order to ensure there are no tasks
assert.equal(
currentURL(),
`/allocations/${allocation.id}/${task.name}`,
Expand Down
2 changes: 2 additions & 0 deletions ui/tests/acceptance/application-errors-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ module('Acceptance | application errors ', function (hooks) {
});

test('it passes an accessibility audit', async function (assert) {
assert.expect(1);

server.pretender.get('/v1/nodes', () => [500, {}, null]);
await ClientsList.visit();
await a11yAudit(assert);
Expand Down
1 change: 1 addition & 0 deletions ui/tests/acceptance/behaviors/fs.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable qunit/require-expect */
import { test } from 'qunit';
import { currentURL, visit } from '@ember/test-helpers';

Expand Down
3 changes: 3 additions & 0 deletions ui/tests/acceptance/client-detail-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable qunit/require-expect */
/* eslint-disable qunit/no-conditional-assertions */
/* Mirage fixtures are random so we can't expect a set number of assertions */
import { currentURL, waitUntil, settled } from '@ember/test-helpers';
import { assign } from '@ember/polyfills';
import { module, test } from 'qunit';
Expand Down
1 change: 1 addition & 0 deletions ui/tests/acceptance/clients-list-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable qunit/require-expect */
import { currentURL, settled } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
Expand Down
1 change: 1 addition & 0 deletions ui/tests/acceptance/exec-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable qunit/require-expect */
import { module, skip, test } from 'qunit';
import { currentURL, settled } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
Expand Down
1 change: 1 addition & 0 deletions ui/tests/acceptance/job-allocations-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable qunit/require-expect */
import { currentURL } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
Expand Down
3 changes: 3 additions & 0 deletions ui/tests/acceptance/job-clients-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable qunit/require-expect */
import { currentURL } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
Expand Down Expand Up @@ -75,11 +76,13 @@ module('Acceptance | job clients', function (hooks) {

['createTime', 'modifyTime'].forEach((col) => {
if (jobStatus === 'not scheduled') {
/* eslint-disable-next-line qunit/no-conditional-assertions */
assert.equal(
clientRow[col].text,
'-',
`row ${index} doesn't have ${col} tooltip`
);
/* eslint-disable-next-line qunit/no-early-return */
return;
}

Expand Down
2 changes: 2 additions & 0 deletions ui/tests/acceptance/job-definition-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module('Acceptance | job definition', function (hooks) {
});

test('it passes an accessibility audit', async function (assert) {
assert.expect(1);

await a11yAudit(assert, 'scrollable-region-focusable');
});

Expand Down
4 changes: 3 additions & 1 deletion ui/tests/acceptance/job-deployments-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ module('Acceptance | job deployments', function (hooks) {
});

test('it passes an accessibility audit', async function (assert) {
assert.expect(1);

await Deployments.visit({ id: job.id });
await a11yAudit(assert);
});

test('/jobs/:id/deployments should list all job deployments', async function (assert) {
await Deployments.visit({ id: job.id });

assert.ok(
assert.equal(
Deployments.deployments.length,
deployments.length,
'Each deployment gets a row in the timeline'
Expand Down
1 change: 1 addition & 0 deletions ui/tests/acceptance/job-detail-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable ember/no-test-module-for */
/* eslint-disable qunit/require-expect */
import { currentURL } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
Expand Down
2 changes: 2 additions & 0 deletions ui/tests/acceptance/job-dispatch-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable ember/no-test-module-for */
/* eslint-disable qunit/require-expect */
/* eslint-disable qunit/no-conditional-assertions */
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { setupMirage } from 'ember-cli-mirage/test-support';
Expand Down
1 change: 1 addition & 0 deletions ui/tests/acceptance/job-evaluations-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable qunit/require-expect */
import { currentURL } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
Expand Down
2 changes: 2 additions & 0 deletions ui/tests/acceptance/job-run-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ module('Acceptance | job run', function (hooks) {
});

test('it passes an accessibility audit', async function (assert) {
assert.expect(1);

await JobRun.visit();
await a11yAudit(assert);
});
Expand Down
4 changes: 3 additions & 1 deletion ui/tests/acceptance/job-versions-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable qunit/require-expect */
/* eslint-disable qunit/no-conditional-assertions */
import { currentURL } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
Expand Down Expand Up @@ -36,7 +38,7 @@ module('Acceptance | job versions', function (hooks) {
});

test('/jobs/:id/versions should list all job versions', async function (assert) {
assert.ok(
assert.equal(
Versions.versions.length,
versions.length,
'Each version gets a row in the timeline'
Expand Down
1 change: 1 addition & 0 deletions ui/tests/acceptance/jobs-list-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable qunit/require-expect */
import { currentURL } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
Expand Down
2 changes: 2 additions & 0 deletions ui/tests/acceptance/optimize-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable qunit/require-expect */
/* eslint-disable qunit/no-conditional-assertions */
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { currentURL, visit } from '@ember/test-helpers';
Expand Down
1 change: 1 addition & 0 deletions ui/tests/acceptance/plugin-allocations-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable qunit/require-expect */
import { module, test } from 'qunit';
import { currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
Expand Down
1 change: 1 addition & 0 deletions ui/tests/acceptance/plugin-detail-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable qunit/require-expect */
import { module, test } from 'qunit';
import { currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
Expand Down
1 change: 1 addition & 0 deletions ui/tests/acceptance/plugins-list-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable qunit/require-expect */
import { currentURL } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
Expand Down
2 changes: 2 additions & 0 deletions ui/tests/acceptance/regions-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable qunit/require-expect */
/* eslint-disable qunit/no-conditional-assertions */
import { currentURL } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
Expand Down
5 changes: 3 additions & 2 deletions ui/tests/acceptance/search-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable ember-a11y-testing/a11y-audit-called */ // TODO
/* eslint-disable ember-a11y-testing/a11y-audit-called */
/* eslint-disable qunit/require-expect */
import { module, test } from 'qunit';
import { currentURL, triggerEvent, visit } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
Expand Down Expand Up @@ -114,7 +115,7 @@ module('Acceptance | search', function (hooks) {
request.requestBody.includes('feature-detection-query')
);

assert.ok(
assert.equal(
featureDetectionQueries.length,
1,
'expect the feature detection query to only run once'
Expand Down
1 change: 1 addition & 0 deletions ui/tests/acceptance/server-detail-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable qunit/require-expect */
import { currentURL } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
Expand Down
2 changes: 2 additions & 0 deletions ui/tests/acceptance/server-monitor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ module('Acceptance | server monitor', function (hooks) {
});

test('it passes an accessibility audit', async function (assert) {
assert.expect(1);

await ServerMonitor.visit({ name: agent.name });
await a11yAudit(assert);
});
Expand Down
1 change: 1 addition & 0 deletions ui/tests/acceptance/servers-list-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable qunit/require-expect */
import { currentURL } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
Expand Down
2 changes: 2 additions & 0 deletions ui/tests/acceptance/task-group-detail-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable qunit/require-expect */
/* eslint-disable qunit/no-conditional-assertions */
import { currentURL, settled } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
Expand Down
1 change: 1 addition & 0 deletions ui/tests/acceptance/task-logs-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable qunit/require-expect */
import { currentURL } from '@ember/test-helpers';
import { run } from '@ember/runloop';
import { module, test } from 'qunit';
Expand Down
2 changes: 2 additions & 0 deletions ui/tests/acceptance/token-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ module('Acceptance | tokens', function (hooks) {
});

test('it passes an accessibility audit', async function (assert) {
assert.expect(1);

await Tokens.visit();
await a11yAudit(assert);
});
Expand Down
2 changes: 2 additions & 0 deletions ui/tests/acceptance/topology-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ module('Acceptance | topology', function (hooks) {
});

test('it passes an accessibility audit', async function (assert) {
assert.expect(1);

server.createList('node', 3);
server.createList('allocation', 5);

Expand Down
1 change: 1 addition & 0 deletions ui/tests/acceptance/volume-detail-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable qunit/require-expect */
import { module, test } from 'qunit';
import { currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
Expand Down
1 change: 1 addition & 0 deletions ui/tests/acceptance/volumes-list-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable qunit/require-expect */
import { currentURL, visit } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
Expand Down
32 changes: 19 additions & 13 deletions ui/tests/helpers/glimmer-factory.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
// Used in glimmer component unit tests. Glimmer components should typically
// be tested with integration tests, but occasionally individual methods or
// properties have logic that isn't coupled to rendering or the DOM and can
// be better tested in a unit fashion.
//
// Use like
//
// setupGlimmerComponentFactory(hooks, 'my-component')
//
// test('testing my component', function(assert) {
// const component = this.createComponent({ hello: 'world' });
// assert.equal(component.args.hello, 'world');
// });
/* eslint-disable qunit/no-commented-tests */
// We comment test to show an example of how to use the factory function

/*
Used in glimmer component unit tests. Glimmer components should typically
be tested with integration tests, but occasionally individual methods or
properties have logic that isn't coupled to rendering or the DOM and can
be better tested in a unit fashion.
Use like
setupGlimmerComponentFactory(hooks, 'my-component')
test('testing my component', function(assert) {
const component = this.createComponent({ hello: 'world' });
assert.equal(component.args.hello, 'world');
});
*/

export default function setupGlimmerComponentFactory(hooks, componentKey) {
hooks.beforeEach(function () {
this.createComponent = glimmerComponentInstantiator(
Expand Down
2 changes: 2 additions & 0 deletions ui/tests/helpers/module-for-job.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable qunit/require-expect */
/* eslint-disable qunit/no-conditional-assertions */
import { currentURL } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
Expand Down
2 changes: 2 additions & 0 deletions ui/tests/integration/components/agent-monitor-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ module('Integration | Component | agent-monitor', function (hooks) {
`;

test('basic appearance', async function (assert) {
assert.expect(5);

this.setProperties({
level: 'info',
client: { id: 'client1' },
Expand Down
14 changes: 7 additions & 7 deletions ui/tests/integration/components/allocation-row-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module('Integration | Component | allocation row', function(hooks) {
JSON.stringify({ ResourceUsage: generateResources() }),
null,
'<Not>Valid JSON</Not>',
JSON.stringify({ ResourceUsage: generateResources() }),
JSON.stringify({ ResourceUsage: generateResources() })
];

this.server.get('/client/allocation/:id/stats', function() {
Expand All @@ -60,7 +60,7 @@ module('Integration | Component | allocation row', function(hooks) {
this.setProperties({
allocation,
context: 'job',
enablePolling: true,
enablePolling: true
});

await render(hbs`
Expand All @@ -87,9 +87,9 @@ module('Integration | Component | allocation row', function(hooks) {
name: 'node-read',
rulesJSON: {
Node: {
Policy: 'read',
},
},
Policy: 'read'
}
}
});
const clientToken = server.create('token', { type: 'client' });
clientToken.policyIds = [policy.id];
Expand All @@ -116,7 +116,7 @@ module('Integration | Component | allocation row', function(hooks) {

this.setProperties({
allocation,
context: 'job',
context: 'job'
});

await render(hbs`
Expand Down Expand Up @@ -150,7 +150,7 @@ module('Integration | Component | allocation row', function(hooks) {
test('when an allocation is not running, the utilization graphs are omitted', async function(assert) {
this.setProperties({
context: 'job',
enablePolling: false,
enablePolling: false
});

// All non-running statuses need to be tested
Expand Down
8 changes: 5 additions & 3 deletions ui/tests/integration/components/app-breadcrumbs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module('Integration | Component | app breadcrumbs', function(hooks) {

const commonCrumbs = [
{ label: 'Jobs', args: ['jobs.index'] },
{ label: 'Job', args: ['jobs.job.index'] },
{ label: 'Job', args: ['jobs.job.index'] }
];

test('every breadcrumb is rendered correctly', async function(assert) {
Expand All @@ -25,7 +25,9 @@ module('Integration | Component | app breadcrumbs', function(hooks) {

assert
.dom('[data-test-breadcrumb-default]')
.exists('We register the default breadcrumb component if no type is specified on the crumb');
.exists(
'We register the default breadcrumb component if no type is specified on the crumb'
);

const renderedCrumbs = findAll('[data-test-breadcrumb]');

Expand All @@ -41,7 +43,7 @@ module('Integration | Component | app breadcrumbs', function(hooks) {
test('when we register a crumb with a type property, a dedicated breadcrumb/<type> component renders', async function(assert) {
const crumbs = [
{ label: 'Jobs', args: ['jobs.index'] },
{ type: 'special', label: 'Job', args: ['jobs.job.index'] },
{ type: 'special', label: 'Job', args: ['jobs.job.index'] }
];
this.set('crumbs', crumbs);

Expand Down
2 changes: 2 additions & 0 deletions ui/tests/integration/components/attributes-table-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ module('Integration | Component | attributes table', function (hooks) {
};

test('should render a row for each key/value pair in a deep object', async function (assert) {
assert.expect(2);

this.set('attributes', commonAttributes);
await render(hbs`<AttributesTable @attributePairs={{attributes}} />`);

Expand Down
Loading

0 comments on commit 2032813

Please sign in to comment.