debian-mirror-gitlab/spec/frontend/pipelines/components/dag/drawing_utils_spec.js

58 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-06-23 00:09:42 +05:30
import { createSankey } from '~/pipelines/components/dag/drawing_utils';
2021-01-03 14:25:43 +05:30
import { parseData } from '~/pipelines/components/parsing_utils';
2020-10-24 23:57:45 +05:30
import { mockParsedGraphQLNodes } from './mock_data';
2020-06-23 00:09:42 +05:30
describe('DAG visualization drawing utilities', () => {
2020-10-24 23:57:45 +05:30
const parsed = parseData(mockParsedGraphQLNodes);
2020-06-23 00:09:42 +05:30
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();
});
});
});
});