blob: 6385af952e735be49c8163988de99f4ca2e5b4b7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
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';
import { HTTP_STATUS_INTERNAL_SERVER_ERROR } from '~/lib/utils/http_status';
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 }) => {
mock.onGet(TEST_URL).replyOnce(200, response);
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 () => {
mock.onGet(TEST_URL).replyOnce(HTTP_STATUS_INTERNAL_SERVER_ERROR);
await expect(setCiStatusFavicon(TEST_URL)).rejects.toEqual(expect.any(Error));
expect(resetFavicon).toHaveBeenCalled();
});
});
});
|