2021-05-18 16:30:27 +02:00
|
|
|
import { render, screen } from '@testing-library/react';
|
2022-04-22 14:33:13 +01:00
|
|
|
import React from 'react';
|
|
|
|
|
|
2021-05-18 16:30:27 +02:00
|
|
|
import { FieldColorModeId } from '@grafana/data';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2021-05-18 16:30:27 +02:00
|
|
|
import { Legend } from './Legend';
|
|
|
|
|
import { NodeDatum } from './types';
|
|
|
|
|
|
|
|
|
|
describe('Legend', () => {
|
|
|
|
|
it('renders ok without nodes', () => {
|
|
|
|
|
render(<Legend nodes={[]} onSort={(sort) => {}} sortable={false} />);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('renders ok with color fields', () => {
|
2022-11-23 16:54:57 +00:00
|
|
|
const nodes = [
|
2021-05-18 16:30:27 +02:00
|
|
|
{
|
|
|
|
|
id: 'nodeId',
|
2022-11-23 16:54:57 +00:00
|
|
|
mainStat: { config: { displayName: 'stat1' } },
|
|
|
|
|
secondaryStat: { config: { displayName: 'stat2' } },
|
|
|
|
|
arcSections: [{ config: { displayName: 'error', color: { mode: FieldColorModeId.Fixed, fixedColor: 'red' } } }],
|
|
|
|
|
},
|
|
|
|
|
] as NodeDatum[];
|
2021-05-18 16:30:27 +02:00
|
|
|
render(<Legend nodes={nodes} onSort={(sort) => {}} sortable={false} />);
|
|
|
|
|
const items = screen.getAllByLabelText(/VizLegend series/);
|
|
|
|
|
expect(items.length).toBe(3);
|
|
|
|
|
|
|
|
|
|
const item = screen.getByLabelText(/VizLegend series error/);
|
|
|
|
|
expect((item.firstChild as HTMLDivElement).style.getPropertyValue('background')).toBe('rgb(242, 73, 92)');
|
|
|
|
|
});
|
|
|
|
|
});
|