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

links_layer_spec.js « graph_shared « pipelines « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5e5365eef3062b6389835d69eaefb24c2b6422e4 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import { GlAlert } from '@gitlab/ui';
import { fireEvent, within } from '@testing-library/dom';
import { mount, shallowMount } from '@vue/test-utils';
import LinksInner from '~/pipelines/components/graph_shared/links_inner.vue';
import LinksLayer from '~/pipelines/components/graph_shared/links_layer.vue';
import { generateResponse, mockPipelineResponse } from '../graph/mock_data';

describe('links layer component', () => {
  let wrapper;

  const withinComponent = () => within(wrapper.element);
  const findAlert = () => wrapper.find(GlAlert);
  const findShowAnyways = () =>
    withinComponent().getByText(wrapper.vm.$options.i18n.showLinksAnyways);
  const findLinksInner = () => wrapper.find(LinksInner);

  const pipeline = generateResponse(mockPipelineResponse, 'root/fungi-xoxo');
  const containerId = `pipeline-links-container-${pipeline.id}`;
  const slotContent = "<div>Ceci n'est pas un graphique</div>";

  const tooManyStages = Array(101)
    .fill(0)
    .flatMap(() => pipeline.stages);

  const defaultProps = {
    containerId,
    containerMeasurements: { width: 400, height: 400 },
    pipelineId: pipeline.id,
    pipelineData: pipeline.stages,
  };

  const createComponent = ({ mountFn = shallowMount, props = {} } = {}) => {
    wrapper = mountFn(LinksLayer, {
      propsData: {
        ...defaultProps,
        ...props,
      },
      slots: {
        default: slotContent,
      },
      stubs: {
        'links-inner': true,
      },
    });
  };

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

  describe('with data under max stages', () => {
    beforeEach(() => {
      createComponent();
    });

    it('renders the default slot', () => {
      expect(wrapper.html()).toContain(slotContent);
    });

    it('renders the inner links component', () => {
      expect(findLinksInner().exists()).toBe(true);
    });
  });

  describe('with more than the max number of stages', () => {
    describe('rendering', () => {
      beforeEach(() => {
        createComponent({ props: { pipelineData: tooManyStages } });
      });

      it('renders the default slot', () => {
        expect(wrapper.html()).toContain(slotContent);
      });

      it('renders the alert component', () => {
        expect(findAlert().exists()).toBe(true);
      });

      it('does not render the inner links component', () => {
        expect(findLinksInner().exists()).toBe(false);
      });
    });

    describe('with width or height measurement at 0', () => {
      beforeEach(() => {
        createComponent({ props: { containerMeasurements: { width: 0, height: 100 } } });
      });

      it('renders the default slot', () => {
        expect(wrapper.html()).toContain(slotContent);
      });

      it('does not render the alert component', () => {
        expect(findAlert().exists()).toBe(false);
      });

      it('does not render the inner links component', () => {
        expect(findLinksInner().exists()).toBe(false);
      });
    });

    describe('interactions', () => {
      beforeEach(() => {
        createComponent({ mountFn: mount, props: { pipelineData: tooManyStages } });
      });

      it('renders the disable button', () => {
        expect(findShowAnyways()).not.toBe(null);
      });

      it('shows links when override is clicked', async () => {
        expect(findLinksInner().exists()).toBe(false);
        fireEvent(findShowAnyways(), new MouseEvent('click', { bubbles: true }));
        await wrapper.vm.$nextTick();
        expect(findLinksInner().exists()).toBe(true);
      });
    });
  });
});