github.com/thanos-io/thanos@v0.32.5/pkg/ui/react-app/src/pages/graph/GraphTabContent.test.tsx (about)

     1  import * as React from 'react';
     2  import { shallow } from 'enzyme';
     3  import { UncontrolledAlert } from 'reactstrap';
     4  import { GraphTabContent } from './GraphTabContent';
     5  
     6  describe('GraphTabContent', () => {
     7    it('renders an alert if data result type is different than "matrix"', () => {
     8      const props: any = {
     9        data: { resultType: 'invalid', result: [{}] },
    10        stacked: false,
    11        queryParams: {
    12          startTime: 1572100210000,
    13          endTime: 1572100217898,
    14          resolution: 10,
    15        },
    16        color: 'danger',
    17        children: `Query result is of wrong type '`,
    18      };
    19      const graph = shallow(<GraphTabContent {...props} />);
    20      const alert = graph.find(UncontrolledAlert);
    21      expect(alert.prop('color')).toEqual(props.color);
    22      expect(alert.childAt(0).text()).toEqual(props.children);
    23    });
    24  
    25    it('renders an alert if data result empty', () => {
    26      const props: any = {
    27        data: {
    28          resultType: 'matrix',
    29          result: [],
    30        },
    31        color: 'secondary',
    32        children: 'Empty query result',
    33        stacked: false,
    34        queryParams: {
    35          startTime: 1572100210000,
    36          endTime: 1572100217898,
    37          resolution: 10,
    38        },
    39      };
    40      const graph = shallow(<GraphTabContent {...props} />);
    41      const alert = graph.find(UncontrolledAlert);
    42      expect(alert.prop('color')).toEqual(props.color);
    43      expect(alert.childAt(0).text()).toEqual(props.children);
    44    });
    45  });