-
Notifications
You must be signed in to change notification settings - Fork 4
/
XAxis.spec.js
83 lines (73 loc) 路 2.78 KB
/
XAxis.spec.js
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
import React from 'react';
import { render } from 'enzyme';
import { scaleLinear, scaleTime } from 'd3-scale';
import XAxis from './XAxis';
describe('<XAxis />', () => {
it('renders child tick elements correctly', () => {
const width = 900;
const height = 360;
const xScale = scaleLinear().range([0, width]).domain([0, 100]);
const axis = render(<XAxis {...{ xScale, width, height }} />);
const ticks = axis.find('.tick');
expect(ticks).toMatchSnapshot();
});
it('renders domain axis', () => {
const width = 900;
const height = 360;
const xScale = scaleLinear().range([0, width]).domain([0, 100]);
const axis = render(<XAxis {...{ xScale, width, height }} />);
const ticks = axis.find('.domain');
expect(ticks).toMatchSnapshot();
});
it('renders axisName', () => {
const width = 900;
const height = 360;
const xScale = scaleLinear().range([0, width]).domain([0, 100]);
const axis = render(<XAxis {...{ xScale, width, height }} axisName="axisName" />);
const ticks = axis.find('.axisName');
expect(ticks).toMatchSnapshot();
});
it('renders the svg group wrapper', () => {
const width = 900;
const height = 360;
const xScale = scaleLinear().range([0, width]).domain([0, 100]);
const axis = render(<XAxis {...{ xScale, width, height }} />);
expect(axis.find('g').prop('transform')).toBe(`translate(0,${height})`);
});
it('sets a hashed class name', () => {
const width = 900;
const height = 360;
const xScale = scaleLinear().range([0, width]).domain([0, 100]);
const axis = render(<XAxis {...{ xScale, width, height }} />);
expect(axis.find('g').prop('class')).toBeDefined();
});
it('renders linear scale correctly', () => {
const width = 900;
const height = 360;
const xScale = scaleLinear().range([0, width]).domain([0, 100]);
const axis = render(<XAxis {...{ xScale, width, height }} />);
const ticks = axis.find('.tick');
expect(ticks).toMatchSnapshot();
});
it('renders time scale correctly', () => {
const width = 900;
const height = 360;
const timeDomain = [new Date(2017, 0, 1), new Date(2017, 1, 1)];
const xScale = scaleTime().domain(timeDomain).range([0, width]);
const axis = render(<XAxis {...{ xScale, width, height }} />);
const ticks = axis.find('.tick');
expect(ticks).toMatchSnapshot();
});
it('handles different ticks input', () => {
const width = 900;
const height = 360;
const xScale = scaleLinear().range([0, width]).domain([0, 100]);
const tickAmount = 5;
const axis = render(<XAxis {...{ xScale, width, height, tickAmount }} />);
const ticks = axis.find('.tick');
expect(ticks).toMatchSnapshot();
});
it('handles tickArguments over ticks', () => {
// TODO: using tickArguments
});
});