-
Notifications
You must be signed in to change notification settings - Fork 715
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix rect color edge case in LegendThreshold * Add tests, fix LegendThreshold default scale for negitive domain * Add test for 0 case and fix LegendThreshold
- Loading branch information
1 parent
86a851c
commit 0762cf3
Showing
2 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,80 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import { scaleThreshold } from '@visx/scale'; | ||
import { LegendThreshold } from '../src'; | ||
|
||
describe('<LegendThreshold />', () => { | ||
test('it should be defined', () => { | ||
expect(LegendThreshold).toBeDefined(); | ||
}); | ||
|
||
it('should render LegendShape with the correct color', () => { | ||
const domain = [1, 2, 9]; | ||
const range = ['green', 'purple', 'blue', 'pink']; | ||
const thresholdScale = scaleThreshold({ | ||
domain, | ||
range, | ||
}); | ||
|
||
const { getAllByTestId } = render( | ||
<svg> | ||
<LegendThreshold scale={thresholdScale} data-testid="thresholdLegend" /> | ||
</svg>, | ||
); | ||
|
||
const thresholdLegend = getAllByTestId('thresholdLegend'); | ||
|
||
range.forEach((color, index) => { | ||
const legendItem = thresholdLegend[index]; | ||
const legendShape = legendItem?.querySelector('.visx-legend-shape'); | ||
expect(legendShape?.querySelector('div')).toHaveStyle(`background: ${color}`); | ||
}); | ||
}); | ||
|
||
it('should render LegendShape with the correct color with a negitive domain', () => { | ||
const domain = [-3, -1]; | ||
const range = ['green', 'purple', 'blue']; | ||
const thresholdScale1 = scaleThreshold({ | ||
domain, | ||
range, | ||
}); | ||
|
||
const { getAllByTestId } = render( | ||
<svg> | ||
<LegendThreshold scale={thresholdScale1} data-testid="thresholdLegend" /> | ||
</svg>, | ||
); | ||
|
||
const thresholdLegend = getAllByTestId('thresholdLegend'); | ||
|
||
range.forEach((color, index) => { | ||
const legendItem = thresholdLegend[index]; | ||
const legendShape = legendItem?.querySelector('.visx-legend-shape'); | ||
expect(legendShape?.querySelector('div')).toHaveStyle(`background: ${color}`); | ||
}); | ||
}); | ||
|
||
it('should render LegendShape with the correct color with 0', () => { | ||
const domain = [0, 1, 4]; | ||
const range = ['green', 'purple', 'blue', 'pink']; | ||
const thresholdScale1 = scaleThreshold({ | ||
domain, | ||
range, | ||
}); | ||
|
||
const { getAllByTestId } = render( | ||
<svg> | ||
<LegendThreshold scale={thresholdScale1} data-testid="thresholdLegend" /> | ||
</svg>, | ||
); | ||
|
||
const thresholdLegend = getAllByTestId('thresholdLegend'); | ||
|
||
range.forEach((color, index) => { | ||
const legendItem = thresholdLegend[index]; | ||
const legendShape = legendItem?.querySelector('.visx-legend-shape'); | ||
expect(legendShape?.querySelector('div')).toHaveStyle(`background: ${color}`); | ||
}); | ||
}); | ||
}); |