Skip to content
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

Fix Search header doesn't mention type #3154 #3161

Merged
merged 8 commits into from
Sep 20, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 40 additions & 1 deletion src/amo/components/SearchContextCard/index.js
Expand Up @@ -5,6 +5,12 @@ import { compose } from 'redux';

import translate from 'core/i18n/translate';
import Card from 'ui/components/Card';
import {
ADDON_TYPE_EXTENSION,
ADDON_TYPE_DICT,
ADDON_TYPE_LANG,
ADDON_TYPE_THEME,
} from 'core/constants';

import './styles.scss';

Expand All @@ -25,10 +31,43 @@ export class SearchContextCardBase extends React.Component {
render() {
const { count, filters, i18n, loading } = this.props;
const { query } = filters;
const { addonType } = filters;

let searchText;

if (!loading && query) {
if (!loading && query && addonType) {
if (addonType === ADDON_TYPE_EXTENSION) {
searchText = i18n.sprintf(i18n.ngettext(
'%(count)s extension found for "%(query)s"',
'%(count)s extensions found for "%(query)s"',
count), { count: i18n.formatNumber(count), query }
);
} else if (addonType === ADDON_TYPE_DICT) {
searchText = i18n.sprintf(i18n.ngettext(
'%(count)s dictionary found for "%(query)s"',
'%(count)s dictionaries found for "%(query)s"',
count), { count: i18n.formatNumber(count), query }
);
} else if (addonType === ADDON_TYPE_LANG) {
searchText = i18n.sprintf(i18n.ngettext(
'%(count)s language pack found for "%(query)s"',
'%(count)s language packs found for "%(query)s"',
count), { count: i18n.formatNumber(count), query }
);
} else if (addonType === ADDON_TYPE_THEME) {
searchText = i18n.sprintf(i18n.ngettext(
'%(count)s theme found for "%(query)s"',
'%(count)s themes found for "%(query)s"',
count), { count: i18n.formatNumber(count), query }
);
} else {
searchText = i18n.sprintf(i18n.ngettext(
'%(count)s result found for "%(query)s"',
'%(count)s results found for "%(query)s"',
count), { count: i18n.formatNumber(count), query }
);
}
} else if (!loading && query) {
searchText = i18n.sprintf(i18n.ngettext(
'%(count)s result for "%(query)s"',
'%(count)s results for "%(query)s"',
Expand Down
153 changes: 152 additions & 1 deletion tests/unit/amo/components/TestSearchContextCard.js
Expand Up @@ -10,7 +10,12 @@ import {
fakeAddon,
} from 'tests/unit/amo/helpers';
import { getFakeI18nInst, shallowUntilTarget } from 'tests/unit/helpers';

import {
ADDON_TYPE_EXTENSION,
ADDON_TYPE_DICT,
ADDON_TYPE_LANG,
ADDON_TYPE_THEME,
} from 'core/constants';

describe('SearchContextCard', () => {
let _store;
Expand Down Expand Up @@ -104,4 +109,150 @@ describe('SearchContextCard', () => {
expect(root.find('.SearchContextCard-header'))
.toIncludeText('No add-ons found');
});

it('should render singular form when only one result is found with addonType ADDON_TYPE_THEME', () => {
const { store } = dispatchSearchResults({
addons: { [fakeAddon.slug]: fakeAddon },
filters: {
addonType: ADDON_TYPE_THEME,
query: 'test',
},
});

const root = render({ store });

expect(root.find('.SearchContextCard-header'))
.toIncludeText('1 theme found for "test"');
});

it('should render plural form when multiple results are found with addonType ADDON_TYPE_THEME', () => {
const { store } = dispatchSearchResults({
filters: {
addonType: ADDON_TYPE_THEME,
query: 'test',
},
});

const root = render({ store });

expect(root.find('.SearchContextCard-header'))
.toIncludeText('2 themes found for "test"');
});

it('should render singular form when only one result is found with addonType ADDON_TYPE_DICT', () => {
const { store } = dispatchSearchResults({
addons: { [fakeAddon.slug]: fakeAddon },
filters: {
addonType: ADDON_TYPE_DICT,
query: 'test',
},
});

const root = render({ store });

expect(root.find('.SearchContextCard-header'))
.toIncludeText('1 dictionary found for "test"');
});

it('should render plural form when multiple results are found with addonType ADDON_TYPE_DICT', () => {
const { store } = dispatchSearchResults({
filters: {
addonType: ADDON_TYPE_DICT,
query: 'test',
},
});

const root = render({ store });

expect(root.find('.SearchContextCard-header'))
.toIncludeText('2 dictionaries found for "test"');
});

it('should render singular form when only one result is found with addonType ADDON_TYPE_EXTENSION', () => {
const { store } = dispatchSearchResults({
addons: { [fakeAddon.slug]: fakeAddon },
filters: {
addonType: ADDON_TYPE_EXTENSION,
query: 'test',
},
});

const root = render({ store });

expect(root.find('.SearchContextCard-header'))
.toIncludeText('1 extension found for "test"');
});

it('should render plural form when multiple results are found with addonType ADDON_TYPE_EXTENSION', () => {
const { store } = dispatchSearchResults({
filters: {
addonType: ADDON_TYPE_EXTENSION,
query: 'test',
},
});

const root = render({ store });

expect(root.find('.SearchContextCard-header'))
.toIncludeText('2 extensions found for "test"');
});

it('should render singular form when only one result is found with addonType ADDON_TYPE_LANG', () => {
const { store } = dispatchSearchResults({
addons: { [fakeAddon.slug]: fakeAddon },
filters: {
addonType: ADDON_TYPE_LANG,
query: 'test',
},
});

const root = render({ store });

expect(root.find('.SearchContextCard-header'))
.toIncludeText('1 language pack found for "test"');
});

it('should render plural form when multiple results are found with addonType ADDON_TYPE_LANG', () => {
const { store } = dispatchSearchResults({
filters: {
addonType: ADDON_TYPE_LANG,
query: 'test',
},
});

const root = render({ store });

expect(root.find('.SearchContextCard-header'))
.toIncludeText('2 language packs found for "test"');
});

it('should render singular form when only one result is found with addonType theme', () => {
const { store } = dispatchSearchResults({
addons: { [fakeAddon.slug]: fakeAddon },
filters: {
addonType: 'theme',
query: 'test',
},
});

const root = render({ store });

expect(root.find('.SearchContextCard-header'))
.toIncludeText('1 result found for "test"');
});

it('should render plural form when multiple results are found with addonType theme', () => {
const { store } = dispatchSearchResults({
filters: {
addonType: 'theme',
query: 'test',
},
});

const root = render({ store });

expect(root.find('.SearchContextCard-header'))
.toIncludeText('2 results found for "test"');
});
});