Skip to content

Commit 37293a7

Browse files
tests(confirmation-modal): add tests to confirmation-modal comp
1 parent c0e2371 commit 37293a7

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from 'react'
2+
import { render, fireEvent } from '@testing-library/react'
3+
import { vi } from 'vitest'
4+
import { ConfirmationModal } from '../confirmation-modal'
5+
6+
describe('ConfirmationModal', () => {
7+
it('should call onConfirm when confirm button is clicked', () => {
8+
const onConfirm = vi.fn()
9+
const onCancel = vi.fn()
10+
11+
const { getByText } = render(
12+
<ConfirmationModal open onConfirm={onConfirm} onCancel={onCancel}>
13+
Are you sure you want to proceed?
14+
</ConfirmationModal>
15+
)
16+
17+
const confirmButton = getByText('Confirm')
18+
19+
fireEvent.click(confirmButton)
20+
21+
expect(onConfirm).toHaveBeenCalled()
22+
expect(onCancel).not.toHaveBeenCalled()
23+
})
24+
25+
it('should call onCancel when cancel button is clicked', () => {
26+
const onConfirm = vi.fn()
27+
const onCancel = vi.fn()
28+
29+
const { getByText } = render(
30+
<ConfirmationModal open onConfirm={onConfirm} onCancel={onCancel}>
31+
Are you sure you want to proceed?
32+
</ConfirmationModal>
33+
)
34+
35+
const cancelButton = getByText('Cancel')
36+
37+
fireEvent.click(cancelButton)
38+
39+
expect(onCancel).toHaveBeenCalled()
40+
expect(onConfirm).not.toHaveBeenCalled()
41+
})
42+
})

0 commit comments

Comments
 (0)