github.com/thanos-io/thanos@v0.32.5/pkg/ui/react-app/src/pages/targets/TargetLabels.test.tsx (about) 1 import * as React from 'react'; 2 import { shallow } from 'enzyme'; 3 import TargetLabels from './TargetLabels'; 4 import { Tooltip, Badge } from 'reactstrap'; 5 import toJson from 'enzyme-to-json'; 6 7 describe('targetLabels', () => { 8 const defaultProps = { 9 discoveredLabels: { 10 __address__: 'localhost:9100', 11 __metrics_path__: '/metrics', 12 __scheme__: 'http', 13 job: 'node_exporter', 14 }, 15 labels: { 16 instance: 'localhost:9100', 17 job: 'node_exporter', 18 foo: 'bar', 19 }, 20 idx: 1, 21 scrapePool: 'cortex/node-exporter_group/0', 22 }; 23 const targetLabels = shallow(<TargetLabels {...defaultProps} />); 24 25 it('renders a div of series labels', () => { 26 const div = targetLabels.find('div').filterWhere((elem) => elem.hasClass('series-labels-container')); 27 expect(div).toHaveLength(1); 28 expect(div.prop('id')).toEqual('series-labels-cortex/node-exporter_group/0-1'); 29 }); 30 31 it('wraps each label in a label badge', () => { 32 const l: { [key: string]: string } = defaultProps.labels; 33 Object.keys(l).forEach((labelName: string): void => { 34 const badge = targetLabels 35 .find(Badge) 36 .filterWhere((badge) => badge.children().text() === `${labelName}="${l[labelName]}"`); 37 expect(badge).toHaveLength(1); 38 }); 39 expect(targetLabels.find(Badge)).toHaveLength(3); 40 }); 41 42 it('renders a tooltip for discovered labels', () => { 43 const tooltip = targetLabels.find(Tooltip); 44 expect(tooltip).toHaveLength(1); 45 expect(tooltip.prop('isOpen')).toBe(false); 46 expect(tooltip.prop('target')).toEqual('series-labels-cortex\\/node-exporter_group\\/0-1'); 47 }); 48 49 it('renders discovered labels', () => { 50 expect(toJson(targetLabels)).toMatchSnapshot(); 51 }); 52 });