This repository has been archived by the owner on Oct 8, 2022. It is now read-only.
/
index.spec.js
73 lines (58 loc) · 1.98 KB
/
index.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import React from 'react'
import { render, fireEvent } from '@testing-library/react'
import LaneForm from './'
describe('<LaneForm />', () => {
let subject, onConfirm, onCancel
function mount() {
onConfirm = jest.fn()
onCancel = jest.fn()
subject = render(<LaneForm onConfirm={onConfirm} onCancel={onCancel} />)
}
beforeEach(mount)
afterEach(() => {
subject = onConfirm = onCancel = undefined
})
it('renders an input asking for a lane title', () => {
expect(subject.container.querySelector('input')).toBeInTheDocument()
})
it('focus on the input', () => {
expect(subject.container.querySelector('input')).toHaveFocus()
})
describe('when the user clicks confirm the input', () => {
describe('when the user has typed a lane title', () => {
beforeEach(() => {
fireEvent.change(subject.container.querySelector('input'), { target: { value: 'Lane Title' } })
fireEvent.click(subject.queryByText('Add'))
})
it('calls the onConfirm prop passing the lane title', () => {
expect(onConfirm).toHaveBeenCalledTimes(1)
expect(onConfirm).toHaveBeenCalledWith('Lane Title')
})
it('does not call the onCancel prop', () => {
expect(onCancel).not.toHaveBeenCalled()
})
})
describe('when the user has not typed a lane title', () => {
beforeEach(() => {
fireEvent.click(subject.queryByText('Add'))
})
it('does not call the onConfirm prop', () => {
expect(onConfirm).not.toHaveBeenCalled()
})
it('does not call the onCancel prop', () => {
expect(onCancel).not.toHaveBeenCalled()
})
})
})
describe('when the user cancels the input', () => {
beforeEach(() => {
fireEvent.click(subject.queryByText('Cancel'))
})
it('calls the onCancel prop', () => {
expect(onCancel).toHaveBeenCalledTimes(1)
})
it('does not call the onConfirm prop', () => {
expect(onConfirm).not.toHaveBeenCalled()
})
})
})