Skip to content

Commit 23ed38b

Browse files
committed
fix tests
1 parent 2ff665e commit 23ed38b

2 files changed

Lines changed: 42 additions & 22 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -1,46 +1,65 @@
11
import React from 'react'
22
import { instance, mock } from 'ts-mockito'
3-
import { fireEvent, render, screen } from 'testSrc/helpers'
4-
import { EditEntireItemAction, Props } from './EditEntireItemAction'
3+
import { screen, fireEvent } from 'testSrc/helpers'
54
import { JSONErrors } from '../../constants'
65

7-
const mockedProps = mock<Props>()
8-
6+
const mockedProps = mock<any>()
97
const valueOfEntireItem = '"Sample string"'
108

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+
1126
describe('EditEntireItemAction', () => {
12-
it('renders correctly with provided props', () => {
13-
render(<EditEntireItemAction
14-
{...instance(mockedProps)}
15-
initialValue={valueOfEntireItem}
16-
/>)
27+
it('renders correctly with provided props', async () => {
28+
await renderWithMockedMonaco({
29+
...instance(mockedProps),
30+
initialValue: valueOfEntireItem,
31+
})
1732

1833
expect(screen.getByTestId('json-value')).toBeInTheDocument()
1934
expect(screen.getByTestId('json-value')).toHaveValue(valueOfEntireItem)
2035
})
2136

22-
it('triggers handleUpdateValueFormSubmit when the form is submitted', () => {
37+
it('triggers handleUpdateValueFormSubmit when the form is submitted', async () => {
2338
const handleUpdateValueFormSubmit = vi.fn()
24-
render(<EditEntireItemAction
25-
{...instance(mockedProps)}
26-
initialValue={valueOfEntireItem}
27-
onSubmit={handleUpdateValueFormSubmit}
28-
/>)
39+
40+
await renderWithMockedMonaco({
41+
...instance(mockedProps),
42+
initialValue: valueOfEntireItem,
43+
onSubmit: handleUpdateValueFormSubmit,
44+
})
2945

3046
fireEvent.submit(screen.getByTestId('json-entire-form'))
3147
expect(handleUpdateValueFormSubmit).toHaveBeenCalled()
3248
})
3349

34-
it('shouuld show error and do not submit', () => {
50+
it('should show error and not submit', async () => {
3551
const handleUpdateValueFormSubmit = vi.fn()
36-
render(<EditEntireItemAction
37-
{...instance(mockedProps)}
38-
initialValue="xxxx"
39-
onSubmit={handleUpdateValueFormSubmit}
40-
/>)
52+
53+
await renderWithMockedMonaco({
54+
...instance(mockedProps),
55+
initialValue: 'xxxx',
56+
onSubmit: handleUpdateValueFormSubmit,
57+
})
4158

4259
fireEvent.submit(screen.getByTestId('json-entire-form'))
43-
expect(screen.getByTestId('edit-json-error')).toHaveTextContent(JSONErrors.valueJSONFormat)
60+
expect(screen.getByTestId('edit-json-error')).toHaveTextContent(
61+
JSONErrors.valueJSONFormat,
62+
)
4463
expect(handleUpdateValueFormSubmit).not.toHaveBeenCalled()
4564
})
4665
})

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export const EditEntireItemAction = (props: Props) => {
6868
wrapperClassName={styles.editorWrapper}
6969
value={value}
7070
onChange={setValue}
71+
data-testid="json-value"
7172
/>
7273
</div>
7374
</div>

0 commit comments

Comments
 (0)