|
1 | 1 | import React from 'react' |
2 | 2 | import { instance, mock } from 'ts-mockito' |
3 | | -import { screen, fireEvent } from 'testSrc/helpers' |
| 3 | +import { fireEvent, render, screen } from 'testSrc/helpers' |
| 4 | +import { EditEntireItemAction, Props } from './EditEntireItemAction' |
4 | 5 | import { JSONErrors } from '../../constants' |
5 | 6 |
|
6 | | -const mockedProps = mock<any>() |
| 7 | +const mockedProps = mock<Props>() |
7 | 8 | const valueOfEntireItem = '"Sample string"' |
8 | 9 |
|
9 | | -async function renderWithMockedMonaco(props: any) { |
10 | | - vi.resetModules() |
11 | | - vi.doMock('react-monaco-editor', () => ({ |
12 | | - default: ({ value, onChange, 'data-testid': dataTestId }: any) => ( |
13 | | - <textarea |
14 | | - data-testid={dataTestId} |
15 | | - value={value} |
16 | | - onChange={(e) => onChange?.(e.target.value)} |
17 | | - /> |
18 | | - ), |
19 | | - })) |
20 | | - |
21 | | - const { EditEntireItemAction } = await import('./EditEntireItemAction') |
22 | | - const { render } = await import('testSrc/helpers') |
23 | | - return render(<EditEntireItemAction {...props} />) |
24 | | -} |
25 | | - |
26 | 10 | describe('EditEntireItemAction', () => { |
27 | | - it('renders correctly with provided props', async () => { |
28 | | - await renderWithMockedMonaco({ |
29 | | - ...instance(mockedProps), |
30 | | - initialValue: valueOfEntireItem, |
31 | | - }) |
| 11 | + it('renders correctly with provided props', () => { |
| 12 | + render( |
| 13 | + <EditEntireItemAction |
| 14 | + {...instance(mockedProps)} |
| 15 | + initialValue={valueOfEntireItem} |
| 16 | + />, |
| 17 | + ) |
32 | 18 |
|
33 | 19 | expect(screen.getByTestId('json-value')).toBeInTheDocument() |
34 | 20 | expect(screen.getByTestId('json-value')).toHaveValue(valueOfEntireItem) |
35 | 21 | }) |
36 | 22 |
|
37 | | - it('triggers handleUpdateValueFormSubmit when the form is submitted', async () => { |
| 23 | + it('triggers handleUpdateValueFormSubmit when the form is submitted', () => { |
38 | 24 | const handleUpdateValueFormSubmit = vi.fn() |
39 | 25 |
|
40 | | - await renderWithMockedMonaco({ |
41 | | - ...instance(mockedProps), |
42 | | - initialValue: valueOfEntireItem, |
43 | | - onSubmit: handleUpdateValueFormSubmit, |
44 | | - }) |
| 26 | + render( |
| 27 | + <EditEntireItemAction |
| 28 | + {...instance(mockedProps)} |
| 29 | + initialValue={valueOfEntireItem} |
| 30 | + onSubmit={handleUpdateValueFormSubmit} |
| 31 | + />, |
| 32 | + ) |
45 | 33 |
|
46 | 34 | fireEvent.submit(screen.getByTestId('json-entire-form')) |
47 | 35 | expect(handleUpdateValueFormSubmit).toHaveBeenCalled() |
48 | 36 | }) |
49 | 37 |
|
50 | | - it('should show error and not submit', async () => { |
| 38 | + it('should show error and not submit', () => { |
51 | 39 | const handleUpdateValueFormSubmit = vi.fn() |
52 | 40 |
|
53 | | - await renderWithMockedMonaco({ |
54 | | - ...instance(mockedProps), |
55 | | - initialValue: 'xxxx', |
56 | | - onSubmit: handleUpdateValueFormSubmit, |
57 | | - }) |
| 41 | + render( |
| 42 | + <EditEntireItemAction |
| 43 | + {...instance(mockedProps)} |
| 44 | + initialValue="xxxx" |
| 45 | + onSubmit={handleUpdateValueFormSubmit} |
| 46 | + />, |
| 47 | + ) |
58 | 48 |
|
59 | 49 | fireEvent.submit(screen.getByTestId('json-entire-form')) |
60 | 50 | expect(screen.getByTestId('edit-json-error')).toHaveTextContent( |
|
0 commit comments