Skip to content

Commit 315a002

Browse files
committed
frontend tests for displaying and sorting by recent downloads
1 parent 162a4a1 commit 315a002

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

mirage/config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ export default function() {
170170
return withMeta(this.serialize(categories), { total });
171171
});
172172

173+
this.get('/categories/:category_id', function(schema, request) {
174+
let catId = request.params.category_id;
175+
let category = schema.categories.find(catId);
176+
return category ? category : notFound();
177+
});
178+
173179
this.get('/keywords', function(schema, request) {
174180
let { start, end } = pageParams(request);
175181

tests/acceptance/categories-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,12 @@ test('listing categories', async function(assert) {
1515
hasText(assert, '.row:eq(1) .desc .info span', '1 crate');
1616
hasText(assert, '.row:eq(2) .desc .info span', '3,910 crates');
1717
});
18+
19+
test('category/:category_id index default sort is recent-downloads', async function(assert) {
20+
server.create('category', { category: 'Algorithms', crates_cnt: 1 });
21+
22+
await visit('/categories/algorithms');
23+
24+
const $sort = findWithAssert('div.sort div.dropdown-container a.dropdown');
25+
hasText(assert, $sort, 'Recent Downloads');
26+
});

tests/acceptance/crates-test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,28 @@ test('navigating to next page of crates', async function(assert) {
4343
hasText(assert, '.amt.small .cur', '11-19');
4444
hasText(assert, '.amt.small .total', '19');
4545
});
46+
47+
test('crates default sort is alphabetical', async function(assert) {
48+
server.loadFixtures();
49+
50+
await visit('/crates');
51+
52+
const $sort = findWithAssert('div.sort div.dropdown-container a.dropdown');
53+
hasText(assert, $sort, 'Alphabetical');
54+
});
55+
56+
test('downloads appears for each crate on crate list', async function(assert) {
57+
server.loadFixtures();
58+
59+
await visit('/crates');
60+
const $recentDownloads = findWithAssert('div.downloads:first span.num');
61+
hasText(assert, $recentDownloads, 'All-Time: 497');
62+
});
63+
64+
test('recent downloads appears for each crate on crate list', async function(assert) {
65+
server.loadFixtures();
66+
67+
await visit('/crates');
68+
const $recentDownloads = findWithAssert('div.recent-downloads:first span.num');
69+
hasText(assert, $recentDownloads, 'Recent:');
70+
});

tests/acceptance/keyword-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { test } from 'qunit';
2+
import moduleForAcceptance from 'cargo/tests/helpers/module-for-acceptance';
3+
import hasText from 'cargo/tests/helpers/has-text';
4+
5+
moduleForAcceptance('Acceptance | keywords');
6+
7+
test('keyword/:keyword_id index default sort is recent-downloads', async function(assert) {
8+
server.create('keyword', { id: 'network', keyword: 'network', crates_cnt: 38 });
9+
10+
await visit('/keywords/network');
11+
12+
const $sort = findWithAssert('div.sort div.dropdown-container a.dropdown');
13+
hasText(assert, $sort, 'Recent Downloads');
14+
});

tests/acceptance/search-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,17 @@ test('pressing S key to focus the search bar', async function(assert) {
5555
await keyEvent(document, 'keydown', KEYCODE_S);
5656
assertSearchBarIsFocused();
5757
});
58+
59+
test('check search results are by default displayed by relevance', async function(assert) {
60+
server.loadFixtures();
61+
62+
await visit('/');
63+
await fillIn('input.search', 'rust');
64+
65+
findWithAssert('form.search').submit();
66+
67+
await wait();
68+
69+
const $sort = findWithAssert('div.sort div.dropdown-container a.dropdown');
70+
hasText(assert, $sort, 'Relevance');
71+
});

0 commit comments

Comments
 (0)