-
Notifications
You must be signed in to change notification settings - Fork 19
/
create-project-modal-feature.spec.tsx
69 lines (56 loc) · 2.02 KB
/
create-project-modal-feature.spec.tsx
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
import { act, fireEvent, render } from '__tests__/utils/setup-jest'
import * as storeProjects from '@qovery/domains/projects'
import CreateProjectModalFeature, { CreateProjectModalFeatureProps } from './create-project-modal-feature'
import SpyInstance = jest.SpyInstance
const mockedUsedNavigate = jest.fn()
jest.mock('react-router-dom', () => ({
...(jest.requireActual('react-router-dom') as any),
useNavigate: () => mockedUsedNavigate,
}))
jest.mock('@qovery/domains/projects', () => ({
...jest.requireActual('@qovery/domains/projects'),
postProject: jest.fn().mockImplementation(() => Promise.resolve()),
}))
const mockDispatch = jest.fn()
jest.mock('react-redux', () => ({
...jest.requireActual('react-redux'),
useDispatch: () => mockDispatch,
}))
describe('CreateProjectModalFeature', () => {
const props: CreateProjectModalFeatureProps = {
onClose: jest.fn(),
organizationId: '0',
goToEnvironment: false,
}
it('should render successfully', () => {
const { baseElement } = render(<CreateProjectModalFeature {...props} />)
expect(baseElement).toBeTruthy()
})
it('should dispatch postProject if form is submitted', async () => {
const postProjectSpy: SpyInstance = jest.spyOn(storeProjects, 'postProject')
mockDispatch.mockImplementation(() => ({
unwrap: () =>
Promise.resolve({
data: {},
}),
}))
const { getByTestId } = render(<CreateProjectModalFeature {...props} />)
await act(() => {
const inputName = getByTestId('input-name')
fireEvent.input(inputName, { target: { value: 'hello-world' } })
})
await act(() => {
const inputName = getByTestId('input-description')
fireEvent.input(inputName, { target: { value: 'description' } })
})
expect(getByTestId('submit-button')).not.toBeDisabled()
await act(() => {
getByTestId('submit-button').click()
})
expect(postProjectSpy).toHaveBeenCalledWith({
name: 'hello-world',
description: 'description',
organizationId: '0',
})
})
})