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

dag_annotations_spec.js « dag « components « pipelines « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 212f8e19a6de19c7d103930f2c7745fcb6ced945 (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
import { GlButton } from '@gitlab/ui';
import { shallowMount, mount } from '@vue/test-utils';
import { nextTick } from 'vue';
import DagAnnotations from '~/pipelines/components/dag/dag_annotations.vue';
import { singleNote, multiNote } from './mock_data';

describe('The DAG annotations', () => {
  let wrapper;

  const getColorBlock = () => wrapper.find('[data-testid="dag-color-block"]');
  const getAllColorBlocks = () => wrapper.findAll('[data-testid="dag-color-block"]');
  const getTextBlock = () => wrapper.find('[data-testid="dag-note-text"]');
  const getAllTextBlocks = () => wrapper.findAll('[data-testid="dag-note-text"]');
  const getToggleButton = () => wrapper.find(GlButton);

  const createComponent = (propsData = {}, method = shallowMount) => {
    if (wrapper?.destroy) {
      wrapper.destroy();
    }

    wrapper = method(DagAnnotations, {
      propsData,
      data() {
        return {
          showList: true,
        };
      },
    });
  };

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

  describe('when there is one annotation', () => {
    const currentNote = singleNote['dag-link103'];

    beforeEach(() => {
      createComponent({ annotations: singleNote });
    });

    it('displays the color block', () => {
      expect(getColorBlock().exists()).toBe(true);
    });

    it('displays the text block', () => {
      expect(getTextBlock().exists()).toBe(true);
      expect(getTextBlock().text()).toBe(`${currentNote.source.name} → ${currentNote.target.name}`);
    });

    it('does not display the list toggle link', () => {
      expect(getToggleButton().exists()).toBe(false);
    });
  });

  describe('when there are multiple annoataions', () => {
    beforeEach(() => {
      createComponent({ annotations: multiNote });
    });

    it('displays a color block for each link', () => {
      expect(getAllColorBlocks().length).toBe(Object.keys(multiNote).length);
    });

    it('displays a text block for each link', () => {
      expect(getAllTextBlocks().length).toBe(Object.keys(multiNote).length);

      Object.values(multiNote).forEach((item, idx) => {
        expect(getAllTextBlocks().at(idx).text()).toBe(`${item.source.name} → ${item.target.name}`);
      });
    });

    it('displays the list toggle link', () => {
      expect(getToggleButton().exists()).toBe(true);
      expect(getToggleButton().text()).toBe('Hide list');
    });
  });

  describe('the list toggle', () => {
    beforeEach(() => {
      createComponent({ annotations: multiNote }, mount);
    });

    describe('clicking hide', () => {
      it('hides listed items and changes text to show', async () => {
        expect(getAllTextBlocks().length).toBe(Object.keys(multiNote).length);
        expect(getToggleButton().text()).toBe('Hide list');
        getToggleButton().trigger('click');
        await nextTick();
        expect(getAllTextBlocks().length).toBe(0);
        expect(getToggleButton().text()).toBe('Show list');
      });
    });

    describe('clicking show', () => {
      it('shows listed items and changes text to hide', async () => {
        getToggleButton().trigger('click');
        getToggleButton().trigger('click');

        await nextTick();
        expect(getAllTextBlocks().length).toBe(Object.keys(multiNote).length);
        expect(getToggleButton().text()).toBe('Hide list');
      });
    });
  });
});