Legend.test.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import { render, screen } from '@testing-library/react';
  2. import React from 'react';
  3. import { FieldColorModeId } from '@grafana/data';
  4. import { Legend } from './Legend';
  5. import { NodeDatum } from './types';
  6. describe('Legend', () => {
  7. it('renders ok without nodes', () => {
  8. render(<Legend nodes={[]} onSort={(sort) => {}} sortable={false} />);
  9. });
  10. it('renders ok with color fields', () => {
  11. const nodes: NodeDatum[] = [
  12. {
  13. id: 'nodeId',
  14. mainStat: { config: { displayName: 'stat1' } } as any,
  15. secondaryStat: { config: { displayName: 'stat2' } } as any,
  16. arcSections: [
  17. { config: { displayName: 'error', color: { mode: FieldColorModeId.Fixed, fixedColor: 'red' } } } as any,
  18. ],
  19. } as any,
  20. ];
  21. render(<Legend nodes={nodes} onSort={(sort) => {}} sortable={false} />);
  22. const items = screen.getAllByLabelText(/VizLegend series/);
  23. expect(items.length).toBe(3);
  24. const item = screen.getByLabelText(/VizLegend series error/);
  25. expect((item.firstChild as HTMLDivElement).style.getPropertyValue('background')).toBe('rgb(242, 73, 92)');
  26. });
  27. });