2021-03-08 18:12:59 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import { setFaviconOverlay, resetFavicon } from '~/lib/utils/favicon';
|
|
|
|
import { setCiStatusFavicon } from '~/lib/utils/favicon_ci';
|
2023-04-23 21:23:45 +05:30
|
|
|
import { HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_OK } from '~/lib/utils/http_status';
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
jest.mock('~/lib/utils/favicon');
|
|
|
|
|
|
|
|
const TEST_URL = '/test/pipelinable/1';
|
|
|
|
const TEST_FAVICON = '/favicon.test.ico';
|
|
|
|
|
|
|
|
describe('~/lib/utils/favicon_ci', () => {
|
|
|
|
let mock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
mock = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setCiStatusFavicon', () => {
|
|
|
|
it.each`
|
|
|
|
response | setFaviconOverlayCalls | resetFaviconCalls
|
|
|
|
${{}} | ${[]} | ${[[]]}
|
|
|
|
${{ favicon: TEST_FAVICON }} | ${[[TEST_FAVICON]]} | ${[]}
|
|
|
|
`(
|
|
|
|
'with response=$response',
|
|
|
|
async ({ response, setFaviconOverlayCalls, resetFaviconCalls }) => {
|
2023-04-23 21:23:45 +05:30
|
|
|
mock.onGet(TEST_URL).replyOnce(HTTP_STATUS_OK, response);
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
expect(setFaviconOverlay).not.toHaveBeenCalled();
|
|
|
|
expect(resetFavicon).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
await setCiStatusFavicon(TEST_URL);
|
|
|
|
|
|
|
|
expect(setFaviconOverlay.mock.calls).toEqual(setFaviconOverlayCalls);
|
|
|
|
expect(resetFavicon.mock.calls).toEqual(resetFaviconCalls);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
it('with error', async () => {
|
2023-04-23 21:23:45 +05:30
|
|
|
mock.onGet(TEST_URL).replyOnce(HTTP_STATUS_INTERNAL_SERVER_ERROR);
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
await expect(setCiStatusFavicon(TEST_URL)).rejects.toEqual(expect.any(Error));
|
|
|
|
expect(resetFavicon).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|