Skip to content

Commit 24dd398

Browse files
committed
Auto merge of #2958 - Turbo87:test-cleanup, r=locks
Frontend tests cleanup This PR is best reviewed commit by commit 😉 tl;dr it cleans up our frontend test code a little bit by splitting a file, fixing problematic `visit()` calls and merging redundant/duplicate tests into single tests. r? `@locks`
2 parents 925bb83 + 65c2958 commit 24dd398

File tree

9 files changed

+118
-198
lines changed

9 files changed

+118
-198
lines changed

tests/acceptance/categories-test.js

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,6 @@ module('Acceptance | categories', function (hooks) {
1212
setupApplicationTest(hooks);
1313
setupMirage(hooks);
1414

15-
test('is accessible', async function (assert) {
16-
assert.expect(0);
17-
18-
this.server.create('category', { category: 'API bindings' });
19-
this.server.create('category', { category: 'Algorithms' });
20-
this.server.create('category', { category: 'Asynchronous' });
21-
22-
await visit('/categories');
23-
await percySnapshot(assert);
24-
25-
await a11yAudit(axeConfig);
26-
});
27-
28-
test('category/:category_id is accessible', async function (assert) {
29-
assert.expect(0);
30-
31-
this.server.create('category', { category: 'Algorithms' });
32-
33-
await visit('/categories/algorithms');
34-
await percySnapshot(assert);
35-
36-
await a11yAudit(axeConfig);
37-
});
38-
3915
test('listing categories', async function (assert) {
4016
this.server.create('category', { category: 'API bindings' });
4117
this.server.create('category', { category: 'Algorithms' });
@@ -48,6 +24,9 @@ module('Acceptance | categories', function (hooks) {
4824
assert.dom('[data-test-category="api-bindings"] [data-test-crate-count]').hasText('0 crates');
4925
assert.dom('[data-test-category="algorithms"] [data-test-crate-count]').hasText('1 crate');
5026
assert.dom('[data-test-category="asynchronous"] [data-test-crate-count]').hasText('15 crates');
27+
28+
await percySnapshot(assert);
29+
await a11yAudit(axeConfig);
5130
});
5231

5332
test('category/:category_id index default sort is recent-downloads', async function (assert) {
@@ -56,6 +35,9 @@ module('Acceptance | categories', function (hooks) {
5635
await visit('/categories/algorithms');
5736

5837
assert.dom('[data-test-category-sort] [data-test-current-order]').hasText('Recent Downloads');
38+
39+
await percySnapshot(assert);
40+
await a11yAudit(axeConfig);
5941
});
6042

6143
test('listing category slugs', async function (assert) {

tests/acceptance/crate-test.js

Lines changed: 10 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { click, fillIn, currentURL, currentRouteName, visit, waitFor } from '@ember/test-helpers';
1+
import { click, currentURL, currentRouteName, visit, waitFor } from '@ember/test-helpers';
22
import { setupApplicationTest } from 'ember-qunit';
33
import { module, test, skip } from 'qunit';
44

@@ -13,43 +13,6 @@ module('Acceptance | crate page', function (hooks) {
1313
setupApplicationTest(hooks);
1414
setupMirage(hooks);
1515

16-
test('/crates/:crate is accessible', async function (assert) {
17-
assert.expect(0);
18-
19-
this.server.create('crate', { name: 'nanomsg' });
20-
this.server.create('version', { crateId: 'nanomsg', num: '0.6.0' });
21-
this.server.create('version', { crateId: 'nanomsg', num: '0.6.1' });
22-
23-
await visit('/crates/nanomsg');
24-
await percySnapshot(assert);
25-
26-
await a11yAudit(axeConfig);
27-
});
28-
29-
test('/crates/:crate/:version is accessible', async function (assert) {
30-
assert.expect(0);
31-
32-
this.server.create('crate', { name: 'nanomsg' });
33-
this.server.create('version', { crateId: 'nanomsg', num: '0.6.0' });
34-
this.server.create('version', { crateId: 'nanomsg', num: '0.6.1' });
35-
36-
await visit('/crates/nanomsg/0.6.0');
37-
await percySnapshot(assert);
38-
39-
await a11yAudit(axeConfig);
40-
});
41-
42-
test('/crates/:crate/owners is accessible', async function (assert) {
43-
assert.expect(0);
44-
45-
this.server.loadFixtures();
46-
47-
await visit('/crates/nanomsg/owners');
48-
await percySnapshot(assert);
49-
50-
await a11yAudit(axeConfig);
51-
});
52-
5316
test('visiting a crate page from the front page', async function (assert) {
5417
this.server.create('crate', { name: 'nanomsg', newest_version: '0.6.1' });
5518
this.server.create('version', { crateId: 'nanomsg', num: '0.6.1' });
@@ -78,6 +41,9 @@ module('Acceptance | crate page', function (hooks) {
7841
assert.dom('[data-test-heading] [data-test-crate-name]').hasText('nanomsg');
7942
assert.dom('[data-test-heading] [data-test-crate-version]').hasText('0.6.1');
8043
assert.dom('[data-test-crate-stats-label]').hasText('Stats Overview');
44+
45+
await percySnapshot(assert);
46+
await a11yAudit(axeConfig);
8147
});
8248

8349
test('visiting /crates/nanomsg/', async function (assert) {
@@ -110,6 +76,9 @@ module('Acceptance | crate page', function (hooks) {
11076
assert.dom('[data-test-heading] [data-test-crate-name]').hasText('nanomsg');
11177
assert.dom('[data-test-heading] [data-test-crate-version]').hasText('0.6.0');
11278
assert.dom('[data-test-crate-stats-label]').hasText('Stats Overview for 0.6.0 (see all)');
79+
80+
await percySnapshot(assert);
81+
await a11yAudit(axeConfig);
11382
});
11483

11584
test('unknown versions fall back to latest version and show an error message', async function (assert) {
@@ -167,23 +136,23 @@ module('Acceptance | crate page', function (hooks) {
167136
test('crates having normal dependencies', async function (assert) {
168137
this.server.loadFixtures();
169138

170-
await visit('crates/nanomsg');
139+
await visit('/crates/nanomsg');
171140

172141
assert.dom('[data-test-dependencies] li').exists({ count: 2 });
173142
});
174143

175144
test('crates having build dependencies', async function (assert) {
176145
this.server.loadFixtures();
177146

178-
await visit('crates/nanomsg');
147+
await visit('/crates/nanomsg');
179148

180149
assert.dom('[data-test-build-dependencies] li').exists({ count: 1 });
181150
});
182151

183152
test('crates having dev dependencies', async function (assert) {
184153
this.server.loadFixtures();
185154

186-
await visit('crates/nanomsg');
155+
await visit('/crates/nanomsg');
187156

188157
assert.dom('[data-test-dev-dependencies] li').exists({ count: 1 });
189158
});
@@ -268,73 +237,4 @@ module('Acceptance | crate page', function (hooks) {
268237

269238
assert.equal(currentURL(), '/crates/nanomsg/owners');
270239
});
271-
272-
test('listing crate owners', async function (assert) {
273-
this.server.loadFixtures();
274-
275-
await visit('/crates/nanomsg/owners');
276-
277-
assert.dom('[data-test-owners] [data-test-owner-team]').exists({ count: 2 });
278-
assert.dom('[data-test-owners] [data-test-owner-user]').exists({ count: 2 });
279-
assert.dom('a[href="/teams/github:org:thehydroimpulse"]').exists();
280-
assert.dom('a[href="/teams/github:org:blabaere"]').exists();
281-
assert.dom('a[href="/users/thehydroimpulse"]').exists();
282-
assert.dom('a[href="/users/blabaere"]').exists();
283-
});
284-
285-
test('attempting to add owner without username', async function (assert) {
286-
this.server.loadFixtures();
287-
288-
await visit('/crates/nanomsg/owners');
289-
await fillIn('input[name="username"]', '');
290-
assert.dom('[data-test-save-button]').isDisabled();
291-
});
292-
293-
test('attempting to add non-existent owner', async function (assert) {
294-
this.server.loadFixtures();
295-
296-
await visit('/crates/nanomsg/owners');
297-
await fillIn('input[name="username"]', 'spookyghostboo');
298-
await click('[data-test-save-button]');
299-
300-
assert
301-
.dom('[data-test-notification-message="error"]')
302-
.hasText('Error sending invite: could not find user with login `spookyghostboo`');
303-
assert.dom('[data-test-owners] [data-test-owner-team]').exists({ count: 2 });
304-
assert.dom('[data-test-owners] [data-test-owner-user]').exists({ count: 2 });
305-
});
306-
307-
test('add a new owner', async function (assert) {
308-
this.server.loadFixtures();
309-
310-
await visit('/crates/nanomsg/owners');
311-
await fillIn('input[name="username"]', 'iain8');
312-
await click('[data-test-save-button]');
313-
314-
assert.dom('[data-test-notification-message="success"]').hasText('An invite has been sent to iain8');
315-
assert.dom('[data-test-owners] [data-test-owner-team]').exists({ count: 2 });
316-
assert.dom('[data-test-owners] [data-test-owner-user]').exists({ count: 2 });
317-
});
318-
319-
test('remove a crate owner when owner is a user', async function (assert) {
320-
this.server.loadFixtures();
321-
322-
await visit('/crates/nanomsg/owners');
323-
await click('[data-test-owner-user="thehydroimpulse"] [data-test-remove-owner-button]');
324-
325-
assert.dom('[data-test-notification-message="success"]').hasText('User thehydroimpulse removed as crate owner');
326-
assert.dom('[data-test-owner-user]').exists({ count: 1 });
327-
});
328-
329-
test('remove a crate owner when owner is a team', async function (assert) {
330-
this.server.loadFixtures();
331-
332-
await visit('/crates/nanomsg/owners');
333-
await click('[data-test-owner-team="github:org:thehydroimpulse"] [data-test-remove-owner-button]');
334-
335-
assert
336-
.dom('[data-test-notification-message="success"]')
337-
.hasText('Team org/thehydroimpulseteam removed as crate owner');
338-
assert.dom('[data-test-owner-team]').exists({ count: 1 });
339-
});
340240
});

tests/acceptance/crates-test.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@ module('Acceptance | crates page', function (hooks) {
1616
// should match the default set in the crates controller
1717
const per_page = 50;
1818

19-
test('/crates is accessible', async function (assert) {
20-
assert.expect(0);
21-
22-
this.server.loadFixtures();
23-
24-
await visit('/crates');
25-
await percySnapshot(assert);
26-
27-
await a11yAudit(axeConfig);
28-
});
29-
3019
test('visiting the crates page from the front page', async function (assert) {
3120
this.server.loadFixtures();
3221

@@ -35,6 +24,9 @@ module('Acceptance | crates page', function (hooks) {
3524

3625
assert.equal(currentURL(), '/crates');
3726
assert.equal(title(), 'Crates - crates.io: Rust Package Registry');
27+
28+
await percySnapshot(assert);
29+
await a11yAudit(axeConfig);
3830
});
3931

4032
test('visiting the crates page directly', async function (assert) {

tests/acceptance/front-page-test.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@ module('Acceptance | front page', function (hooks) {
1313
setupApplicationTest(hooks);
1414
setupMirage(hooks);
1515

16-
test('is accessible', async function (assert) {
17-
assert.expect(0);
18-
19-
this.server.loadFixtures();
20-
21-
await visit('/');
22-
await a11yAudit(axeConfig);
23-
});
24-
2516
test('visiting /', async function (assert) {
2617
this.server.loadFixtures();
2718

@@ -47,5 +38,6 @@ module('Acceptance | front page', function (hooks) {
4738
assert.dom('[data-test-just-updated] [data-test-crate-link="0"]').hasAttribute('href', '/crates/nanomsg');
4839

4940
await percySnapshot(assert);
41+
await a11yAudit(axeConfig);
5042
});
5143
});

tests/acceptance/keyword-test.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,14 @@ module('Acceptance | keywords', function (hooks) {
1212
setupApplicationTest(hooks);
1313
setupMirage(hooks);
1414

15-
test('keyword/:keyword_id is accessible', async function (assert) {
16-
assert.expect(0);
17-
18-
this.server.create('keyword', { keyword: 'network' });
19-
20-
await visit('keywords/network');
21-
await percySnapshot(assert);
22-
23-
await a11yAudit(axeConfig);
24-
});
25-
2615
test('keyword/:keyword_id index default sort is recent-downloads', async function (assert) {
2716
this.server.create('keyword', { keyword: 'network' });
2817

2918
await visit('/keywords/network');
3019

3120
assert.dom('[data-test-keyword-sort] [data-test-current-order]').hasText('Recent Downloads');
21+
22+
await percySnapshot(assert);
23+
await a11yAudit(axeConfig);
3224
});
3325
});

tests/acceptance/owners-test.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { click, fillIn, visit } from '@ember/test-helpers';
2+
import { setupApplicationTest } from 'ember-qunit';
3+
import { module, test } from 'qunit';
4+
5+
import percySnapshot from '@percy/ember';
6+
import a11yAudit from 'ember-a11y-testing/test-support/audit';
7+
8+
import axeConfig from '../axe-config';
9+
import setupMirage from '../helpers/setup-mirage';
10+
11+
module('Acceptance | /crates/:name/owners', function (hooks) {
12+
setupApplicationTest(hooks);
13+
setupMirage(hooks);
14+
15+
test('listing crate owners', async function (assert) {
16+
this.server.loadFixtures();
17+
18+
await visit('/crates/nanomsg/owners');
19+
20+
assert.dom('[data-test-owners] [data-test-owner-team]').exists({ count: 2 });
21+
assert.dom('[data-test-owners] [data-test-owner-user]').exists({ count: 2 });
22+
assert.dom('a[href="/teams/github:org:thehydroimpulse"]').exists();
23+
assert.dom('a[href="/teams/github:org:blabaere"]').exists();
24+
assert.dom('a[href="/users/thehydroimpulse"]').exists();
25+
assert.dom('a[href="/users/blabaere"]').exists();
26+
27+
await percySnapshot(assert);
28+
await a11yAudit(axeConfig);
29+
});
30+
31+
test('attempting to add owner without username', async function (assert) {
32+
this.server.loadFixtures();
33+
34+
await visit('/crates/nanomsg/owners');
35+
await fillIn('input[name="username"]', '');
36+
assert.dom('[data-test-save-button]').isDisabled();
37+
});
38+
39+
test('attempting to add non-existent owner', async function (assert) {
40+
this.server.loadFixtures();
41+
42+
await visit('/crates/nanomsg/owners');
43+
await fillIn('input[name="username"]', 'spookyghostboo');
44+
await click('[data-test-save-button]');
45+
46+
assert
47+
.dom('[data-test-notification-message="error"]')
48+
.hasText('Error sending invite: could not find user with login `spookyghostboo`');
49+
assert.dom('[data-test-owners] [data-test-owner-team]').exists({ count: 2 });
50+
assert.dom('[data-test-owners] [data-test-owner-user]').exists({ count: 2 });
51+
});
52+
53+
test('add a new owner', async function (assert) {
54+
this.server.loadFixtures();
55+
56+
await visit('/crates/nanomsg/owners');
57+
await fillIn('input[name="username"]', 'iain8');
58+
await click('[data-test-save-button]');
59+
60+
assert.dom('[data-test-notification-message="success"]').hasText('An invite has been sent to iain8');
61+
assert.dom('[data-test-owners] [data-test-owner-team]').exists({ count: 2 });
62+
assert.dom('[data-test-owners] [data-test-owner-user]').exists({ count: 2 });
63+
});
64+
65+
test('remove a crate owner when owner is a user', async function (assert) {
66+
this.server.loadFixtures();
67+
68+
await visit('/crates/nanomsg/owners');
69+
await click('[data-test-owner-user="thehydroimpulse"] [data-test-remove-owner-button]');
70+
71+
assert.dom('[data-test-notification-message="success"]').hasText('User thehydroimpulse removed as crate owner');
72+
assert.dom('[data-test-owner-user]').exists({ count: 1 });
73+
});
74+
75+
test('remove a crate owner when owner is a team', async function (assert) {
76+
this.server.loadFixtures();
77+
78+
await visit('/crates/nanomsg/owners');
79+
await click('[data-test-owner-team="github:org:thehydroimpulse"] [data-test-remove-owner-button]');
80+
81+
assert
82+
.dom('[data-test-notification-message="success"]')
83+
.hasText('Team org/thehydroimpulseteam removed as crate owner');
84+
assert.dom('[data-test-owner-team]').exists({ count: 1 });
85+
});
86+
});

0 commit comments

Comments
 (0)