diff --git a/package.json b/package.json index 1b46e860e1..5de68879ca 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/acceptance/categories-test.js b/tests/acceptance/categories-test.js index 32e57755f6..9fc4c02df0 100644 --- a/tests/acceptance/categories-test.js +++ b/tests/acceptance/categories-test.js @@ -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'); @@ -11,9 +10,9 @@ 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) { @@ -21,6 +20,5 @@ test('category/:category_id index default sort is recent-downloads', async funct 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'); }); diff --git a/tests/acceptance/crate-test.js b/tests/acceptance/crate-test.js index ab57ee90b5..67e9c6297e 100644 --- a/tests/acceptance/crate-test.js +++ b/tests/acceptance/crate-test.js @@ -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'); @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -99,7 +94,7 @@ 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) { @@ -107,8 +102,8 @@ test('crates having user-owners', async function(assert) { 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) { @@ -116,15 +111,16 @@ test('crates having team-owners', async function(assert) { 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'); }); diff --git a/tests/acceptance/crates-test.js b/tests/acceptance/crates-test.js index 594f30cfa6..31f2fc9d22 100644 --- a/tests/acceptance/crates-test.js +++ b/tests/acceptance/crates-test.js @@ -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'); @@ -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) { @@ -40,8 +39,8 @@ 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) { @@ -49,22 +48,19 @@ test('crates default sort is alphabetical', async function(assert) { 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'); }); diff --git a/tests/acceptance/front-page-test.js b/tests/acceptance/front-page-test.js index 7ebdcda54a..6301de9976 100644 --- a/tests/acceptance/front-page-test.js +++ b/tests/acceptance/front-page-test.js @@ -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'); @@ -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'); }); diff --git a/tests/acceptance/keyword-test.js b/tests/acceptance/keyword-test.js index b89a2b9406..ec007c5168 100644 --- a/tests/acceptance/keyword-test.js +++ b/tests/acceptance/keyword-test.js @@ -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'); @@ -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'); }); diff --git a/tests/acceptance/search-test.js b/tests/acceptance/search-test.js index 0ae40213d5..e5b8791ebf 100644 --- a/tests/acceptance/search-test.js +++ b/tests/acceptance/search-test.js @@ -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'); @@ -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) { @@ -35,9 +33,8 @@ 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('/'); @@ -45,10 +42,8 @@ test('pressing S key to focus the search bar', async function(assert) { 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(); @@ -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'); }); diff --git a/tests/acceptance/team-page-test.js b/tests/acceptance/team-page-test.js index e96d5af61c..c4bd7345db 100644 --- a/tests/acceptance/team-page-test.js +++ b/tests/acceptance/team-page-test.js @@ -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'); @@ -9,8 +8,8 @@ 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) { @@ -18,8 +17,7 @@ test('has link to github in team header', async function(assert) { 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) { @@ -27,8 +25,7 @@ test('github link has image in team header', async function(assert) { 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) { @@ -36,6 +33,5 @@ test('team organization details has github profile icon', async function(assert) 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'); }); diff --git a/tests/acceptance/user-page-test.js b/tests/acceptance/user-page-test.js index 4559e07f1c..017d7763fe 100644 --- a/tests/acceptance/user-page-test.js +++ b/tests/acceptance/user-page-test.js @@ -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 | user page'); @@ -9,7 +8,7 @@ test('has user display', async function(assert) { await visit('/users/thehydroimpulse'); - hasText(assert, '#crates-heading h1', 'thehydroimpulse'); + assert.dom('#crates-heading h1').hasText('thehydroimpulse'); }); test('has link to github in user header', async function(assert) { @@ -17,8 +16,7 @@ test('has link to github in user header', async function(assert) { await visit('/users/thehydroimpulse'); - const $githubLink = findWithAssert('#crates-heading a'); - assert.equal($githubLink.attr('href').trim(), 'https://github.com/thehydroimpulse'); + assert.dom('#crates-heading a').hasAttribute('href', 'https://github.com/thehydroimpulse'); }); test('github link has image in user header', async function(assert) { @@ -26,8 +24,7 @@ test('github link has image in user header', async function(assert) { await visit('/users/thehydroimpulse'); - const $githubImg = findWithAssert('#crates-heading a img'); - assert.equal($githubImg.attr('src').trim(), '/assets/GitHub-Mark-32px.png'); + assert.dom('#crates-heading a img').hasAttribute('src', '/assets/GitHub-Mark-32px.png'); }); test('user details has github profile icon', async function(assert) { @@ -35,6 +32,5 @@ test('user details has github profile icon', async function(assert) { await visit('/users/thehydroimpulse'); - const $githubProfileImg = findWithAssert('#crates-heading img'); - assert.equal($githubProfileImg.attr('src').trim(), 'https://avatars.githubusercontent.com/u/565790?v=3&s=170'); + assert.dom('#crates-heading img').hasAttribute('src', 'https://avatars.githubusercontent.com/u/565790?v=3&s=170'); }); diff --git a/tests/helpers/has-text.js b/tests/helpers/has-text.js deleted file mode 100644 index 3852fd39e5..0000000000 --- a/tests/helpers/has-text.js +++ /dev/null @@ -1,3 +0,0 @@ -export default function hasText(assert, selector, expected) { - assert.equal(findWithAssert(selector).text().trim().replace(/\s+/g, ' '), expected); -} diff --git a/tests/helpers/matches-text.js b/tests/helpers/matches-text.js deleted file mode 100644 index 5a2a8301a4..0000000000 --- a/tests/helpers/matches-text.js +++ /dev/null @@ -1,9 +0,0 @@ -export default function matchesText(assert, selector, expectedRegex) { - const $selected = findWithAssert(selector); - const $actual = $selected.text().trim().replace(/\s+/g, ' '); - assert.notEqual( - null, - $actual.match(expectedRegex), - `Text found ('${$actual}') did not match regex ('${expectedRegex}')` - ); -} diff --git a/tests/helpers/start-app.js b/tests/helpers/start-app.js index 5234c2d205..882629c4a4 100644 --- a/tests/helpers/start-app.js +++ b/tests/helpers/start-app.js @@ -2,8 +2,6 @@ import { run } from '@ember/runloop'; import { assign } from '@ember/polyfills'; import Application from '../../app'; import config from '../../config/environment'; -import './has-text'; -import './matches-text'; export default function startApp(attrs) { let application;