summaryrefslogtreecommitdiff
path: root/spec/frontend/design_management/router_spec.js
blob: b9edde559c81efa1622c8a41e1c5f9190cae5bcd (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { mount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
import VueRouter from 'vue-router';
import App from '~/design_management/components/app.vue';
import DesignDetail from '~/design_management/pages/design/index.vue';
import Designs from '~/design_management/pages/index.vue';
import createRouter from '~/design_management/router';
import { DESIGNS_ROUTE_NAME, DESIGN_ROUTE_NAME } from '~/design_management/router/constants';
import '~/commons/bootstrap';

function factory(routeArg) {
  Vue.use(VueRouter);

  window.gon = { sprite_icons: '' };

  const router = createRouter('/');
  if (routeArg !== undefined) {
    router.push(routeArg);
  }

  return mount(App, {
    router,
    provide: { issueIid: '1' },
    stubs: { Toolbar: true },
    mocks: {
      $apollo: {
        queries: {
          designCollection: { loading: true },
          design: { loading: true },
          permissions: { loading: true },
        },
        mutate: jest.fn(),
      },
    },
  });
}

describe('Design management router', () => {
  afterEach(() => {
    window.location.hash = '';
  });

  describe.each([['/'], [{ name: DESIGNS_ROUTE_NAME }]])('root route', (routeArg) => {
    it('pushes home component', () => {
      const wrapper = factory(routeArg);

      expect(wrapper.findComponent(Designs).exists()).toBe(true);
    });
  });

  describe.each([['/designs/1'], [{ name: DESIGN_ROUTE_NAME, params: { id: '1' } }]])(
    'designs detail route',
    (routeArg) => {
      it('pushes designs detail component', () => {
        const wrapper = factory(routeArg);

        return nextTick().then(() => {
          const detail = wrapper.findComponent(DesignDetail);
          expect(detail.exists()).toBe(true);
          expect(detail.props('id')).toEqual('1');
        });
      });
    },
  );
});