UNPKG

2.32 kBJavaScriptView Raw
1import chai, { expect } from 'chai'
2import chaiEnzyme from 'chai-enzyme'
3import React from 'react'
4import sinon from 'sinon'
5import sinonChai from 'sinon-chai'
6import { mount, shallow } from 'enzyme'
7
8import styles from './styles.css'
9import Input from './'
10
11chai.use(chaiEnzyme())
12chai.use(sinonChai)
13
14describe('<Input />', () => {
15 describe('when given no props', () => {
16 let sut
17
18 beforeEach(() => {
19 sut = mount(<Input />)
20 })
21
22 it('should set the default props', () => {
23 expect(sut).to.have.prop('name', '')
24 })
25
26 it('should not render the label', () => {
27 expect(sut).to.not.contain(<label />)
28 })
29 })
30
31 describe('when given a name', () => {
32 it('should render the text input with the name', () => {
33 const sut = mount(<Input name="cats" />)
34 expect(sut).to.have.prop('name', 'cats')
35 })
36 })
37
38 describe('when given a placeholder', () => {
39 it('should render the text input with the placeholder', () => {
40 const sut = mount(<Input placeholder="Enter Cats Here" />)
41 expect(sut).to.have.prop('placeholder', 'Enter Cats Here')
42 })
43 })
44
45 describe('when given a label', () => {
46 it('should render the text input with the label', () => {
47 const sut = mount(<Input label="Cats4Ever" />)
48 expect(sut).to.have.prop('label', 'Cats4Ever')
49 })
50 })
51
52 describe('when given a class name', () => {
53 it('should add the class name in to the text input', () => {
54 const sut = shallow(<Input className="catsAreAwesome" />)
55 expect(sut).to.have.className("catsAreAwesome")
56 })
57 })
58
59 describe('when disabled prop is truthy', () => {
60 it('should render the input as disabled', () => {
61 const sut = shallow(<Input disabled />)
62 expect(sut).to.have.className(styles['is-disabled'])
63 })
64 })
65
66 describe('when required prop is truthy', () => {
67 it('should add the is-required class to the input', () => {
68 const sut = shallow(<Input required />)
69 expect(sut).to.have.className(styles['is-required'])
70 })
71 })
72
73 describe('when given unspecified props', () => {
74 it('should merge the props with <input /> props', () => {
75 const sut = mount(<Input required />)
76 const inputField = sut.find('input[type="text"]')
77 expect(inputField).to.have.prop('required', true)
78 })
79 })
80})