-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathDeleteDraftModal.test.js
49 lines (37 loc) · 1.07 KB
/
DeleteDraftModal.test.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
import React from 'react'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import DeleteDraftModal from '../DeleteDraftModal'
const setup = () => {
const props = {
closeModal: jest.fn(),
onDelete: jest.fn(),
show: true
}
render(<DeleteDraftModal {...props} />)
return {
props
}
}
describe('DeleteDraftModal', () => {
test('renders a modal', () => {
setup()
expect(screen.getByText('Are you sure you want to delete this draft?')).toBeInTheDocument()
})
describe('when selecting `No`', () => {
test('calls closeModal', async () => {
const { props } = setup()
const button = screen.getByText('No')
await userEvent.click(button)
expect(props.closeModal).toHaveBeenCalledTimes(1)
})
})
describe('when selecting `Yes`', () => {
test('calls onDelete', async () => {
const { props } = setup()
const button = screen.getByText('Yes')
await userEvent.click(button)
expect(props.onDelete).toHaveBeenCalledTimes(1)
})
})
})