2021-02-22 17:27:13 +05:30
|
|
|
import Cookies from 'js-cookie';
|
|
|
|
import {
|
|
|
|
DIFF_FILE_BY_FILE_COOKIE_NAME,
|
|
|
|
DIFF_VIEW_FILE_BY_FILE,
|
|
|
|
DIFF_VIEW_ALL_FILES,
|
|
|
|
} from '~/diffs/constants';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { fileByFile } from '~/diffs/utils/preferences';
|
|
|
|
import { getParameterValues } from '~/lib/utils/url_utility';
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
jest.mock('~/lib/utils/url_utility');
|
|
|
|
|
|
|
|
describe('diffs preferences', () => {
|
|
|
|
describe('fileByFile', () => {
|
|
|
|
it.each`
|
|
|
|
result | preference | cookie | searchParam
|
|
|
|
${false} | ${false} | ${undefined} | ${undefined}
|
|
|
|
${true} | ${true} | ${undefined} | ${undefined}
|
|
|
|
${true} | ${false} | ${DIFF_VIEW_FILE_BY_FILE} | ${undefined}
|
|
|
|
${false} | ${true} | ${DIFF_VIEW_ALL_FILES} | ${undefined}
|
|
|
|
${true} | ${false} | ${undefined} | ${[DIFF_VIEW_FILE_BY_FILE]}
|
|
|
|
${false} | ${true} | ${undefined} | ${[DIFF_VIEW_ALL_FILES]}
|
|
|
|
${true} | ${false} | ${DIFF_VIEW_FILE_BY_FILE} | ${[DIFF_VIEW_FILE_BY_FILE]}
|
|
|
|
${true} | ${true} | ${DIFF_VIEW_ALL_FILES} | ${[DIFF_VIEW_FILE_BY_FILE]}
|
|
|
|
${false} | ${false} | ${DIFF_VIEW_ALL_FILES} | ${[DIFF_VIEW_ALL_FILES]}
|
|
|
|
${false} | ${true} | ${DIFF_VIEW_FILE_BY_FILE} | ${[DIFF_VIEW_ALL_FILES]}
|
|
|
|
`(
|
|
|
|
'should return $result when { preference: $preference, cookie: $cookie, search: $searchParam }',
|
|
|
|
({ result, preference, cookie, searchParam }) => {
|
|
|
|
if (cookie) {
|
|
|
|
Cookies.set(DIFF_FILE_BY_FILE_COOKIE_NAME, cookie);
|
|
|
|
}
|
|
|
|
|
|
|
|
getParameterValues.mockReturnValue(searchParam);
|
|
|
|
|
|
|
|
expect(fileByFile(preference)).toBe(result);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|