debian-mirror-gitlab/spec/frontend/feature_highlight/feature_highlight_helper_spec.js

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

42 lines
1.3 KiB
JavaScript
Raw Normal View History

2021-03-11 19:13:27 +05:30
import MockAdapter from 'axios-mock-adapter';
import { dismiss } from '~/feature_highlight/feature_highlight_helper';
2021-09-30 23:02:18 +05:30
import createFlash from '~/flash';
2018-03-17 18:26:18 +05:30
import axios from '~/lib/utils/axios_utils';
2021-03-11 19:13:27 +05:30
import httpStatusCodes from '~/lib/utils/http_status';
2018-10-15 14:42:47 +05:30
2021-03-11 19:13:27 +05:30
jest.mock('~/flash');
2018-03-17 18:26:18 +05:30
2021-03-11 19:13:27 +05:30
describe('feature highlight helper', () => {
2018-03-17 18:26:18 +05:30
describe('dismiss', () => {
2021-03-11 19:13:27 +05:30
let mockAxios;
const endpoint = '/-/callouts/dismiss';
const highlightId = '123';
const { CREATED, INTERNAL_SERVER_ERROR } = httpStatusCodes;
2018-03-17 18:26:18 +05:30
beforeEach(() => {
2021-03-11 19:13:27 +05:30
mockAxios = new MockAdapter(axios);
2018-03-17 18:26:18 +05:30
});
2021-03-11 19:13:27 +05:30
afterEach(() => {
mockAxios.reset();
2018-03-17 18:26:18 +05:30
});
2021-03-11 19:13:27 +05:30
it('calls persistent dismissal endpoint with highlightId', async () => {
mockAxios.onPost(endpoint, { feature_name: highlightId }).replyOnce(CREATED);
2018-03-17 18:26:18 +05:30
2021-03-11 19:13:27 +05:30
await expect(dismiss(endpoint, highlightId)).resolves.toEqual(expect.anything());
2018-03-17 18:26:18 +05:30
});
2021-03-11 19:13:27 +05:30
it('triggers flash when dismiss request fails', async () => {
mockAxios.onPost(endpoint, { feature_name: highlightId }).replyOnce(INTERNAL_SERVER_ERROR);
await dismiss(endpoint, highlightId);
2021-09-30 23:02:18 +05:30
expect(createFlash).toHaveBeenCalledWith({
message:
'An error occurred while dismissing the feature highlight. Refresh the page and try dismissing again.',
});
2018-03-17 18:26:18 +05:30
});
});
});