Skip to content

Commit 2cbda76

Browse files
committedJan 12, 2022
feat(heatmap): add tests for forceSquare
1 parent 236e94c commit 2cbda76

File tree

1 file changed

+51
-18
lines changed

1 file changed

+51
-18
lines changed
 

‎packages/heatmap/tests/HeatMap.test.tsx

+51-18
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ afterAll(() => {
5959
Globals.assign({ skipAnimation: false })
6060
})
6161

62-
it('should render a basic heamap chart', () => {
62+
it('should render a basic heatmap chart', () => {
6363
const wrapper = mount(<HeatMap {...baseProps} />)
6464

6565
dataPoints.forEach(datum => {
@@ -72,26 +72,59 @@ it('should render a basic heamap chart', () => {
7272
})
7373
})
7474

75+
describe('force square cells', () => {
76+
const expectedSquareSize = 100
77+
78+
CELL_SHAPES.forEach(shape => {
79+
describe(shape, () => {
80+
it('cells should have square dimensions', () => {
81+
const wrapper = mount(
82+
<HeatMap {...baseProps} cellComponent={shape} width={2000} forceSquare />
83+
)
84+
85+
dataPoints.forEach(datum => {
86+
const cell = wrapper.find(`g[data-testid='cell.${datum.id}']`)
87+
const cellShape = cell.find(shape).parent()
88+
89+
if (shape === 'rect') {
90+
expect(cellShape.prop<SpringValue<number>>('width').get()).toEqual(
91+
expectedSquareSize
92+
)
93+
expect(cellShape.prop<SpringValue<number>>('height').get()).toEqual(
94+
expectedSquareSize
95+
)
96+
} else {
97+
expect(cellShape.prop<SpringValue<number>>('r').get() * 2).toEqual(
98+
expectedSquareSize
99+
)
100+
}
101+
})
102+
})
103+
})
104+
})
105+
})
106+
75107
describe('size variation', () => {
108+
// use simpler data for easier assertions
109+
const sizeVariationData = [
110+
{
111+
id: 'A',
112+
data: [
113+
{ x: 'X', y: 5 },
114+
{ x: 'Y', y: 10 },
115+
],
116+
},
117+
{
118+
id: 'B',
119+
data: [
120+
{ x: 'X', y: 7.5 },
121+
{ x: 'Y', y: 10 },
122+
],
123+
},
124+
]
125+
76126
CELL_SHAPES.forEach(shape => {
77127
describe(shape, () => {
78-
// use simpler data for easier assertions
79-
const sizeVariationData = [
80-
{
81-
id: 'A',
82-
data: [
83-
{ x: 'X', y: 5 },
84-
{ x: 'Y', y: 10 },
85-
],
86-
},
87-
{
88-
id: 'B',
89-
data: [
90-
{ x: 'X', y: 7.5 },
91-
{ x: 'Y', y: 10 },
92-
],
93-
},
94-
]
95128
const cellIdAndValues: { id: string; value: number }[] = []
96129
sizeVariationData.forEach(serie => {
97130
serie.data.forEach(datum => {

0 commit comments

Comments
 (0)
Please sign in to comment.