Skip to content

Commit db90ec7

Browse files
committed
remove local mock
1 parent 78abc04 commit db90ec7

File tree

1 file changed

+26
-36
lines changed

1 file changed

+26
-36
lines changed

src/webviews/src/modules/key-details/components/rejson-details/components/edit-entire-item-action/EditEntireItemAction.spec.tsx

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,50 @@
11
import React from 'react'
22
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'
45
import { JSONErrors } from '../../constants'
56

6-
const mockedProps = mock<any>()
7+
const mockedProps = mock<Props>()
78
const valueOfEntireItem = '"Sample string"'
89

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-
2610
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+
)
3218

3319
expect(screen.getByTestId('json-value')).toBeInTheDocument()
3420
expect(screen.getByTestId('json-value')).toHaveValue(valueOfEntireItem)
3521
})
3622

37-
it('triggers handleUpdateValueFormSubmit when the form is submitted', async () => {
23+
it('triggers handleUpdateValueFormSubmit when the form is submitted', () => {
3824
const handleUpdateValueFormSubmit = vi.fn()
3925

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+
)
4533

4634
fireEvent.submit(screen.getByTestId('json-entire-form'))
4735
expect(handleUpdateValueFormSubmit).toHaveBeenCalled()
4836
})
4937

50-
it('should show error and not submit', async () => {
38+
it('should show error and not submit', () => {
5139
const handleUpdateValueFormSubmit = vi.fn()
5240

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+
)
5848

5949
fireEvent.submit(screen.getByTestId('json-entire-form'))
6050
expect(screen.getByTestId('edit-json-error')).toHaveTextContent(

0 commit comments

Comments
 (0)