Welcome to mirror list, hosted at ThFree Co, Russian Federation.

fetch_spec.js « utils « markdown_drawer « components « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ff07b2cf838e21aaa76de29234f5236212b8138e (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
import MockAdapter from 'axios-mock-adapter';
import {
  getRenderedMarkdown,
  splitDocument,
} from '~/vue_shared/components/markdown_drawer/utils/fetch';
import axios from '~/lib/utils/axios_utils';
import {
  MOCK_HTML,
  MOCK_DRAWER_DATA,
  MOCK_DRAWER_DATA_ERROR,
  MOCK_TABLE_DATA_BEFORE,
  MOCK_HTML_DATA_AFTER,
} from '../mock_data';

describe('utils/fetch', () => {
  let mock;

  afterEach(() => {
    mock.restore();
  });

  describe.each`
    axiosMock                                  | type         | toExpect
    ${{ code: 200, res: { html: MOCK_HTML } }} | ${'success'} | ${MOCK_DRAWER_DATA}
    ${{ code: 500, res: null }}                | ${'error'}   | ${MOCK_DRAWER_DATA_ERROR}
  `('process markdown data', ({ axiosMock, type, toExpect }) => {
    describe(`if api fetch responds with ${type}`, () => {
      beforeEach(() => {
        mock = new MockAdapter(axios);
        mock.onGet().reply(axiosMock.code, axiosMock.res);
      });
      it(`should update drawer correctly`, async () => {
        expect(await getRenderedMarkdown('/any/path')).toStrictEqual(toExpect);
      });
    });
  });

  describe('splitDocument', () => {
    it(`should update tables correctly`, () => {
      expect(splitDocument(MOCK_TABLE_DATA_BEFORE)).toStrictEqual(MOCK_HTML_DATA_AFTER);
    });
  });
});