summaryrefslogtreecommitdiff
path: root/spec/frontend/monitoring/components/create_dashboard_modal_spec.js
blob: 8202d423ff39160237301360c18be5ccffe2b817 (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 { GlModal } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import CreateDashboardModal from '~/monitoring/components/create_dashboard_modal.vue';

describe('Create dashboard modal', () => {
  let wrapper;

  const defaultProps = {
    modalId: 'id',
    projectPath: 'https://localhost/',
    addDashboardDocumentationPath: 'https://link/to/docs',
  };

  const findDocsButton = () => wrapper.find('[data-testid="create-dashboard-modal-docs-button"]');
  const findRepoButton = () => wrapper.find('[data-testid="create-dashboard-modal-repo-button"]');

  const createWrapper = (props = {}, options = {}) => {
    wrapper = shallowMount(CreateDashboardModal, {
      propsData: { ...defaultProps, ...props },
      stubs: {
        GlModal,
      },
      ...options,
    });
  };

  beforeEach(() => {
    createWrapper();
  });

  afterEach(() => {
    wrapper.destroy();
  });

  it('has button that links to the project url', () => {
    findRepoButton().trigger('click');

    return wrapper.vm.$nextTick().then(() => {
      expect(findRepoButton().exists()).toBe(true);
      expect(findRepoButton().attributes('href')).toBe(defaultProps.projectPath);
    });
  });

  it('has button that links to the docs', () => {
    expect(findDocsButton().exists()).toBe(true);
    expect(findDocsButton().attributes('href')).toBe(defaultProps.addDashboardDocumentationPath);
  });
});