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';
2022-11-25 23:54:43 +05:30
import { createAlert } from '~/flash';
2018-03-17 18:26:18 +05:30
import axios from '~/lib/utils/axios_utils';
2023-03-04 22:38:38 +05:30
import httpStatusCodes, { HTTP_STATUS_CREATED } 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';
2023-03-04 22:38:38 +05:30
const { 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 () => {
2023-03-04 22:38:38 +05:30
mockAxios.onPost(endpoint, { feature_name: highlightId }).replyOnce(HTTP_STATUS_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);
2022-11-25 23:54:43 +05:30
expect(createAlert).toHaveBeenCalledWith({
2021-09-30 23:02:18 +05:30
message:
'An error occurred while dismissing the feature highlight. Refresh the page and try dismissing again.',
});
2018-03-17 18:26:18 +05:30
});
});
});