debian-mirror-gitlab/spec/frontend/design_management/utils/cache_update_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

42 lines
1.7 KiB
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import { InMemoryCache } from '@apollo/client/core';
2020-05-24 23:13:21 +05:30
import {
updateStoreAfterDesignsDelete,
updateStoreAfterAddImageDiffNote,
updateStoreAfterUploadDesign,
2021-01-29 00:20:46 +05:30
updateStoreAfterRepositionImageDiffNote,
2020-05-24 23:13:21 +05:30
} from '~/design_management/utils/cache_update';
import {
designDeletionError,
ADD_IMAGE_DIFF_NOTE_ERROR,
UPDATE_IMAGE_DIFF_NOTE_ERROR,
} from '~/design_management/utils/error_messages';
2023-05-27 22:25:52 +05:30
import { createAlert } from '~/alert';
2021-03-11 19:13:27 +05:30
import design from '../mock_data/design';
2020-05-24 23:13:21 +05:30
2023-05-27 22:25:52 +05:30
jest.mock('~/alert');
2020-05-24 23:13:21 +05:30
describe('Design Management cache update', () => {
const mockErrors = ['code red!'];
let mockStore;
beforeEach(() => {
mockStore = new InMemoryCache();
});
describe('error handling', () => {
it.each`
2021-11-18 22:05:49 +05:30
fnName | subject | errorMessage | extraArgs
${'updateStoreAfterDesignsDelete'} | ${updateStoreAfterDesignsDelete} | ${designDeletionError()} | ${[[design]]}
${'updateStoreAfterAddImageDiffNote'} | ${updateStoreAfterAddImageDiffNote} | ${ADD_IMAGE_DIFF_NOTE_ERROR} | ${[]}
${'updateStoreAfterUploadDesign'} | ${updateStoreAfterUploadDesign} | ${mockErrors[0]} | ${[]}
${'updateStoreAfterUpdateImageDiffNote'} | ${updateStoreAfterRepositionImageDiffNote} | ${UPDATE_IMAGE_DIFF_NOTE_ERROR} | ${[]}
2020-05-24 23:13:21 +05:30
`('$fnName handles errors in response', ({ subject, extraArgs, errorMessage }) => {
2022-11-25 23:54:43 +05:30
expect(createAlert).not.toHaveBeenCalled();
2020-05-24 23:13:21 +05:30
expect(() => subject(mockStore, { errors: mockErrors }, {}, ...extraArgs)).toThrow();
2022-11-25 23:54:43 +05:30
expect(createAlert).toHaveBeenCalledTimes(1);
expect(createAlert).toHaveBeenCalledWith({ message: errorMessage });
2020-05-24 23:13:21 +05:30
});
});
});