2021-06-08 01:23:25 +05:30
|
|
|
import {
|
|
|
|
apiParams,
|
|
|
|
apiParamsWithSpecialValues,
|
|
|
|
filteredTokens,
|
|
|
|
filteredTokensWithSpecialValues,
|
|
|
|
locationSearch,
|
|
|
|
locationSearchWithSpecialValues,
|
|
|
|
urlParams,
|
|
|
|
urlParamsWithSpecialValues,
|
2022-03-02 08:16:31 +05:30
|
|
|
} from 'jest/issues/list/mock_data';
|
2021-10-27 15:23:28 +05:30
|
|
|
import {
|
|
|
|
defaultPageSizeParams,
|
|
|
|
DUE_DATE_VALUES,
|
|
|
|
largePageSizeParams,
|
|
|
|
RELATIVE_POSITION_ASC,
|
|
|
|
urlSortParams,
|
2022-03-02 08:16:31 +05:30
|
|
|
} from '~/issues/list/constants';
|
2021-06-08 01:23:25 +05:30
|
|
|
import {
|
2021-09-30 23:02:18 +05:30
|
|
|
convertToApiParams,
|
2021-06-08 01:23:25 +05:30
|
|
|
convertToSearchQuery,
|
2021-09-30 23:02:18 +05:30
|
|
|
convertToUrlParams,
|
2021-06-08 01:23:25 +05:30
|
|
|
getDueDateValue,
|
|
|
|
getFilterTokens,
|
2021-10-27 15:23:28 +05:30
|
|
|
getInitialPageParams,
|
2021-06-08 01:23:25 +05:30
|
|
|
getSortKey,
|
|
|
|
getSortOptions,
|
2022-03-02 08:16:31 +05:30
|
|
|
} from '~/issues/list/utils';
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
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-06-08 01:23:25 +05:30
|
|
|
describe('getSortKey', () => {
|
|
|
|
it.each(Object.keys(urlSortParams))('returns %s given the correct inputs', (sortKey) => {
|
2021-09-30 23:02:18 +05:30
|
|
|
const sort = urlSortParams[sortKey];
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(getSortKey(sort)).toBe(sortKey);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getSortOptions', () => {
|
|
|
|
describe.each`
|
|
|
|
hasIssueWeightsFeature | hasBlockedIssuesFeature | length | containsWeight | containsBlocking
|
2021-12-11 22:18:48 +05:30
|
|
|
${false} | ${false} | ${9} | ${false} | ${false}
|
|
|
|
${true} | ${false} | ${10} | ${true} | ${false}
|
|
|
|
${false} | ${true} | ${10} | ${false} | ${true}
|
|
|
|
${true} | ${true} | ${11} | ${true} | ${true}
|
2021-06-08 01:23:25 +05:30
|
|
|
`(
|
|
|
|
'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);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getFilterTokens', () => {
|
|
|
|
it('returns filtered tokens given "window.location.search"', () => {
|
|
|
|
expect(getFilterTokens(locationSearch)).toEqual(filteredTokens);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns filtered tokens given "window.location.search" with special values', () => {
|
|
|
|
expect(getFilterTokens(locationSearchWithSpecialValues)).toEqual(
|
|
|
|
filteredTokensWithSpecialValues,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
describe('convertToApiParams', () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
it('returns api params given filtered tokens', () => {
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(convertToApiParams(filteredTokens)).toEqual(apiParams);
|
2021-06-08 01:23:25 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('returns api params given filtered tokens with special values', () => {
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(convertToApiParams(filteredTokensWithSpecialValues)).toEqual(apiParamsWithSpecialValues);
|
2021-06-08 01:23:25 +05:30
|
|
|
});
|
2021-09-30 23:02:18 +05:30
|
|
|
});
|
2021-06-08 01:23:25 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
describe('convertToUrlParams', () => {
|
2021-06-08 01:23:25 +05:30
|
|
|
it('returns url params given filtered tokens', () => {
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(convertToUrlParams(filteredTokens)).toEqual(urlParams);
|
2021-06-08 01:23:25 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('returns url params given filtered tokens with special values', () => {
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(convertToUrlParams(filteredTokensWithSpecialValues)).toEqual(urlParamsWithSpecialValues);
|
2021-06-08 01:23:25 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('convertToSearchQuery', () => {
|
|
|
|
it('returns search string given filtered tokens', () => {
|
|
|
|
expect(convertToSearchQuery(filteredTokens)).toBe('find issues');
|
|
|
|
});
|
|
|
|
});
|