Skip to content

Use High Level DOM Assertions from "qunit-dom" #1127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"emberx-select": "^3.0.1",
"eslint-plugin-ember-suave": "^1.0.0",
"loader.js": "^4.5.1",
"normalize.css": "^7.0.0"
"normalize.css": "^7.0.0",
"qunit-dom": "^0.3.2"
},
"engines": {
"node": "^8.1.3",
Expand Down
10 changes: 4 additions & 6 deletions tests/acceptance/categories-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { test } from 'qunit';
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
import hasText from 'cargo/tests/helpers/has-text';

moduleForAcceptance('Acceptance | categories');

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

await visit('/categories');

hasText(assert, '.row:eq(0) .desc .info span', '0 crates');
hasText(assert, '.row:eq(1) .desc .info span', '1 crate');
hasText(assert, '.row:eq(2) .desc .info span', '3,910 crates');
assert.dom('.desc .info span', find('.row').get(0)).hasText('0 crates');
assert.dom('.desc .info span', find('.row').get(1)).hasText('1 crate');
assert.dom('.desc .info span', find('.row').get(2)).hasText('3,910 crates');
});

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

await visit('/categories/algorithms');

const $sort = findWithAssert('div.sort div.dropdown-container a.dropdown');
hasText(assert, $sort, 'Recent Downloads');
assert.dom('div.sort div.dropdown-container a.dropdown').hasText('Recent Downloads');
});
38 changes: 17 additions & 21 deletions tests/acceptance/crate-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { test } from 'qunit';
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
import matchesText from 'cargo/tests/helpers/matches-text';
import hasText from 'cargo/tests/helpers/has-text';

moduleForAcceptance('Acceptance | crate page');

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

assert.equal(find('#crates-heading .info h1').text(), 'nanomsg');
assert.equal(find('#crates-heading .info h2').text(), '0.6.1');
assert.dom('#crates-heading .info h1').hasText('nanomsg');
assert.dom('#crates-heading .info h2').hasText('0.6.1');
});

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

assert.equal(find('#crates-heading .info h1').text(), 'nanomsg');
assert.equal(find('#crates-heading .info h2').text(), '0.6.1');
assert.dom('#crates-heading .info h1').hasText('nanomsg');
assert.dom('#crates-heading .info h2').hasText('0.6.1');
});

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

assert.equal(find('#crates-heading .info h1').text(), 'nanomsg');
assert.equal(find('#crates-heading .info h2').text(), '0.6.0');
assert.dom('#crates-heading .info h1').hasText('nanomsg');
assert.dom('#crates-heading .info h2').hasText('0.6.0');
});

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

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

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

assert.equal(currentURL(), '/crates/nanomsg/reverse_dependencies');

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

hasText(assert, $revDep, 'unicorn-rpc');
assert.dom('a[href="/crates/unicorn-rpc"]').hasText('unicorn-rpc');
});

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

assert.equal(currentURL(), '/users/blabaere');
hasText(assert, '#crates-heading h1', 'blabaere');
assert.dom('#crates-heading h1').hasText('blabaere');
});

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

assert.equal(currentURL(), '/teams/github:org:thehydroimpulse');
hasText(assert, '.team-info h2', 'thehydroimpulseteam');
assert.dom('.team-info h2').hasText('thehydroimpulseteam');
});

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

await visit('/crates/nanomsg');

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

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

await visit('/crates/nanomsg');

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

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

await visit('/crates/nanomsg');
hasText(assert, '.license', 'Apache-2.0');
assert.dom('.license').hasText('Apache-2.0');

await click('#crate-versions a:contains("0.5.0")');
hasText(assert, '.license', 'MIT/Apache-2.0');
assert.dom('.license').hasText('MIT/Apache-2.0');
});
18 changes: 7 additions & 11 deletions tests/acceptance/crates-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { test } from 'qunit';
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
import hasText from 'cargo/tests/helpers/has-text';

moduleForAcceptance('Acceptance | crates page');

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

await visit('/crates');

hasText(assert, '.amt.small .cur', '1-10');
hasText(assert, '.amt.small .total', '19');
assert.dom('.amt.small .cur').hasText('1-10');
assert.dom('.amt.small .total').hasText('19');
});

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

assert.equal(currentURL(), '/crates?page=2');
hasText(assert, '.amt.small .cur', '11-19');
hasText(assert, '.amt.small .total', '19');
assert.dom('.amt.small .cur').hasText('11-19');
assert.dom('.amt.small .total').hasText('19');
});

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

await visit('/crates');

const $sort = findWithAssert('div.sort div.dropdown-container a.dropdown');
hasText(assert, $sort, 'Alphabetical');
assert.dom('div.sort div.dropdown-container a.dropdown').hasText('Alphabetical');
});

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

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

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

await visit('/crates');
const $recentDownloads = findWithAssert('div.recent-downloads:first span.num');
hasText(assert, $recentDownloads, 'Recent: 497');
assert.dom('div.recent-downloads span.num').hasText('Recent: 497');
});
26 changes: 11 additions & 15 deletions tests/acceptance/front-page-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { test } from 'qunit';
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
import hasText from 'cargo/tests/helpers/has-text';

moduleForAcceptance('Acceptance | front page');

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

findWithAssert('a[href="/install"]');
findWithAssert('a[href="/crates"]');
findWithAssert('a[href="/login"]');
assert.dom('a[href="/install"]').exists();
assert.dom('a[href="/crates"]').exists();
assert.dom('a[href="/login"]').exists();

hasText(assert, '.downloads .num', '122,669');
hasText(assert, '.crates .num', '19');
assert.dom('.downloads .num').hasText('122,669');
assert.dom('.crates .num').hasText('19');

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

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

const $justUpdated = findWithAssert('#just-updated ul > li:first a');
hasText(assert, $justUpdated, 'nanomsg (0.7.0-alpha)');
assert.equal($justUpdated.attr('href').trim(), '/crates/nanomsg');
assert.dom('#just-updated ul > li a').hasText('nanomsg (0.7.0-alpha)');
assert.dom('#just-updated ul > li a').hasAttribute('href', '/crates/nanomsg');
});
4 changes: 1 addition & 3 deletions tests/acceptance/keyword-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { test } from 'qunit';
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
import hasText from 'cargo/tests/helpers/has-text';

moduleForAcceptance('Acceptance | keywords');

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

await visit('/keywords/network');

const $sort = findWithAssert('div.sort div.dropdown-container a.dropdown');
hasText(assert, $sort, 'Recent Downloads');
assert.dom('div.sort div.dropdown-container a.dropdown').hasText('Recent Downloads');
});
30 changes: 12 additions & 18 deletions tests/acceptance/search-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { test } from 'qunit';
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
import hasText from 'cargo/tests/helpers/has-text';

moduleForAcceptance('Acceptance | search');

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

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

hasText(assert, '#crates .row:first .desc .info', 'kinetic-rust');
findWithAssert('#crates .row:first .desc .info .vers img[alt="0.0.16"]');

hasText(assert, '#crates .row:first .desc .summary', 'A Kinetic protocol library written in Rust');
hasText(assert, '#crates .row:first .downloads', 'All-Time: 225');
findWithAssert('#crates .row:first .desc .info img[alt="Maintenance intention for this crate"]');
assert.dom('#crates .row .desc .summary').hasText('A Kinetic protocol library written in Rust');
assert.dom('#crates .row .downloads').hasText('All-Time: 225');
assert.dom('#crates .row .desc .info img[alt="Maintenance intention for this crate"]').exists();
});

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

function assertSearchBarIsFocused() {
const $searchBar = find('#cargo-desktop-search');
assert.equal($searchBar[0], document.activeElement);
$searchBar.blur();
assert.dom('#cargo-desktop-search').isFocused();
find('#cargo-desktop-search').blur();
}

await visit('/');

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

await keyEvent(document, 'keypress', KEYCODE_A);

const $searchBar = find('#cargo-desktop-search');
assert.notEqual($searchBar[0], document.activeElement);
$searchBar.blur();
assert.dom('#cargo-desktop-search').isNotFocused();
find('#cargo-desktop-search').blur();

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

await wait();

const $sort = findWithAssert('div.sort div.dropdown-container a.dropdown');
hasText(assert, $sort, 'Relevance');
assert.dom('div.sort div.dropdown-container a.dropdown').hasText('Relevance');
});
14 changes: 5 additions & 9 deletions tests/acceptance/team-page-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { test } from 'qunit';
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
import hasText from 'cargo/tests/helpers/has-text';

moduleForAcceptance('Acceptance | team page');

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

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

hasText(assert, '.team-info h1', 'org');
hasText(assert, '.team-info h2', 'thehydroimpulseteam');
assert.dom('.team-info h1').hasText('org');
assert.dom('.team-info h2').hasText('thehydroimpulseteam');
});

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

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

const $githubLink = findWithAssert('.info a');
assert.equal($githubLink.attr('href').trim(), 'https://github.com/org_test');
assert.dom('.info a').hasAttribute('href', 'https://github.com/org_test');
});

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

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

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

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

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

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