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';
9
describe('TimeInput', () => {
10
const timeInputProps = {
13
placeholder: 'time input',
14
onChangeTime: (): void => {
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');
26
it('renders buttons to adjust time', () => {
30
title: 'Decrease time',
40
title: 'Increase time',
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);
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 });