2021-09-18 13:59:54 +03:00
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import { Mock } from 'ts-mockery';
|
|
|
|
import { Chart, ChartDataset } from 'chart.js';
|
2021-09-18 20:05:28 +03:00
|
|
|
import { DoughnutChartLegend } from '../../../src/visits/charts/DoughnutChartLegend';
|
2021-09-18 13:59:54 +03:00
|
|
|
|
2021-09-18 20:05:28 +03:00
|
|
|
describe('<DoughnutChartLegend />', () => {
|
2022-03-26 14:17:42 +03:00
|
|
|
const labels = ['foo', 'bar', 'baz', 'foo2', 'bar2'];
|
|
|
|
const colors = ['foo_color', 'bar_color', 'baz_color'];
|
2021-09-18 13:59:54 +03:00
|
|
|
const defaultColor = 'red';
|
2022-03-26 14:17:42 +03:00
|
|
|
const datasets = [Mock.of<ChartDataset>({ backgroundColor: colors })];
|
2021-09-18 13:59:54 +03:00
|
|
|
const chart = Mock.of<Chart>({
|
|
|
|
config: {
|
|
|
|
data: { labels, datasets },
|
|
|
|
options: { defaultColor } as any,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-09-20 23:00:34 +03:00
|
|
|
it('renders the expected amount of items with expected colors and labels', () => {
|
2021-09-18 20:05:28 +03:00
|
|
|
const wrapper = shallow(<DoughnutChartLegend chart={chart} />);
|
2021-09-18 13:59:54 +03:00
|
|
|
const items = wrapper.find('li');
|
|
|
|
|
|
|
|
expect.assertions(labels.length * 2 + 1);
|
|
|
|
expect(items).toHaveLength(labels.length);
|
|
|
|
labels.forEach((label, index) => {
|
|
|
|
const item = items.at(index);
|
|
|
|
|
2021-09-18 20:05:28 +03:00
|
|
|
expect(item.find('.doughnut-chart-legend__item-color').prop('style')).toEqual({
|
2021-09-18 13:59:54 +03:00
|
|
|
backgroundColor: colors[index] ?? defaultColor,
|
|
|
|
});
|
2021-09-18 20:05:28 +03:00
|
|
|
expect(item.find('.doughnut-chart-legend__item-text').text()).toEqual(label);
|
2021-09-18 13:59:54 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|