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

     1  import React from 'react';
     2  import { shallow } from 'enzyme';
     3  import { Badge, UncontrolledAlert } from 'reactstrap';
     4  import EndpointLink from './EndpointLink';
     5  
     6  describe('EndpointLink', () => {
     7    it('renders a simple anchor if the endpoint has no query params', () => {
     8      const endpoint = 'http://100.104.208.71:15090/stats/prometheus';
     9      const globalURL = 'http://100.104.208.71:15090/stats/prometheus';
    10      const endpointLink = shallow(<EndpointLink endpoint={endpoint} globalUrl={globalURL} />);
    11      const anchor = endpointLink.find('a');
    12      expect(anchor.prop('href')).toEqual(globalURL);
    13      expect(anchor.children().text()).toEqual(endpoint);
    14      expect(endpointLink.find('br')).toHaveLength(0);
    15    });
    16  
    17    it('renders an anchor targeting endpoint but with query param labels if the endpoint has query params', () => {
    18      const endpoint = 'http://100.99.128.71:9115/probe?module=http_2xx&target=http://some-service';
    19      const globalURL = 'http://100.99.128.71:9115/probe?module=http_2xx&target=http://some-service';
    20      const endpointLink = shallow(<EndpointLink endpoint={endpoint} globalUrl={globalURL} />);
    21      const anchor = endpointLink.find('a');
    22      const badges = endpointLink.find(Badge);
    23      expect(anchor.prop('href')).toEqual(globalURL);
    24      expect(anchor.children().text()).toEqual('http://100.99.128.71:9115/probe');
    25      expect(endpointLink.find('br')).toHaveLength(1);
    26      expect(badges).toHaveLength(2);
    27      const moduleLabel = badges.filterWhere((badge) => badge.hasClass('module'));
    28      expect(moduleLabel.children().text()).toEqual('module="http_2xx"');
    29      const targetLabel = badges.filterWhere((badge) => badge.hasClass('target'));
    30      expect(targetLabel.children().text()).toEqual('target="http://some-service"');
    31    });
    32  
    33    it('renders an alert if url is invalid', () => {
    34      const endpointLink = shallow(<EndpointLink endpoint={'afdsacas'} globalUrl={'afdsacas'} />);
    35      const err = endpointLink.find(UncontrolledAlert);
    36      expect(err.render().text()).toContain('Error: Invalid URL');
    37    });
    38  });