Skip to content

Commit

Permalink
Update tests and added coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroledesma committed Sep 30, 2019
1 parent 67edf10 commit f5041b2
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 65 deletions.
74 changes: 64 additions & 10 deletions src/charts/WPieChart/__snapshots__/WPieChart.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,38 @@

exports[`Charts/WPieChart Should be ommit children components not allowed 1`] = `
<div class="WPieChart" style="position: relative; width: 600px;"><svg width="600" height="400" viewBox="0 0 600 400">
<g style="position: relative; transform: translate(50%, 50%);">
<foreignObject style="width: 300px; height: 300px; transform: translate(-150px, -150px);"></foreignObject>
<path id="0" d="M9.184850993605149e-15,-150A150,150,0,0,1,129.9038105676658,-75L95.26279441628824,-55A110,110,0,0,0,6.735557395310443e-15,-110Z" fill="#48c0b6" style="opacity: 1;"></path>
<path id="1" d="M129.9038105676658,-75A150,150,0,1,1,-129.90381056766577,75.00000000000006L-95.26279441628823,55.000000000000036A110,110,0,1,0,95.26279441628824,-55Z" fill="#9d6af5" style="opacity: 1;"></path>
<path id="2" d="M-129.90381056766577,75.00000000000006A150,150,0,0,1,-2.7554552980815446e-14,-150L-2.0206672185931328e-14,-110A110,110,0,0,0,-95.26279441628823,55.000000000000036Z" fill="#ffde69" style="opacity: 1;"></path>
<g class="pie-sectors">
<foreignObject style="width: 300px; height: 300px; transform: translate(150px, 50px);"></foreignObject>
<g class="pie-sector">
<path id="0" d="M 450,200
A 150,150,0,
0,0,
450,200
L 410,200
A 110,110,0,
0,1,
410,200 Z" fill="#48c0b6" style="opacity: 1;"></path>
</g>
<g class="pie-sector">
<path id="1" d="M 450,200
A 150,150,0,
0,0,
450,200
L 410,200
A 110,110,0,
0,1,
410,200 Z" fill="#9d6af5" style="opacity: 1;"></path>
</g>
<g class="pie-sector">
<path id="2" d="M 450,200
A 150,150,0,
0,0,
450,200
L 410,200
A 110,110,0,
0,1,
410,200 Z" fill="#ffde69" style="opacity: 1;"></path>
</g>
</g>
</svg>
<!---->
Expand All @@ -17,11 +44,38 @@ exports[`Charts/WPieChart Should be render correctly 1`] = `<div class="WPieChar

exports[`Charts/WPieChart Should be render correctly with WPie component and WTooltip 1`] = `
<div class="WPieChart" style="position: relative; width: 600px;"><svg width="600" height="400" viewBox="0 0 600 400">
<g style="position: relative; transform: translate(50%, 50%);">
<foreignObject style="width: 300px; height: 300px; transform: translate(-150px, -150px);"></foreignObject>
<path id="0" d="M9.184850993605149e-15,-150A150,150,0,0,1,129.9038105676658,-75L95.26279441628824,-55A110,110,0,0,0,6.735557395310443e-15,-110Z" fill="#48c0b6" style="opacity: 1;"></path>
<path id="1" d="M129.9038105676658,-75A150,150,0,1,1,-129.90381056766577,75.00000000000006L-95.26279441628823,55.000000000000036A110,110,0,1,0,95.26279441628824,-55Z" fill="#9d6af5" style="opacity: 1;"></path>
<path id="2" d="M-129.90381056766577,75.00000000000006A150,150,0,0,1,-2.7554552980815446e-14,-150L-2.0206672185931328e-14,-110A110,110,0,0,0,-95.26279441628823,55.000000000000036Z" fill="#ffde69" style="opacity: 1;"></path>
<g class="pie-sectors">
<foreignObject style="width: 300px; height: 300px; transform: translate(150px, 50px);"></foreignObject>
<g class="pie-sector">
<path id="0" d="M 450,200
A 150,150,0,
0,0,
450,200
L 410,200
A 110,110,0,
0,1,
410,200 Z" fill="#48c0b6" style="opacity: 1;"></path>
</g>
<g class="pie-sector">
<path id="1" d="M 450,200
A 150,150,0,
0,0,
450,200
L 410,200
A 110,110,0,
0,1,
410,200 Z" fill="#9d6af5" style="opacity: 1;"></path>
</g>
<g class="pie-sector">
<path id="2" d="M 450,200
A 150,150,0,
0,0,
450,200
L 410,200
A 110,110,0,
0,1,
410,200 Z" fill="#ffde69" style="opacity: 1;"></path>
</g>
</g>
</svg>
<!---->
Expand Down
74 changes: 19 additions & 55 deletions src/components/Pie/WPie.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,76 +61,40 @@ describe('Components/WPie', () => {
expect(wrapper.html()).toMatchSnapshot()
})

it('Should be render correctly with radius prop', () => {
const wrapperArray = mount(WPie, {
...defaultConfig,
propsData: {
...propsData,
radius: [0, 50],
},
})

expect(wrapperArray.vm.curRadius).toEqual([0, 50])

const wrapperNum = mount(WPie, {
...defaultConfig,
propsData: {
...propsData,
radius: 5,
},
})

expect(wrapperNum.vm.curRadius).toEqual([0, 100])
it('Should be render correctly with custom styles', () => {
const wrapper = mount(WPie, { ...defaultConfig, propsData: { ...propsData, styles: { backgroundColor: 'green' } } })
expect(wrapper.vm.stylesCmp).toEqual({ backgroundColor: 'green', position: 'relative', transform: 'translate(50%, 50%)' })
})

it('Should be render correctly with angles prop', () => {
const wrapperArray = mount(WPie, {
...defaultConfig,
propsData: {
...propsData,
angles: [0, Math.PI * 3],
},
})

expect(wrapperArray.vm.curAngles).toEqual([0, Math.PI * 3])

const wrapperNum = mount(WPie, {
...defaultConfig,
propsData: {
...propsData,
angles: 5,
},
})
it('Should be render correctly with custom radius', () => {
const wrapper = mount(WPie, { ...defaultConfig, propsData: { ...propsData, radius: [150, 180] } })
expect(wrapper.vm.curRadius).toEqual({ innerRadius: 150, outerRadius: 180 })
expect(wrapper.html()).toMatchSnapshot()

expect(wrapperNum.vm.curAngles).toEqual([0, 5])
const wrapperTwo = mount(WPie, { ...defaultConfig, propsData: { ...propsData, radius: null } })
expect(wrapperTwo.vm.curRadius).toEqual({ innerRadius: 0, outerRadius: 100 })
})

it('It emits the handleClick event', () => {
const wrapper = mount(WPie, {
...defaultConfig,
propsData: {
...propsData,
trigger: 'click',
},
})
const wrapper = mount(WPie, { ...defaultConfig, propsData: { ...propsData, trigger: 'click' } })
wrapper.findAll('path').at(0).trigger('click')
expect(wrapper.emitted('onClick')).toHaveLength(1)
})

it('It emits the handleMouseEnter event', () => {
it('It emits the handleMouseEnter event', () => {
const wrapper = mount(WPie, defaultConfig)
wrapper.findAll('path').at(0).trigger('mouseenter')
expect(wrapper.emitted('onMouseenter')).toHaveLength(1)
})

it('It emits the handleMouseEnter event', () => {
const wrapper = mount(WPie, {
...defaultConfig,
propsData: {
...propsData,
trigger: 'hover',
},
})
it('It emits the handleClick event', () => {
const wrapper = mount(WPie, { ...defaultConfig, propsData: { ...propsData, trigger: 'click' } })
wrapper.findAll('path').at(0).trigger('click')
expect(wrapper.emitted('onClick')).toHaveLength(1)
})

it('It emits the handleMouseleave event', () => {
const wrapper = mount(WPie, { ...defaultConfig, propsData: { ...propsData, trigger: 'hover' } })
wrapper.findAll('path').at(0).trigger('mouseleave')
expect(wrapper.emitted('onMouseleave')).toHaveLength(1)
})
Expand Down
76 changes: 76 additions & 0 deletions src/components/Pie/__snapshots__/WPie.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,79 @@ L 300,200 Z" fill="red" style="opacity: 1;"></path>
</g>
</g>
`;

exports[`Components/WPie Should be render correctly with custom radius 1`] = `
<g class="pie-sectors">
<foreignObject style="width: 360px; height: 360px; transform: translate(180px, 20px);"></foreignObject>
<g class="pie-sector">
<path id="0" d="M 480,200
A 180,180,0,
0,0,
467.1830816055703,133.29304965099047
L 439.31923467130855,144.41087470915872
A 150,150,0,
0,1,
450,200 Z" fill="red" style="opacity: 1;"></path>
</g>
<g class="pie-sector">
<path id="1" d="M 467.1830816055703,133.29304965099047
A 180,180,0,
0,0,
309.39203737870235,20.245195797505716
L 307.8266978155853,50.20432983125477
A 150,150,0,
0,1,
439.31923467130855,144.41087470915872 Z" fill="red" style="opacity: 1;"></path>
</g>
<g class="pie-sector">
<path id="2" d="M 309.39203737870235,20.245195797505716
A 180,180,0,
0,0,
183.0668772924099,63.15466827892271
L 202.55573107700826,85.96222356576894
A 150,150,0,
0,1,
307.8266978155853,50.20432983125477 Z" fill="red" style="opacity: 1;"></path>
</g>
<g class="pie-sector">
<path id="3" d="M 183.0668772924099,63.15466827892271
A 180,180,0,
0,0,
123.29805807296268,234.29903379417465
L 152.7483817274689,228.5825281618122
A 150,150,0,
0,1,
202.55573107700826,85.96222356576894 Z" fill="red" style="opacity: 1;"></path>
</g>
<g class="pie-sector">
<path id="4" d="M 123.29805807296268,234.29903379417465
A 180,180,0,
0,0,
189.42042586353426,342.028721686136
L 207.85035488627852,318.35726807178
A 150,150,0,
0,1,
152.7483817274689,228.5825281618122 Z" fill="red" style="opacity: 1;"></path>
</g>
<g class="pie-sector">
<path id="5" d="M 189.42042586353426,342.028721686136
A 180,180,0,
0,0,
343.803753683698,374.58874867303996
L 336.5031280697483,345.4906238942
A 150,150,0,
0,1,
207.85035488627852,318.35726807178 Z" fill="red" style="opacity: 1;"></path>
</g>
<g class="pie-sector">
<path id="6" d="M 343.803753683698,374.58874867303996
A 180,180,0,
0,0,
480,200.00000000000006
L 450,200.00000000000003
A 150,150,0,
0,1,
336.5031280697483,345.4906238942 Z" fill="red" style="opacity: 1;"></path>
</g>
</g>
`;

0 comments on commit f5041b2

Please sign in to comment.