diff --git a/app/templates/categories.hbs b/app/templates/categories.hbs index f591598e2db..29adf9860b6 100644 --- a/app/templates/categories.hbs +++ b/app/templates/categories.hbs @@ -27,7 +27,7 @@ {{category.category}} - {{ pluralize (format-num category.crates_cnt) "crate" }} + {{format-num category.crates_cnt}} {{if (eq category.crates_cnt 1) "crate" "crates"}}
diff --git a/app/templates/category/index.hbs b/app/templates/category/index.hbs index e66ae510ead..732969b1fd3 100644 --- a/app/templates/category/index.hbs +++ b/app/templates/category/index.hbs @@ -21,7 +21,7 @@
{{subcategory.category}} - {{ pluralize (format-num subcategory.crates_cnt) "crate" }} + {{format-num subcategory.crates_cnt}} {{if (eq subcategory.crates_cnt 1) "crate" "crates"}}
diff --git a/app/templates/keywords.hbs b/app/templates/keywords.hbs index 22e437fcaae..320ba30c3a0 100644 --- a/app/templates/keywords.hbs +++ b/app/templates/keywords.hbs @@ -24,7 +24,7 @@
{{keyword.id}} - {{ pluralize (format-num keyword.crates_cnt) "crate" }} + {{format-num keyword.crates_cnt}} {{if (eq keyword.crates_cnt 1) "crate" "crates"}}
{{/each}} diff --git a/mirage/serializers/category.js b/mirage/serializers/category.js index dad1fee24af..5d3cacb04eb 100644 --- a/mirage/serializers/category.js +++ b/mirage/serializers/category.js @@ -19,6 +19,6 @@ export default BaseSerializer.extend({ let allCrates = this.schema.crates.all(); let associatedCrates = allCrates.filter(it => it.categoryIds.includes(hash.id)); - hash.crates_cnt = associatedCrates.length; + hash.crates_cnt ??= associatedCrates.length; }, }); diff --git a/mirage/serializers/keyword.js b/mirage/serializers/keyword.js index aba4d7ff4e9..bad201b12cf 100644 --- a/mirage/serializers/keyword.js +++ b/mirage/serializers/keyword.js @@ -19,6 +19,6 @@ export default BaseSerializer.extend({ let allCrates = this.schema.crates.all(); let associatedCrates = allCrates.filter(it => it.keywordIds.includes(hash.id)); - hash.crates_cnt = associatedCrates.length; + hash.crates_cnt ??= associatedCrates.length; }, }); diff --git a/tests/acceptance/categories-test.js b/tests/acceptance/categories-test.js index 97a40b9ddfd..3e32f70f50e 100644 --- a/tests/acceptance/categories-test.js +++ b/tests/acceptance/categories-test.js @@ -4,31 +4,47 @@ import { module, test } from 'qunit'; import percySnapshot from '@percy/ember'; import a11yAudit from 'ember-a11y-testing/test-support/audit'; +import window from 'ember-window-mock'; +import { setupWindowMock } from 'ember-window-mock/test-support'; import axeConfig from '../axe-config'; import setupMirage from '../helpers/setup-mirage'; module('Acceptance | categories', function (hooks) { setupApplicationTest(hooks); + setupWindowMock(hooks); setupMirage(hooks); test('listing categories', async function (assert) { + window.navigator = { languages: ['en'] }; + this.server.create('category', { category: 'API bindings' }); this.server.create('category', { category: 'Algorithms' }); this.server.createList('crate', 1, { categoryIds: ['algorithms'] }); this.server.create('category', { category: 'Asynchronous' }); this.server.createList('crate', 15, { categoryIds: ['asynchronous'] }); + this.server.create('category', { category: 'Everything', crates_cnt: 1234 }); await visit('/categories'); assert.dom('[data-test-category="api-bindings"] [data-test-crate-count]').hasText('0 crates'); assert.dom('[data-test-category="algorithms"] [data-test-crate-count]').hasText('1 crate'); assert.dom('[data-test-category="asynchronous"] [data-test-crate-count]').hasText('15 crates'); + assert.dom('[data-test-category="everything"] [data-test-crate-count]').hasText('1,234 crates'); await percySnapshot(assert); await a11yAudit(axeConfig); }); + test('listing categories (locale: de)', async function (assert) { + window.navigator = { languages: ['de'] }; + + this.server.create('category', { category: 'Everything', crates_cnt: 1234 }); + + await visit('/categories'); + assert.dom('[data-test-category="everything"] [data-test-crate-count]').hasText('1.234 crates'); + }); + test('category/:category_id index default sort is recent-downloads', async function (assert) { this.server.create('category', { category: 'Algorithms' });