Skip to content

Commit

Permalink
tests(waffle): add test for Waffle legends
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Benitte committed Aug 26, 2018
1 parent 38fe789 commit 87e3d9e
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions packages/waffle/tests/Waffle.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react'
import renderer from 'react-test-renderer'
import { mount } from 'enzyme'
import { LegendSvg, LegendSvgItem } from '@nivo/legends'
import Waffle from '../src/Waffle'

it('should render a basic waffle chart in SVG', () => {
Expand Down Expand Up @@ -37,3 +39,53 @@ for (const fillMode of fillModes) {
expect(tree).toMatchSnapshot()
})
}

describe('legends', () => {
it('should support legends', () => {
const data = [
{ id: 'one', label: 'one', value: 10 },
{ id: 'two', label: 'two', value: 20 },
{ id: 'tree', label: 'tree', value: 30 },
]
const legends = [
{
anchor: 'top-left',
direction: 'column',
itemWidth: 100,
itemHeight: 20,
},
]
const wrapper = mount(
<Waffle
width={400}
height={400}
rows={10}
columns={10}
total={100}
colors={['red', 'green', 'blue']}
data={data}
legends={legends}
/>
)

expect(wrapper.find(LegendSvg)).toHaveLength(1)

const legendItems = wrapper.find(LegendSvgItem)
expect(legendItems).toHaveLength(3)
expect(legendItems.at(0).prop('data')).toEqual({
id: 'one',
label: 'one',
color: 'red',
})
expect(legendItems.at(1).prop('data')).toEqual({
id: 'two',
label: 'two',
color: 'green',
})
expect(legendItems.at(2).prop('data')).toEqual({
id: 'tree',
label: 'tree',
color: 'blue',
})
})
})

0 comments on commit 87e3d9e

Please sign in to comment.