1
import * as React from 'react';
2
import { mount, ReactWrapper } from 'enzyme';
3
import MetricsExplorer from './MetricsExplorer';
4
import { Input } from 'reactstrap';
6
describe('MetricsExplorer', () => {
7
const spyInsertAtCursor = jest.fn().mockImplementation((value: string) => {
10
const metricsExplorerProps = {
12
updateShow: (show: boolean): void => {
15
metrics: ['go_test_1', 'prometheus_test_1'],
16
insertAtCursor: spyInsertAtCursor,
19
let metricsExplorer: ReactWrapper;
21
metricsExplorer = mount(<MetricsExplorer {...metricsExplorerProps} />);
24
it('renders an Input[type=text]', () => {
25
const input = metricsExplorer.find(Input);
26
expect(input.prop('type')).toEqual('text');
29
it('lists all metrics in props', () => {
30
const metrics = metricsExplorer.find('.metric');
31
expect(metrics).toHaveLength(metricsExplorerProps.metrics.length);
34
it('filters metrics with search', () => {
35
const input = metricsExplorer.find(Input);
36
input.simulate('change', { target: { value: 'go' } });
37
const metrics = metricsExplorer.find('.metric');
38
expect(metrics).toHaveLength(1);
41
it('handles click on metric', () => {
42
const metric = metricsExplorer.find('.metric').at(0);
43
metric.simulate('click');
44
expect(metricsExplorerProps.insertAtCursor).toHaveBeenCalled();