Skip to content

Commit 50769ac

Browse files
committed
tests/acceptance: Use async/await instead of andThen() blocks
1 parent 0f38b6e commit 50769ac

File tree

6 files changed

+138
-173
lines changed

6 files changed

+138
-173
lines changed

tests/acceptance/categories-test.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@ import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
33

44
moduleForAcceptance('Acceptance | categories');
55

6-
test('listing categories', function(assert) {
7-
visit('/categories');
6+
test('listing categories', async function(assert) {
7+
await visit('/categories');
88

9-
andThen(function() {
10-
hasText(assert, '.row:eq(0) .desc .info span', '0 crates');
11-
12-
hasText(assert, '.row:eq(1) .desc .info span', '1 crate');
13-
14-
hasText(assert, '.row:eq(2) .desc .info span', '3,910 crates');
15-
});
9+
hasText(assert, '.row:eq(0) .desc .info span', '0 crates');
10+
hasText(assert, '.row:eq(1) .desc .info span', '1 crate');
11+
hasText(assert, '.row:eq(2) .desc .info span', '3,910 crates');
1612
});

tests/acceptance/crate-test.js

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,37 @@ import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
33

44
moduleForAcceptance('Acceptance | crate page');
55

6-
test('visiting a crate page from the front page', function(assert) {
7-
visit('/');
8-
click('#just-updated ul > li:first a');
6+
test('visiting a crate page from the front page', async function(assert) {
7+
await visit('/');
8+
await click('#just-updated ul > li:first a');
99

10-
andThen(function() {
11-
assert.equal(currentURL(), '/crates/nanomsg');
12-
assert.equal(document.title, 'nanomsg - Cargo: packages for Rust');
13-
});
10+
assert.equal(currentURL(), '/crates/nanomsg');
11+
assert.equal(document.title, 'nanomsg - Cargo: packages for Rust');
1412
});
1513

16-
test('visiting a crate page directly', function(assert) {
17-
visit('/crates/nanomsg');
14+
test('visiting a crate page directly', async function(assert) {
15+
await visit('/crates/nanomsg');
1816

19-
andThen(function() {
20-
assert.equal(currentURL(), '/crates/nanomsg');
21-
assert.equal(document.title, 'nanomsg - Cargo: packages for Rust');
22-
});
17+
assert.equal(currentURL(), '/crates/nanomsg');
18+
assert.equal(document.title, 'nanomsg - Cargo: packages for Rust');
2319
});
2420

25-
test('navigating to the all versions page', function(assert) {
26-
visit('/crates/nanomsg');
27-
click('#crate-versions span.small a');
21+
test('navigating to the all versions page', async function(assert) {
22+
await visit('/crates/nanomsg');
23+
await click('#crate-versions span.small a');
2824

29-
andThen(function() {
30-
matchesText(assert, '.info', /All 13 versions of nanomsg since December \d+, 2014/);
31-
});
25+
matchesText(assert, '.info', /All 13 versions of nanomsg since December \d+, 2014/);
3226
});
3327

34-
test('navigating to the reverse dependencies page', function(assert) {
35-
visit('/crates/nanomsg');
36-
click('a:contains("Dependent crates")');
28+
test('navigating to the reverse dependencies page', async function(assert) {
29+
await visit('/crates/nanomsg');
30+
await click('a:contains("Dependent crates")');
3731

38-
andThen(function() {
39-
assert.equal(currentURL(), '/crates/nanomsg/reverse_dependencies');
32+
assert.equal(currentURL(), '/crates/nanomsg/reverse_dependencies');
4033

41-
const $revDep = findWithAssert('a[href="/crates/unicorn-rpc"]:first');
34+
const $revDep = findWithAssert('a[href="/crates/unicorn-rpc"]:first');
4235

43-
hasText(assert, $revDep, 'unicorn-rpc');
44-
});
36+
hasText(assert, $revDep, 'unicorn-rpc');
4537
});
4638

4739
test('navigating to a user page', function(assert) {

tests/acceptance/front-page-test.js

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,28 @@ import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
33

44
moduleForAcceptance('Acceptance | front page');
55

6-
test('visiting /', function(assert) {
7-
visit('/');
6+
test('visiting /', async function(assert) {
7+
await visit('/');
88

9-
andThen(function() {
10-
assert.equal(currentURL(), '/');
11-
assert.equal(document.title, 'Cargo: packages for Rust');
9+
assert.equal(currentURL(), '/');
10+
assert.equal(document.title, 'Cargo: packages for Rust');
1211

13-
findWithAssert('a[href="/install"]');
14-
findWithAssert('a[href="/crates"]');
15-
findWithAssert('a[href="/login"]');
12+
findWithAssert('a[href="/install"]');
13+
findWithAssert('a[href="/crates"]');
14+
findWithAssert('a[href="/login"]');
1615

17-
hasText(assert, '.downloads .num', '13,534,453');
18-
hasText(assert, '.crates .num', '3,430');
16+
hasText(assert, '.downloads .num', '13,534,453');
17+
hasText(assert, '.crates .num', '3,430');
1918

20-
const $newCrate = findWithAssert('#new-crates ul > li:first a');
21-
hasText(assert, $newCrate, 'mkstemp (0.2.0)');
22-
assert.equal($newCrate.attr('href').trim(), '/crates/mkstemp');
19+
const $newCrate = findWithAssert('#new-crates ul > li:first a');
20+
hasText(assert, $newCrate, 'mkstemp (0.2.0)');
21+
assert.equal($newCrate.attr('href').trim(), '/crates/mkstemp');
2322

24-
const $mostDownloaded = findWithAssert('#most-downloaded ul > li:first a');
25-
hasText(assert, $mostDownloaded, 'libc (0.2.2)');
26-
assert.equal($mostDownloaded.attr('href').trim(), '/crates/libc');
23+
const $mostDownloaded = findWithAssert('#most-downloaded ul > li:first a');
24+
hasText(assert, $mostDownloaded, 'libc (0.2.2)');
25+
assert.equal($mostDownloaded.attr('href').trim(), '/crates/libc');
2726

28-
const $justUpdated = findWithAssert('#just-updated ul > li:first a');
29-
hasText(assert, $justUpdated, 'nanomsg (0.4.2)');
30-
assert.equal($justUpdated.attr('href').trim(), '/crates/nanomsg');
31-
});
27+
const $justUpdated = findWithAssert('#just-updated ul > li:first a');
28+
hasText(assert, $justUpdated, 'nanomsg (0.4.2)');
29+
assert.equal($justUpdated.attr('href').trim(), '/crates/nanomsg');
3230
});

tests/acceptance/search-test.js

Lines changed: 65 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,60 @@ import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
33

44
moduleForAcceptance('Acceptance | search');
55

6-
test('searching for "rust"', function(assert) {
7-
visit('/');
8-
fillIn('input.search', 'rust');
9-
andThen(function() {
10-
findWithAssert('form.search').submit();
11-
});
12-
wait();
13-
14-
andThen(function() {
15-
assert.equal(currentURL(), '/search?q=rust');
16-
assert.equal(document.title, 'Search Results for \'rust\' - Cargo: packages for Rust');
17-
18-
findWithAssert('a[href="/search?page=2&q=rust"]');
19-
assert.notOk(find('a[href="/search?page=3&q=rust"]')[0]);
20-
21-
hasText(assert, '#crates-heading', 'Search Results for \'rust\'');
22-
hasText(assert, '#results', 'Displaying 1-10 of 18 total results Sort by Relevance Relevance Downloads');
23-
24-
hasText(assert, '#crates .row:first .desc .info', 'rust_mixin');
25-
findWithAssert('#crates .row:first .desc .info .vers img[alt="0.0.1"]');
26-
27-
findWithAssert('#crates .row:first .desc .info .badge:first a[href="https://ci.appveyor.com/project/huonw/external_mixin"]');
28-
findWithAssert('#crates .row:first .desc .info .badge:first a img[src="https://ci.appveyor.com/api/projects/status/github/huonw/external_mixin?svg=true&branch=master"]');
29-
findWithAssert('#crates .row:first .desc .info .badge:eq(1) a[href="https://codecov.io/github/huonw/external_mixin?branch=master"]');
30-
findWithAssert('#crates .row:first .desc .info .badge:eq(1) a img[src="https://codecov.io/github/huonw/external_mixin/coverage.svg?branch=master"]');
31-
findWithAssert('#crates .row:first .desc .info .badge:eq(2) a[href="https://coveralls.io/github/huonw/external_mixin?branch=master"]');
32-
findWithAssert('#crates .row:first .desc .info .badge:eq(2) a img[src="https://coveralls.io/repos/github/huonw/external_mixin/badge.svg?branch=master"]');
33-
findWithAssert('#crates .row:first .desc .info .badge:eq(3) a[href="https://gitlab.com/huonw/external_mixin/pipelines"]');
34-
findWithAssert('#crates .row:first .desc .info .badge:eq(3) a img[src="https://gitlab.com/huonw/external_mixin/badges/master/build.svg"]');
35-
findWithAssert('#crates .row:first .desc .info .badge:eq(4) a[href="https://isitmaintained.com/project/huonw/external_mixin"]');
36-
findWithAssert('#crates .row:first .desc .info .badge:eq(4) a img[src="https://isitmaintained.com/badge/resolution/huonw/external_mixin.svg"]');
37-
findWithAssert('#crates .row:first .desc .info .badge:eq(5) a[href="https://isitmaintained.com/project/huonw/external_mixin"]');
38-
findWithAssert('#crates .row:first .desc .info .badge:eq(5) a img[src="https://isitmaintained.com/badge/open/huonw/external_mixin.svg"]');
39-
findWithAssert('#crates .row:first .desc .info .badge:eq(6) a[href="https://travis-ci.org/huonw/external_mixin"]');
40-
findWithAssert('#crates .row:first .desc .info .badge:eq(6) a img[src="https://travis-ci.org/huonw/external_mixin.svg?branch=master"]');
41-
42-
hasText(assert, '#crates .row:first .desc .summary', 'Yo dawg, use Rust to generate Rust, right in your Rust. (See `external_mixin` to use scripting languages.)');
43-
hasText(assert, '#crates .row:first .downloads', '477');
44-
});
45-
click('a[href="/search?page=2&q=rust"]');
46-
47-
andThen(function() {
48-
assert.equal(currentURL(), '/search?page=2&q=rust');
49-
assert.equal(document.title, 'Search Results for \'rust\' - Cargo: packages for Rust');
50-
51-
findWithAssert('a[href="/search?q=rust"]');
52-
assert.notOk(find('a[href="/search?page=3&q=rust"]')[0]);
53-
54-
hasText(assert, '#crates-heading', 'Search Results for \'rust\'');
55-
hasText(assert, '#results', 'Displaying 11-18 of 18 total results Sort by Relevance Relevance Downloads');
56-
57-
hasText(assert, '#crates .row:first .desc .info', 'rusted_cypher');
58-
findWithAssert('#crates .row:first .desc .info .vers img[alt="0.7.1"]');
59-
});
6+
test('searching for "rust"', async function(assert) {
7+
await visit('/');
8+
await fillIn('input.search', 'rust');
9+
10+
findWithAssert('form.search').submit();
11+
12+
await wait();
13+
14+
assert.equal(currentURL(), '/search?q=rust');
15+
assert.equal(document.title, 'Search Results for \'rust\' - Cargo: packages for Rust');
16+
17+
findWithAssert('a[href="/search?page=2&q=rust"]');
18+
assert.notOk(find('a[href="/search?page=3&q=rust"]')[0]);
19+
20+
hasText(assert, '#crates-heading', 'Search Results for \'rust\'');
21+
hasText(assert, '#results', 'Displaying 1-10 of 18 total results Sort by Relevance Relevance Downloads');
22+
23+
hasText(assert, '#crates .row:first .desc .info', 'rust_mixin');
24+
findWithAssert('#crates .row:first .desc .info .vers img[alt="0.0.1"]');
25+
26+
findWithAssert('#crates .row:first .desc .info .badge:first a[href="https://ci.appveyor.com/project/huonw/external_mixin"]');
27+
findWithAssert('#crates .row:first .desc .info .badge:first a img[src="https://ci.appveyor.com/api/projects/status/github/huonw/external_mixin?svg=true&branch=master"]');
28+
findWithAssert('#crates .row:first .desc .info .badge:eq(1) a[href="https://codecov.io/github/huonw/external_mixin?branch=master"]');
29+
findWithAssert('#crates .row:first .desc .info .badge:eq(1) a img[src="https://codecov.io/github/huonw/external_mixin/coverage.svg?branch=master"]');
30+
findWithAssert('#crates .row:first .desc .info .badge:eq(2) a[href="https://coveralls.io/github/huonw/external_mixin?branch=master"]');
31+
findWithAssert('#crates .row:first .desc .info .badge:eq(2) a img[src="https://coveralls.io/repos/github/huonw/external_mixin/badge.svg?branch=master"]');
32+
findWithAssert('#crates .row:first .desc .info .badge:eq(3) a[href="https://gitlab.com/huonw/external_mixin/pipelines"]');
33+
findWithAssert('#crates .row:first .desc .info .badge:eq(3) a img[src="https://gitlab.com/huonw/external_mixin/badges/master/build.svg"]');
34+
findWithAssert('#crates .row:first .desc .info .badge:eq(4) a[href="https://isitmaintained.com/project/huonw/external_mixin"]');
35+
findWithAssert('#crates .row:first .desc .info .badge:eq(4) a img[src="https://isitmaintained.com/badge/resolution/huonw/external_mixin.svg"]');
36+
findWithAssert('#crates .row:first .desc .info .badge:eq(5) a[href="https://isitmaintained.com/project/huonw/external_mixin"]');
37+
findWithAssert('#crates .row:first .desc .info .badge:eq(5) a img[src="https://isitmaintained.com/badge/open/huonw/external_mixin.svg"]');
38+
findWithAssert('#crates .row:first .desc .info .badge:eq(6) a[href="https://travis-ci.org/huonw/external_mixin"]');
39+
findWithAssert('#crates .row:first .desc .info .badge:eq(6) a img[src="https://travis-ci.org/huonw/external_mixin.svg?branch=master"]');
40+
41+
hasText(assert, '#crates .row:first .desc .summary', 'Yo dawg, use Rust to generate Rust, right in your Rust. (See `external_mixin` to use scripting languages.)');
42+
hasText(assert, '#crates .row:first .downloads', '477');
43+
44+
await click('a[href="/search?page=2&q=rust"]');
45+
46+
assert.equal(currentURL(), '/search?page=2&q=rust');
47+
assert.equal(document.title, 'Search Results for \'rust\' - Cargo: packages for Rust');
48+
49+
findWithAssert('a[href="/search?q=rust"]');
50+
assert.notOk(find('a[href="/search?page=3&q=rust"]')[0]);
51+
52+
hasText(assert, '#crates-heading', 'Search Results for \'rust\'');
53+
hasText(assert, '#results', 'Displaying 11-18 of 18 total results Sort by Relevance Relevance Downloads');
54+
55+
hasText(assert, '#crates .row:first .desc .info', 'rusted_cypher');
56+
findWithAssert('#crates .row:first .desc .info .vers img[alt="0.7.1"]');
6057
});
6158

62-
test('pressing S key to focus the search bar', function(assert) {
59+
test('pressing S key to focus the search bar', async function(assert) {
6360
const KEYCODE_S = 83;
6461
const KEYCODE_A = 65;
6562

@@ -69,20 +66,19 @@ test('pressing S key to focus the search bar', function(assert) {
6966
$searchBar.blur();
7067
}
7168

72-
visit('/');
73-
andThen(function() {
74-
findWithAssert('#cargo-desktop-search').blur();
75-
});
69+
await visit('/');
7670

77-
keyEvent(document, 'keypress', KEYCODE_A);
78-
andThen(function assertSearchBarIsNotFocused() {
79-
const $searchBar = find('#cargo-desktop-search');
80-
assert.notEqual($searchBar[0], document.activeElement);
81-
$searchBar.blur();
82-
});
71+
findWithAssert('#cargo-desktop-search').blur();
72+
73+
await keyEvent(document, 'keypress', KEYCODE_A);
74+
75+
const $searchBar = find('#cargo-desktop-search');
76+
assert.notEqual($searchBar[0], document.activeElement);
77+
$searchBar.blur();
78+
79+
await keyEvent(document, 'keypress', KEYCODE_S);
80+
assertSearchBarIsFocused();
8381

84-
keyEvent(document, 'keypress', KEYCODE_S);
85-
andThen(assertSearchBarIsFocused);
86-
keyEvent(document, 'keydown', KEYCODE_S);
87-
andThen(assertSearchBarIsFocused);
82+
await keyEvent(document, 'keydown', KEYCODE_S);
83+
assertSearchBarIsFocused();
8884
});

tests/acceptance/team-page-test.js

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,30 @@ import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
33

44
moduleForAcceptance('Acceptance | team page');
55

6-
test('has team organization display', function(assert) {
7-
visit('/teams/github:org:thehydroimpulse');
6+
test('has team organization display', async function(assert) {
7+
await visit('/teams/github:org:thehydroimpulse');
88

9-
andThen(function() {
10-
hasText(assert, '.team-info h1', 'org_test');
11-
hasText(assert, '.team-info h2', 'thehydroimpulseteam');
12-
});
9+
hasText(assert, '.team-info h1', 'org_test');
10+
hasText(assert, '.team-info h2', 'thehydroimpulseteam');
1311
});
1412

15-
test('has link to github in team header', function(assert) {
16-
visit('/teams/github:org:thehydroimpulse');
17-
18-
andThen(function() {
19-
const $githubLink = findWithAssert('.info a');
20-
assert.equal($githubLink.attr('href').trim(), 'https://github.com/org_test');
21-
});
13+
test('has link to github in team header', async function(assert) {
14+
await visit('/teams/github:org:thehydroimpulse');
2215

16+
const $githubLink = findWithAssert('.info a');
17+
assert.equal($githubLink.attr('href').trim(), 'https://github.com/org_test');
2318
});
2419

25-
test('github link has image in team header', function(assert) {
26-
visit('/teams/github:org:thehydroimpulse');
20+
test('github link has image in team header', async function(assert) {
21+
await visit('/teams/github:org:thehydroimpulse');
2722

28-
andThen(function() {
29-
const $githubImg = findWithAssert('.info a img');
30-
assert.equal($githubImg.attr('src').trim(), '/assets/GitHub-Mark-32px.png');
31-
});
23+
const $githubImg = findWithAssert('.info a img');
24+
assert.equal($githubImg.attr('src').trim(), '/assets/GitHub-Mark-32px.png');
3225
});
3326

34-
test('team organization details has github profile icon', function(assert) {
35-
visit('/teams/github:org:thehydroimpulse');
27+
test('team organization details has github profile icon', async function(assert) {
28+
await visit('/teams/github:org:thehydroimpulse');
3629

37-
andThen(function() {
38-
const $githubProfileImg = findWithAssert('.info img');
39-
assert.equal($githubProfileImg.attr('src').trim(), 'https://avatars.githubusercontent.com/u/565790?v=3&s=170');
40-
});
30+
const $githubProfileImg = findWithAssert('.info img');
31+
assert.equal($githubProfileImg.attr('src').trim(), 'https://avatars.githubusercontent.com/u/565790?v=3&s=170');
4132
});

tests/acceptance/user-page-test.js

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,29 @@ import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
33

44
moduleForAcceptance('Acceptance | user page');
55

6-
test('has user display', function(assert) {
7-
visit('/users/thehydroimpulse');
6+
test('has user display', async function(assert) {
7+
await visit('/users/thehydroimpulse');
88

9-
andThen(function() {
10-
hasText(assert, '#crates-heading h1', 'thehydroimpulse');
11-
});
9+
hasText(assert, '#crates-heading h1', 'thehydroimpulse');
1210
});
1311

14-
test('has link to github in user header', function(assert) {
15-
visit('/users/thehydroimpulse');
12+
test('has link to github in user header', async function(assert) {
13+
await visit('/users/thehydroimpulse');
1614

17-
andThen(function() {
18-
const $githubLink = findWithAssert('#crates-heading a');
19-
assert.equal($githubLink.attr('href').trim(), 'https://github.com/thehydroimpulse');
20-
});
15+
const $githubLink = findWithAssert('#crates-heading a');
16+
assert.equal($githubLink.attr('href').trim(), 'https://github.com/thehydroimpulse');
2117
});
2218

23-
test('github link has image in user header', function(assert) {
24-
visit('/users/thehydroimpulse');
19+
test('github link has image in user header', async function(assert) {
20+
await visit('/users/thehydroimpulse');
2521

26-
andThen(function() {
27-
const $githubImg = findWithAssert('#crates-heading a img');
28-
assert.equal($githubImg.attr('src').trim(), '/assets/GitHub-Mark-32px.png');
29-
});
22+
const $githubImg = findWithAssert('#crates-heading a img');
23+
assert.equal($githubImg.attr('src').trim(), '/assets/GitHub-Mark-32px.png');
3024
});
3125

32-
test('user details has github profile icon', function(assert) {
33-
visit('/users/thehydroimpulse');
26+
test('user details has github profile icon', async function(assert) {
27+
await visit('/users/thehydroimpulse');
3428

35-
andThen(function() {
36-
const $githubProfileImg = findWithAssert('#crates-heading img');
37-
assert.equal($githubProfileImg.attr('src').trim(), 'https://avatars.githubusercontent.com/u/565790?v=3&s=170');
38-
});
29+
const $githubProfileImg = findWithAssert('#crates-heading img');
30+
assert.equal($githubProfileImg.attr('src').trim(), 'https://avatars.githubusercontent.com/u/565790?v=3&s=170');
3931
});

0 commit comments

Comments
 (0)