github.com/thanos-io/thanos@v0.32.5/pkg/ui/react-app/src/pages/graph/TimeInput.test.tsx (about) 1 import * as React from 'react'; 2 import { shallow } from 'enzyme'; 3 import sinon from 'sinon'; 4 import TimeInput from './TimeInput'; 5 import { Button, InputGroup, InputGroupAddon, Input } from 'reactstrap'; 6 import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; 7 import { faChevronLeft, faChevronRight, faTimes } from '@fortawesome/free-solid-svg-icons'; 8 9 describe('TimeInput', () => { 10 const timeInputProps = { 11 time: 1572102237932, 12 range: 60 * 60 * 7, 13 placeholder: 'time input', 14 useLocalTime: true, 15 onChangeTime: (): void => { 16 // Do nothing. 17 }, 18 }; 19 const timeInput = shallow(<TimeInput {...timeInputProps} />); 20 it('renders the string "scalar"', () => { 21 const inputGroup = timeInput.find(InputGroup); 22 expect(inputGroup.prop('className')).toEqual('time-input'); 23 expect(inputGroup.prop('size')).toEqual('sm'); 24 }); 25 26 it('renders buttons to adjust time', () => { 27 [ 28 { 29 position: 'prepend', 30 title: 'Decrease time', 31 icon: faChevronLeft, 32 }, 33 { 34 position: 'append', 35 title: 'Clear time', 36 icon: faTimes, 37 }, 38 { 39 position: 'append', 40 title: 'Increase time', 41 icon: faChevronRight, 42 }, 43 ].forEach((button) => { 44 const onChangeTime = sinon.spy(); 45 const timeInput = shallow(<TimeInput {...timeInputProps} onChangeTime={onChangeTime} />); 46 const addon = timeInput.find(InputGroupAddon).filterWhere((addon) => addon.prop('addonType') === button.position); 47 const btn = addon.find(Button).filterWhere((btn) => btn.prop('title') === button.title); 48 const icon = btn.find(FontAwesomeIcon); 49 expect(icon.prop('icon')).toEqual(button.icon); 50 expect(icon.prop('fixedWidth')).toBe(true); 51 btn.simulate('click'); 52 expect(onChangeTime.calledOnce).toBe(true); 53 }); 54 }); 55 56 it('renders an Input', () => { 57 const input = timeInput.find(Input); 58 expect(input.prop('placeholder')).toEqual(timeInputProps.placeholder); 59 expect(input.prop('innerRef')).toEqual({ current: null }); 60 }); 61 });