|
| 1 | +import ChartComponent from "../Chart"; |
| 2 | + |
| 3 | +describe('Chart re-rendering', () => { |
| 4 | + |
| 5 | + it('required when chart data changes', () => { |
| 6 | + const chart = new ChartComponent({type: 'bar', data: {}}); |
| 7 | + const updateRequired = chart.shouldComponentUpdate({type: 'bar', data: {labels: ['a', 'b']}}); |
| 8 | + expect(updateRequired).toBeTruthy(); |
| 9 | + }); |
| 10 | + |
| 11 | + it('required when chart legend changes', () => { |
| 12 | + const chart = new ChartComponent({type: 'bar', legend: {display: false}}); |
| 13 | + const updateRequired = chart.shouldComponentUpdate({type: 'bar', legend: {display: true}}); |
| 14 | + expect(updateRequired).toBeTruthy(); |
| 15 | + }); |
| 16 | + |
| 17 | + it('required when chart options change', () => { |
| 18 | + const chart = new ChartComponent({type: 'bar', options: {hover: {mode: 'single'}}}); |
| 19 | + const updateRequired = chart.shouldComponentUpdate({type: 'bar', options: {hover: {mode: 'label'}}}); |
| 20 | + expect(updateRequired).toBeTruthy(); |
| 21 | + }); |
| 22 | + |
| 23 | + it('not required when width changes', () => { |
| 24 | + const chart = new ChartComponent({type: 'bar', width: 100}); |
| 25 | + const updateRequired = chart.shouldComponentUpdate({type: 'bar', width: 200}); |
| 26 | + expect(updateRequired).toBeFalsy(); |
| 27 | + }); |
| 28 | + |
| 29 | + it('not required when height changes', () => { |
| 30 | + const chart = new ChartComponent({type: 'bar', height: 100}); |
| 31 | + const updateRequired = chart.shouldComponentUpdate({type: 'bar', height: 200}); |
| 32 | + expect(updateRequired).toBeFalsy(); |
| 33 | + }); |
| 34 | + |
| 35 | + it('not required when data do not change and onElementsClick installed', () => { |
| 36 | + const chart = new ChartComponent({ |
| 37 | + type: 'bar', data: {}, onElementsClick: () => { |
| 38 | + } |
| 39 | + }); |
| 40 | + const updateRequired = chart.shouldComponentUpdate({ |
| 41 | + type: 'bar', data: {}, onElementsClick: () => { |
| 42 | + } |
| 43 | + }); |
| 44 | + expect(updateRequired).toBeFalsy(); |
| 45 | + }); |
| 46 | +}); |
0 commit comments