-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathBulletChart.cy.tsx
More file actions
89 lines (80 loc) · 2.46 KB
/
BulletChart.cy.tsx
File metadata and controls
89 lines (80 loc) · 2.46 KB
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
import { complexDataSet } from '../../resources/DemoProps.js';
import { BulletChart } from './BulletChart.js';
import { cypressPassThroughTestsFactory, testChartLegendConfig, testChartZoomingTool } from '@/cypress/support/utils';
const dimensions = [
{
accessor: 'name',
interval: 0,
},
];
const measures = [
{
accessor: 'users',
label: 'Users',
formatter: (val: number) => val.toLocaleString('en'),
type: 'primary',
},
{
accessor: 'sessions',
label: 'Active Sessions',
formatter: (val) => `${val} sessions`,
hideDataLabel: true,
type: 'comparison',
},
{
accessor: 'volume',
label: 'Vol.',
type: 'additional',
},
];
describe('BulletChart', () => {
it('Basic', () => {
cy.mount(<BulletChart dataset={complexDataSet} dimensions={dimensions} measures={measures} />);
cy.get('.recharts-responsive-container').should('be.visible');
cy.get('.recharts-bar').should('have.length', 3);
cy.get('.recharts-bar-rectangles').should('have.length', 3);
});
it('click handlers', () => {
const onClick = cy.spy().as('onClick');
const onLegendClick = cy.spy().as('onLegendClick');
cy.mount(
<BulletChart
dataset={complexDataSet}
dimensions={dimensions}
measures={measures}
onClick={onClick}
onLegendClick={onLegendClick}
/>,
);
cy.findByText('January').click();
cy.get('@onClick').should('have.been.called');
cy.get('[name="January"]').eq(0).click();
cy.get('@onClick')
.should('have.been.calledTwice')
.and(
'have.been.calledWith',
Cypress.sinon.match({
detail: Cypress.sinon.match({
payload: complexDataSet[0],
}),
}),
);
cy.get('[class="recharts-legend-wrapper"]').findByText('Users').realClick();
cy.get('@onLegendClick').should(
'have.been.calledWith',
Cypress.sinon.match({
detail: Cypress.sinon.match({
dataKey: 'users',
}),
}),
);
});
it('Loading Placeholder', () => {
cy.mount(<BulletChart dataset={[]} dimensions={[]} measures={[]} />);
cy.get('.recharts-bar').should('not.exist');
cy.contains('Loading...').should('exist');
});
testChartZoomingTool(BulletChart, { dataset: complexDataSet, dimensions, measures });
testChartLegendConfig(BulletChart, { dataset: complexDataSet, dimensions, measures });
cypressPassThroughTestsFactory(BulletChart, { dimensions: [], measures: [] });
});