summaryrefslogtreecommitdiff
path: root/spec/frontend/ide/ide_router_extension_spec.js
blob: 3e29ecc4a900e11e1f7b6b4393b772fc195727d9 (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
import VueRouter from 'vue-router';
import IdeRouter from '~/ide/ide_router_extension';

jest.mock('vue-router');

describe('IDE overrides of VueRouter', () => {
  const paths = branch => [
    `${branch}`,
    `/${branch}`,
    `/${branch}/-/`,
    `/edit/${branch}`,
    `/edit/${branch}/-/`,
    `/blob/${branch}`,
    `/blob/${branch}/-/`,
    `/blob/${branch}/-/src/merge_requests/2`,
    `/blob/${branch}/-/src/blob/`,
    `/tree/${branch}/-/src/blob/`,
    `/tree/${branch}/-/src/tree/`,
  ];
  let router;

  beforeEach(() => {
    VueRouter.mockClear();
    router = new IdeRouter({
      mode: 'history',
    });
  });

  it.each`
    path               | expected
    ${'#-test'}        | ${'%23-test'}
    ${'#test'}         | ${'%23test'}
    ${'test#'}         | ${'test%23'}
    ${'test-#'}        | ${'test-%23'}
    ${'test-#-hash'}   | ${'test-%23-hash'}
    ${'test/hash#123'} | ${'test/hash%23123'}
  `('finds project path when route is $path', ({ path, expected }) => {
    paths(path).forEach(route => {
      const expectedPath = route.replace(path, expected);

      router.push(route);
      expect(VueRouter.prototype.push).toHaveBeenCalledWith(expectedPath, undefined, undefined);

      router.resolve(route);
      expect(VueRouter.prototype.resolve).toHaveBeenCalledWith(expectedPath, undefined, undefined);
    });
  });
});