debian-mirror-gitlab/spec/frontend/feature_highlight/feature_highlight_helper_spec.js
2023-03-04 22:38:38 +05:30

41 lines
1.3 KiB
JavaScript

import MockAdapter from 'axios-mock-adapter';
import { dismiss } from '~/feature_highlight/feature_highlight_helper';
import { createAlert } from '~/flash';
import axios from '~/lib/utils/axios_utils';
import httpStatusCodes, { HTTP_STATUS_CREATED } from '~/lib/utils/http_status';
jest.mock('~/flash');
describe('feature highlight helper', () => {
describe('dismiss', () => {
let mockAxios;
const endpoint = '/-/callouts/dismiss';
const highlightId = '123';
const { INTERNAL_SERVER_ERROR } = httpStatusCodes;
beforeEach(() => {
mockAxios = new MockAdapter(axios);
});
afterEach(() => {
mockAxios.reset();
});
it('calls persistent dismissal endpoint with highlightId', async () => {
mockAxios.onPost(endpoint, { feature_name: highlightId }).replyOnce(HTTP_STATUS_CREATED);
await expect(dismiss(endpoint, highlightId)).resolves.toEqual(expect.anything());
});
it('triggers flash when dismiss request fails', async () => {
mockAxios.onPost(endpoint, { feature_name: highlightId }).replyOnce(INTERNAL_SERVER_ERROR);
await dismiss(endpoint, highlightId);
expect(createAlert).toHaveBeenCalledWith({
message:
'An error occurred while dismissing the feature highlight. Refresh the page and try dismissing again.',
});
});
});
});