summaryrefslogtreecommitdiff
path: root/spec/frontend/pipelines/components/dag/drawing_utils_spec.js
blob: a50163411ed4f858f994832568bf7378a406a7ba (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
import { createSankey } from '~/pipelines/components/dag/drawing_utils';
import { parseData } from '~/pipelines/components/dag/parsing_utils';
import { mockBaseData } from './mock_data';

describe('DAG visualization drawing utilities', () => {
  const parsed = parseData(mockBaseData.stages);

  const layoutSettings = {
    width: 200,
    height: 200,
    nodeWidth: 10,
    nodePadding: 20,
    paddingForLabels: 100,
  };

  const sankeyLayout = createSankey(layoutSettings)(parsed);

  describe('createSankey', () => {
    it('returns a nodes data structure with expected d3-added properties', () => {
      const exampleNode = sankeyLayout.nodes[0];
      expect(exampleNode).toHaveProperty('sourceLinks');
      expect(exampleNode).toHaveProperty('targetLinks');
      expect(exampleNode).toHaveProperty('depth');
      expect(exampleNode).toHaveProperty('layer');
      expect(exampleNode).toHaveProperty('x0');
      expect(exampleNode).toHaveProperty('x1');
      expect(exampleNode).toHaveProperty('y0');
      expect(exampleNode).toHaveProperty('y1');
    });

    it('returns a links data structure with expected d3-added properties', () => {
      const exampleLink = sankeyLayout.links[0];
      expect(exampleLink).toHaveProperty('source');
      expect(exampleLink).toHaveProperty('target');
      expect(exampleLink).toHaveProperty('width');
      expect(exampleLink).toHaveProperty('y0');
      expect(exampleLink).toHaveProperty('y1');
    });

    describe('data structure integrity', () => {
      const newObject = { name: 'bad-actor' };

      beforeEach(() => {
        sankeyLayout.nodes.unshift(newObject);
      });

      it('sankey does not propagate changes back to the original', () => {
        expect(sankeyLayout.nodes[0]).toBe(newObject);
        expect(parsed.nodes[0]).not.toBe(newObject);
      });

      afterEach(() => {
        sankeyLayout.nodes.shift();
      });
    });
  });
});