summaryrefslogtreecommitdiff
path: root/spec/frontend/repository/router_spec.js
blob: 6944b23558aa8e9dc3fa651d0e63644976924c8c (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
import IndexPage from '~/repository/pages/index.vue';
import TreePage from '~/repository/pages/tree.vue';
import createRouter from '~/repository/router';

describe('Repository router spec', () => {
  it.each`
    path                                     | branch              | component    | componentName
    ${'/'}                                   | ${'master'}         | ${IndexPage} | ${'IndexPage'}
    ${'/tree/master'}                        | ${'master'}         | ${TreePage}  | ${'TreePage'}
    ${'/-/tree/master'}                      | ${'master'}         | ${TreePage}  | ${'TreePage'}
    ${'/-/tree/master/app/assets'}           | ${'master'}         | ${TreePage}  | ${'TreePage'}
    ${'/-/tree/feature/test-%23/app/assets'} | ${'feature/test-#'} | ${TreePage}  | ${'TreePage'}
    ${'/-/tree/123/app/assets'}              | ${'master'}         | ${null}      | ${'null'}
  `('sets component as $componentName for path "$path"', ({ path, component, branch }) => {
    const router = createRouter('', branch);

    const componentsForRoute = router.getMatchedComponents(path);

    expect(componentsForRoute.length).toBe(component ? 1 : 0);

    if (component) {
      expect(componentsForRoute).toContain(component);
    }
  });
});