Skip to content

Commit ef1ac58

Browse files
authored
Merge pull request #1127 from Turbo87/qunit-dom
Use High Level DOM Assertions from "qunit-dom"
2 parents a26f307 + eba431a commit ef1ac58

12 files changed

+63
-106
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
"emberx-select": "^3.0.1",
6363
"eslint-plugin-ember-suave": "^1.0.0",
6464
"loader.js": "^4.5.1",
65-
"normalize.css": "^7.0.0"
65+
"normalize.css": "^7.0.0",
66+
"qunit-dom": "^0.3.2"
6667
},
6768
"engines": {
6869
"node": "^8.1.3",

tests/acceptance/categories-test.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { test } from 'qunit';
22
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
3-
import hasText from 'cargo/tests/helpers/has-text';
43

54
moduleForAcceptance('Acceptance | categories');
65

@@ -11,16 +10,15 @@ test('listing categories', async function(assert) {
1110

1211
await visit('/categories');
1312

14-
hasText(assert, '.row:eq(0) .desc .info span', '0 crates');
15-
hasText(assert, '.row:eq(1) .desc .info span', '1 crate');
16-
hasText(assert, '.row:eq(2) .desc .info span', '3,910 crates');
13+
assert.dom('.desc .info span', find('.row').get(0)).hasText('0 crates');
14+
assert.dom('.desc .info span', find('.row').get(1)).hasText('1 crate');
15+
assert.dom('.desc .info span', find('.row').get(2)).hasText('3,910 crates');
1716
});
1817

1918
test('category/:category_id index default sort is recent-downloads', async function(assert) {
2019
server.create('category', { category: 'Algorithms', crates_cnt: 1 });
2120

2221
await visit('/categories/algorithms');
2322

24-
const $sort = findWithAssert('div.sort div.dropdown-container a.dropdown');
25-
hasText(assert, $sort, 'Recent Downloads');
23+
assert.dom('div.sort div.dropdown-container a.dropdown').hasText('Recent Downloads');
2624
});

tests/acceptance/crate-test.js

+17-21
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { test } from 'qunit';
22
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
3-
import matchesText from 'cargo/tests/helpers/matches-text';
4-
import hasText from 'cargo/tests/helpers/has-text';
53

64
moduleForAcceptance('Acceptance | crate page');
75

@@ -26,8 +24,8 @@ test('visiting /crates/nanomsg', async function(assert) {
2624
assert.equal(currentRouteName(), 'crate.index');
2725
assert.equal(document.title, 'nanomsg - Cargo: packages for Rust');
2826

29-
assert.equal(find('#crates-heading .info h1').text(), 'nanomsg');
30-
assert.equal(find('#crates-heading .info h2').text(), '0.6.1');
27+
assert.dom('#crates-heading .info h1').hasText('nanomsg');
28+
assert.dom('#crates-heading .info h2').hasText('0.6.1');
3129
});
3230

3331
test('visiting /crates/nanomsg/', async function(assert) {
@@ -41,8 +39,8 @@ test('visiting /crates/nanomsg/', async function(assert) {
4139
assert.equal(currentRouteName(), 'crate.index');
4240
assert.equal(document.title, 'nanomsg - Cargo: packages for Rust');
4341

44-
assert.equal(find('#crates-heading .info h1').text(), 'nanomsg');
45-
assert.equal(find('#crates-heading .info h2').text(), '0.6.1');
42+
assert.dom('#crates-heading .info h1').hasText('nanomsg');
43+
assert.dom('#crates-heading .info h2').hasText('0.6.1');
4644
});
4745

4846
test('visiting /crates/nanomsg/0.6.0', async function(assert) {
@@ -56,8 +54,8 @@ test('visiting /crates/nanomsg/0.6.0', async function(assert) {
5654
assert.equal(currentRouteName(), 'crate.version');
5755
assert.equal(document.title, 'nanomsg - Cargo: packages for Rust');
5856

59-
assert.equal(find('#crates-heading .info h1').text(), 'nanomsg');
60-
assert.equal(find('#crates-heading .info h2').text(), '0.6.0');
57+
assert.dom('#crates-heading .info h1').hasText('nanomsg');
58+
assert.dom('#crates-heading .info h2').hasText('0.6.0');
6159
});
6260

6361
test('navigating to the all versions page', async function(assert) {
@@ -66,7 +64,7 @@ test('navigating to the all versions page', async function(assert) {
6664
await visit('/crates/nanomsg');
6765
await click('#crate-versions span.small a');
6866

69-
matchesText(assert, '.info', /All 13 versions of nanomsg since December \d+, 2014/);
67+
assert.dom('.info').hasText(/All 13\s+versions of nanomsg since\s+December \d+, 2014/);
7068
});
7169

7270
test('navigating to the reverse dependencies page', async function(assert) {
@@ -76,10 +74,7 @@ test('navigating to the reverse dependencies page', async function(assert) {
7674
await click('a:contains("Dependent crates")');
7775

7876
assert.equal(currentURL(), '/crates/nanomsg/reverse_dependencies');
79-
80-
const $revDep = findWithAssert('a[href="/crates/unicorn-rpc"]:first');
81-
82-
hasText(assert, $revDep, 'unicorn-rpc');
77+
assert.dom('a[href="/crates/unicorn-rpc"]').hasText('unicorn-rpc');
8378
});
8479

8580
test('navigating to a user page', async function(assert) {
@@ -89,7 +84,7 @@ test('navigating to a user page', async function(assert) {
8984
await click('.owners li:last a');
9085

9186
assert.equal(currentURL(), '/users/blabaere');
92-
hasText(assert, '#crates-heading h1', 'blabaere');
87+
assert.dom('#crates-heading h1').hasText('blabaere');
9388
});
9489

9590
test('navigating to a team page', async function(assert) {
@@ -99,32 +94,33 @@ test('navigating to a team page', async function(assert) {
9994
await click('.owners li:first a ');
10095

10196
assert.equal(currentURL(), '/teams/github:org:thehydroimpulse');
102-
hasText(assert, '.team-info h2', 'thehydroimpulseteam');
97+
assert.dom('.team-info h2').hasText('thehydroimpulseteam');
10398
});
10499

105100
test('crates having user-owners', async function(assert) {
106101
server.loadFixtures();
107102

108103
await visit('/crates/nanomsg');
109104

110-
findWithAssert('ul.owners li:first a[href="/teams/github:org:thehydroimpulse"] img[src="https://avatars.githubusercontent.com/u/565790?v=3&s=64"]');
111-
assert.equal(find('ul.owners li').length, 4);
105+
assert.dom('ul.owners li a[href="/teams/github:org:thehydroimpulse"] img[src="https://avatars.githubusercontent.com/u/565790?v=3&s=64"]').exists();
106+
assert.dom('ul.owners li').exists({ count: 4 });
112107
});
113108

114109
test('crates having team-owners', async function(assert) {
115110
server.loadFixtures();
116111

117112
await visit('/crates/nanomsg');
118113

119-
findWithAssert('ul.owners li:first a[href="/teams/github:org:thehydroimpulse"]');
120-
assert.equal(find('ul.owners li').length, 4);
114+
assert.dom('ul.owners li a[href="/teams/github:org:thehydroimpulse"]').exists();
115+
assert.dom('ul.owners li').exists({ count: 4 });
121116
});
122117

123118
test('crates license is supplied by version', async function(assert) {
124119
server.loadFixtures();
125120

126121
await visit('/crates/nanomsg');
127-
hasText(assert, '.license', 'Apache-2.0');
122+
assert.dom('.license').hasText('Apache-2.0');
123+
128124
await click('#crate-versions a:contains("0.5.0")');
129-
hasText(assert, '.license', 'MIT/Apache-2.0');
125+
assert.dom('.license').hasText('MIT/Apache-2.0');
130126
});

tests/acceptance/crates-test.js

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { test } from 'qunit';
22
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
3-
import hasText from 'cargo/tests/helpers/has-text';
43

54
moduleForAcceptance('Acceptance | crates page');
65

@@ -29,8 +28,8 @@ test('listing crates', async function(assert) {
2928

3029
await visit('/crates');
3130

32-
hasText(assert, '.amt.small .cur', '1-10');
33-
hasText(assert, '.amt.small .total', '19');
31+
assert.dom('.amt.small .cur').hasText('1-10');
32+
assert.dom('.amt.small .total').hasText('19');
3433
});
3534

3635
test('navigating to next page of crates', async function(assert) {
@@ -40,31 +39,28 @@ test('navigating to next page of crates', async function(assert) {
4039
await click('.pagination .next');
4140

4241
assert.equal(currentURL(), '/crates?page=2');
43-
hasText(assert, '.amt.small .cur', '11-19');
44-
hasText(assert, '.amt.small .total', '19');
42+
assert.dom('.amt.small .cur').hasText('11-19');
43+
assert.dom('.amt.small .total').hasText('19');
4544
});
4645

4746
test('crates default sort is alphabetical', async function(assert) {
4847
server.loadFixtures();
4948

5049
await visit('/crates');
5150

52-
const $sort = findWithAssert('div.sort div.dropdown-container a.dropdown');
53-
hasText(assert, $sort, 'Alphabetical');
51+
assert.dom('div.sort div.dropdown-container a.dropdown').hasText('Alphabetical');
5452
});
5553

5654
test('downloads appears for each crate on crate list', async function(assert) {
5755
server.loadFixtures();
5856

5957
await visit('/crates');
60-
const $recentDownloads = findWithAssert('div.downloads:first span.num');
61-
hasText(assert, $recentDownloads, 'All-Time: 497');
58+
assert.dom('div.downloads span.num').hasText('All-Time: 497');
6259
});
6360

6461
test('recent downloads appears for each crate on crate list', async function(assert) {
6562
server.loadFixtures();
6663

6764
await visit('/crates');
68-
const $recentDownloads = findWithAssert('div.recent-downloads:first span.num');
69-
hasText(assert, $recentDownloads, 'Recent: 497');
65+
assert.dom('div.recent-downloads span.num').hasText('Recent: 497');
7066
});

tests/acceptance/front-page-test.js

+11-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { test } from 'qunit';
22
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
3-
import hasText from 'cargo/tests/helpers/has-text';
43

54
moduleForAcceptance('Acceptance | front page');
65

@@ -12,22 +11,19 @@ test('visiting /', async function(assert) {
1211
assert.equal(currentURL(), '/');
1312
assert.equal(document.title, 'Cargo: packages for Rust');
1413

15-
findWithAssert('a[href="/install"]');
16-
findWithAssert('a[href="/crates"]');
17-
findWithAssert('a[href="/login"]');
14+
assert.dom('a[href="/install"]').exists();
15+
assert.dom('a[href="/crates"]').exists();
16+
assert.dom('a[href="/login"]').exists();
1817

19-
hasText(assert, '.downloads .num', '122,669');
20-
hasText(assert, '.crates .num', '19');
18+
assert.dom('.downloads .num').hasText('122,669');
19+
assert.dom('.crates .num').hasText('19');
2120

22-
const $newCrate = findWithAssert('#new-crates ul > li:first a');
23-
hasText(assert, $newCrate, 'Inflector (0.1.6)');
24-
assert.equal($newCrate.attr('href').trim(), '/crates/Inflector');
21+
assert.dom('#new-crates ul > li a').hasText('Inflector (0.1.6)');
22+
assert.dom('#new-crates ul > li a').hasAttribute('href', '/crates/Inflector');
2523

26-
const $mostDownloaded = findWithAssert('#most-downloaded ul > li:first a');
27-
hasText(assert, $mostDownloaded, 'serde (0.6.1)');
28-
assert.equal($mostDownloaded.attr('href').trim(), '/crates/serde');
24+
assert.dom('#most-downloaded ul > li a').hasText('serde (0.6.1)');
25+
assert.dom('#most-downloaded ul > li a').hasAttribute('href', '/crates/serde');
2926

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

tests/acceptance/keyword-test.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { test } from 'qunit';
22
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
3-
import hasText from 'cargo/tests/helpers/has-text';
43

54
moduleForAcceptance('Acceptance | keywords');
65

@@ -9,6 +8,5 @@ test('keyword/:keyword_id index default sort is recent-downloads', async functio
98

109
await visit('/keywords/network');
1110

12-
const $sort = findWithAssert('div.sort div.dropdown-container a.dropdown');
13-
hasText(assert, $sort, 'Recent Downloads');
11+
assert.dom('div.sort div.dropdown-container a.dropdown').hasText('Recent Downloads');
1412
});

tests/acceptance/search-test.js

+12-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { test } from 'qunit';
22
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
3-
import hasText from 'cargo/tests/helpers/has-text';
43

54
moduleForAcceptance('Acceptance | search');
65

@@ -17,15 +16,14 @@ test('searching for "rust"', async function(assert) {
1716
assert.equal(currentURL(), '/search?q=rust');
1817
assert.equal(document.title, 'Search Results for \'rust\' - Cargo: packages for Rust');
1918

20-
hasText(assert, '#crates-heading', 'Search Results for \'rust\'');
21-
hasText(assert, '#results', 'Displaying 1-8 of 8 total results Sort by Relevance Relevance All-Time Downloads Recent Downloads');
19+
assert.dom('#crates-heading').hasText('Search Results for \'rust\'');
20+
assert.dom('#results').hasText('Displaying 1-8 of 8 total results Sort by Relevance Relevance All-Time Downloads Recent Downloads');
21+
assert.dom('#crates .row .desc .info').hasText('kinetic-rust');
22+
assert.dom('#crates .row .desc .info .vers img[alt="0.0.16"]').exists();
2223

23-
hasText(assert, '#crates .row:first .desc .info', 'kinetic-rust');
24-
findWithAssert('#crates .row:first .desc .info .vers img[alt="0.0.16"]');
25-
26-
hasText(assert, '#crates .row:first .desc .summary', 'A Kinetic protocol library written in Rust');
27-
hasText(assert, '#crates .row:first .downloads', 'All-Time: 225');
28-
findWithAssert('#crates .row:first .desc .info img[alt="Maintenance intention for this crate"]');
24+
assert.dom('#crates .row .desc .summary').hasText('A Kinetic protocol library written in Rust');
25+
assert.dom('#crates .row .downloads').hasText('All-Time: 225');
26+
assert.dom('#crates .row .desc .info img[alt="Maintenance intention for this crate"]').exists();
2927
});
3028

3129
test('pressing S key to focus the search bar', async function(assert) {
@@ -35,20 +33,17 @@ test('pressing S key to focus the search bar', async function(assert) {
3533
const KEYCODE_A = 65;
3634

3735
function assertSearchBarIsFocused() {
38-
const $searchBar = find('#cargo-desktop-search');
39-
assert.equal($searchBar[0], document.activeElement);
40-
$searchBar.blur();
36+
assert.dom('#cargo-desktop-search').isFocused();
37+
find('#cargo-desktop-search').blur();
4138
}
4239

4340
await visit('/');
4441

4542
findWithAssert('#cargo-desktop-search').blur();
4643

4744
await keyEvent(document, 'keypress', KEYCODE_A);
48-
49-
const $searchBar = find('#cargo-desktop-search');
50-
assert.notEqual($searchBar[0], document.activeElement);
51-
$searchBar.blur();
45+
assert.dom('#cargo-desktop-search').isNotFocused();
46+
find('#cargo-desktop-search').blur();
5247

5348
await keyEvent(document, 'keypress', KEYCODE_S);
5449
assertSearchBarIsFocused();
@@ -67,6 +62,5 @@ test('check search results are by default displayed by relevance', async functio
6762

6863
await wait();
6964

70-
const $sort = findWithAssert('div.sort div.dropdown-container a.dropdown');
71-
hasText(assert, $sort, 'Relevance');
65+
assert.dom('div.sort div.dropdown-container a.dropdown').hasText('Relevance');
7266
});

tests/acceptance/team-page-test.js

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { test } from 'qunit';
22
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
3-
import hasText from 'cargo/tests/helpers/has-text';
43

54
moduleForAcceptance('Acceptance | team page');
65

@@ -9,33 +8,30 @@ test('has team organization display', async function(assert) {
98

109
await visit('/teams/github:org:thehydroimpulse');
1110

12-
hasText(assert, '.team-info h1', 'org');
13-
hasText(assert, '.team-info h2', 'thehydroimpulseteam');
11+
assert.dom('.team-info h1').hasText('org');
12+
assert.dom('.team-info h2').hasText('thehydroimpulseteam');
1413
});
1514

1615
test('has link to github in team header', async function(assert) {
1716
server.loadFixtures();
1817

1918
await visit('/teams/github:org:thehydroimpulse');
2019

21-
const $githubLink = findWithAssert('.info a');
22-
assert.equal($githubLink.attr('href').trim(), 'https://github.com/org_test');
20+
assert.dom('.info a').hasAttribute('href', 'https://github.com/org_test');
2321
});
2422

2523
test('github link has image in team header', async function(assert) {
2624
server.loadFixtures();
2725

2826
await visit('/teams/github:org:thehydroimpulse');
2927

30-
const $githubImg = findWithAssert('.info a img');
31-
assert.equal($githubImg.attr('src').trim(), '/assets/GitHub-Mark-32px.png');
28+
assert.dom('.info a img').hasAttribute('src', '/assets/GitHub-Mark-32px.png');
3229
});
3330

3431
test('team organization details has github profile icon', async function(assert) {
3532
server.loadFixtures();
3633

3734
await visit('/teams/github:org:thehydroimpulse');
3835

39-
const $githubProfileImg = findWithAssert('.info img');
40-
assert.equal($githubProfileImg.attr('src').trim(), 'https://avatars.githubusercontent.com/u/565790?v=3&s=170');
36+
assert.dom('.info img').hasAttribute('src', 'https://avatars.githubusercontent.com/u/565790?v=3&s=170');
4137
});

0 commit comments

Comments
 (0)