2021-05-07 12:10:27 +00:00
|
|
|
import {
|
|
|
|
apiParams,
|
|
|
|
apiParamsWithSpecialValues,
|
|
|
|
filteredTokens,
|
|
|
|
filteredTokensWithSpecialValues,
|
|
|
|
locationSearch,
|
|
|
|
locationSearchWithSpecialValues,
|
|
|
|
urlParams,
|
|
|
|
urlParamsWithSpecialValues,
|
|
|
|
} from 'jest/issues_list/mock_data';
|
2021-08-09 15:09:13 +00:00
|
|
|
import {
|
|
|
|
defaultPageSizeParams,
|
|
|
|
DUE_DATE_VALUES,
|
|
|
|
largePageSizeParams,
|
|
|
|
RELATIVE_POSITION_ASC,
|
|
|
|
urlSortParams,
|
|
|
|
} from '~/issues_list/constants';
|
2021-04-23 03:09:40 +00:00
|
|
|
import {
|
2021-06-21 12:07:45 +00:00
|
|
|
convertToApiParams,
|
2021-04-23 03:09:40 +00:00
|
|
|
convertToSearchQuery,
|
2021-06-21 12:07:45 +00:00
|
|
|
convertToUrlParams,
|
2021-05-17 21:10:42 +00:00
|
|
|
getDueDateValue,
|
2021-04-23 03:09:40 +00:00
|
|
|
getFilterTokens,
|
2021-08-09 15:09:13 +00:00
|
|
|
getInitialPageParams,
|
2021-04-23 03:09:40 +00:00
|
|
|
getSortKey,
|
2021-05-04 15:10:36 +00:00
|
|
|
getSortOptions,
|
2021-04-23 03:09:40 +00:00
|
|
|
} from '~/issues_list/utils';
|
|
|
|
|
2021-08-09 15:09:13 +00:00
|
|
|
describe('getInitialPageParams', () => {
|
|
|
|
it.each(Object.keys(urlSortParams))(
|
|
|
|
'returns the correct page params for sort key %s',
|
|
|
|
(sortKey) => {
|
|
|
|
const expectedPageParams =
|
|
|
|
sortKey === RELATIVE_POSITION_ASC ? largePageSizeParams : defaultPageSizeParams;
|
|
|
|
|
|
|
|
expect(getInitialPageParams(sortKey)).toBe(expectedPageParams);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-04-23 03:09:40 +00:00
|
|
|
describe('getSortKey', () => {
|
2021-05-13 00:10:23 +00:00
|
|
|
it.each(Object.keys(urlSortParams))('returns %s given the correct inputs', (sortKey) => {
|
2021-06-21 12:07:45 +00:00
|
|
|
const sort = urlSortParams[sortKey];
|
2021-05-13 00:10:23 +00:00
|
|
|
expect(getSortKey(sort)).toBe(sortKey);
|
2021-04-23 03:09:40 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-17 21:10:42 +00:00
|
|
|
describe('getDueDateValue', () => {
|
|
|
|
it.each(DUE_DATE_VALUES)('returns the argument when it is `%s`', (value) => {
|
|
|
|
expect(getDueDateValue(value)).toBe(value);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns undefined when the argument is invalid', () => {
|
|
|
|
expect(getDueDateValue('invalid value')).toBeUndefined();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-04 15:10:36 +00: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-23 03:09:40 +00:00
|
|
|
describe('getFilterTokens', () => {
|
|
|
|
it('returns filtered tokens given "window.location.search"', () => {
|
|
|
|
expect(getFilterTokens(locationSearch)).toEqual(filteredTokens);
|
|
|
|
});
|
2021-05-07 12:10:27 +00:00
|
|
|
|
|
|
|
it('returns filtered tokens given "window.location.search" with special values', () => {
|
|
|
|
expect(getFilterTokens(locationSearchWithSpecialValues)).toEqual(
|
|
|
|
filteredTokensWithSpecialValues,
|
|
|
|
);
|
|
|
|
});
|
2021-04-23 03:09:40 +00:00
|
|
|
});
|
|
|
|
|
2021-06-21 12:07:45 +00:00
|
|
|
describe('convertToApiParams', () => {
|
2021-04-23 03:09:40 +00:00
|
|
|
it('returns api params given filtered tokens', () => {
|
2021-06-21 12:07:45 +00:00
|
|
|
expect(convertToApiParams(filteredTokens)).toEqual(apiParams);
|
2021-04-23 03:09:40 +00:00
|
|
|
});
|
2021-05-07 12:10:27 +00:00
|
|
|
|
|
|
|
it('returns api params given filtered tokens with special values', () => {
|
2021-06-21 12:07:45 +00:00
|
|
|
expect(convertToApiParams(filteredTokensWithSpecialValues)).toEqual(apiParamsWithSpecialValues);
|
2021-05-07 12:10:27 +00:00
|
|
|
});
|
2021-06-21 12:07:45 +00:00
|
|
|
});
|
2021-04-23 03:09:40 +00:00
|
|
|
|
2021-06-21 12:07:45 +00:00
|
|
|
describe('convertToUrlParams', () => {
|
2021-04-23 03:09:40 +00:00
|
|
|
it('returns url params given filtered tokens', () => {
|
2021-06-21 12:07:45 +00:00
|
|
|
expect(convertToUrlParams(filteredTokens)).toEqual(urlParams);
|
2021-04-23 03:09:40 +00:00
|
|
|
});
|
2021-05-07 12:10:27 +00:00
|
|
|
|
|
|
|
it('returns url params given filtered tokens with special values', () => {
|
2021-06-21 12:07:45 +00:00
|
|
|
expect(convertToUrlParams(filteredTokensWithSpecialValues)).toEqual(urlParamsWithSpecialValues);
|
2021-05-07 12:10:27 +00:00
|
|
|
});
|
2021-04-23 03:09:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('convertToSearchQuery', () => {
|
|
|
|
it('returns search string given filtered tokens', () => {
|
|
|
|
expect(convertToSearchQuery(filteredTokens)).toBe('find issues');
|
|
|
|
});
|
|
|
|
});
|