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.

43 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';
2023-05-27 22:25:52 +05:30
import { createAlert } from '~/alert';
2018-03-17 18:26:18 +05:30
import axios from '~/lib/utils/axios_utils';
2023-03-17 16:20:25 +05:30
import { HTTP_STATUS_CREATED, HTTP_STATUS_INTERNAL_SERVER_ERROR } from '~/lib/utils/http_status';
2018-10-15 14:42:47 +05:30
2023-05-27 22:25:52 +05:30
jest.mock('~/alert');
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';
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
});
2023-05-27 22:25:52 +05:30
it('triggers an alert when dismiss request fails', async () => {
2023-03-17 16:20:25 +05:30
mockAxios
.onPost(endpoint, { feature_name: highlightId })
.replyOnce(HTTP_STATUS_INTERNAL_SERVER_ERROR);
2021-03-11 19:13:27 +05:30
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
});
});
});