2021-05-07 08:10:27 -04:00
|
|
|
import {
|
|
|
|
apiParams,
|
|
|
|
apiParamsWithSpecialValues,
|
|
|
|
filteredTokens,
|
|
|
|
filteredTokensWithSpecialValues,
|
|
|
|
locationSearch,
|
|
|
|
locationSearchWithSpecialValues,
|
|
|
|
urlParams,
|
|
|
|
urlParamsWithSpecialValues,
|
|
|
|
} from 'jest/issues_list/mock_data';
|
2021-05-12 20:10:23 -04:00
|
|
|
import { urlSortParams } from '~/issues_list/constants';
|
2021-04-22 23:09:40 -04:00
|
|
|
import {
|
|
|
|
convertToApiParams,
|
|
|
|
convertToSearchQuery,
|
|
|
|
convertToUrlParams,
|
|
|
|
getFilterTokens,
|
|
|
|
getSortKey,
|
2021-05-04 11:10:36 -04:00
|
|
|
getSortOptions,
|
2021-04-22 23:09:40 -04:00
|
|
|
} from '~/issues_list/utils';
|
|
|
|
|
|
|
|
describe('getSortKey', () => {
|
2021-05-12 20:10:23 -04:00
|
|
|
it.each(Object.keys(urlSortParams))('returns %s given the correct inputs', (sortKey) => {
|
|
|
|
const { sort } = urlSortParams[sortKey];
|
|
|
|
expect(getSortKey(sort)).toBe(sortKey);
|
2021-04-22 23:09:40 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-04 11:10:36 -04:00
|
|
|
describe('getSortOptions', () => {
|
|
|
|
describe.each`
|
|
|
|
hasIssueWeightsFeature | hasBlockedIssuesFeature | length | containsWeight | containsBlocking
|
|
|
|
${false} | ${false} | ${8} | ${false} | ${false}
|
|
|
|
${true} | ${false} | ${9} | ${true} | ${false}
|
|
|
|
${false} | ${true} | ${9} | ${false} | ${true}
|
|
|
|
${true} | ${true} | ${10} | ${true} | ${true}
|
|
|
|
`(
|
|
|
|
'when hasIssueWeightsFeature=$hasIssueWeightsFeature and hasBlockedIssuesFeature=$hasBlockedIssuesFeature',
|
|
|
|
({
|
|
|
|
hasIssueWeightsFeature,
|
|
|
|
hasBlockedIssuesFeature,
|
|
|
|
length,
|
|
|
|
containsWeight,
|
|
|
|
containsBlocking,
|
|
|
|
}) => {
|
|
|
|
const sortOptions = getSortOptions(hasIssueWeightsFeature, hasBlockedIssuesFeature);
|
|
|
|
|
|
|
|
it('returns the correct length of sort options', () => {
|
|
|
|
expect(sortOptions).toHaveLength(length);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`${containsWeight ? 'contains' : 'does not contain'} weight option`, () => {
|
|
|
|
expect(sortOptions.some((option) => option.title === 'Weight')).toBe(containsWeight);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`${containsBlocking ? 'contains' : 'does not contain'} blocking option`, () => {
|
|
|
|
expect(sortOptions.some((option) => option.title === 'Blocking')).toBe(containsBlocking);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-04-22 23:09:40 -04:00
|
|
|
describe('getFilterTokens', () => {
|
|
|
|
it('returns filtered tokens given "window.location.search"', () => {
|
|
|
|
expect(getFilterTokens(locationSearch)).toEqual(filteredTokens);
|
|
|
|
});
|
2021-05-07 08:10:27 -04:00
|
|
|
|
|
|
|
it('returns filtered tokens given "window.location.search" with special values', () => {
|
|
|
|
expect(getFilterTokens(locationSearchWithSpecialValues)).toEqual(
|
|
|
|
filteredTokensWithSpecialValues,
|
|
|
|
);
|
|
|
|
});
|
2021-04-22 23:09:40 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('convertToApiParams', () => {
|
|
|
|
it('returns api params given filtered tokens', () => {
|
2021-04-27 08:10:12 -04:00
|
|
|
expect(convertToApiParams(filteredTokens)).toEqual(apiParams);
|
2021-04-22 23:09:40 -04:00
|
|
|
});
|
2021-05-07 08:10:27 -04:00
|
|
|
|
|
|
|
it('returns api params given filtered tokens with special values', () => {
|
|
|
|
expect(convertToApiParams(filteredTokensWithSpecialValues)).toEqual(apiParamsWithSpecialValues);
|
|
|
|
});
|
2021-04-22 23:09:40 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('convertToUrlParams', () => {
|
|
|
|
it('returns url params given filtered tokens', () => {
|
2021-04-27 08:10:12 -04:00
|
|
|
expect(convertToUrlParams(filteredTokens)).toEqual(urlParams);
|
2021-04-22 23:09:40 -04:00
|
|
|
});
|
2021-05-07 08:10:27 -04:00
|
|
|
|
|
|
|
it('returns url params given filtered tokens with special values', () => {
|
|
|
|
expect(convertToUrlParams(filteredTokensWithSpecialValues)).toEqual(urlParamsWithSpecialValues);
|
|
|
|
});
|
2021-04-22 23:09:40 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('convertToSearchQuery', () => {
|
|
|
|
it('returns search string given filtered tokens', () => {
|
|
|
|
expect(convertToSearchQuery(filteredTokens)).toBe('find issues');
|
|
|
|
});
|
|
|
|
});
|