mirror of
https://github.com/langgenius/dify.git
synced 2026-05-09 04:36:31 +08:00
test: refactor GenericTable tests to use a helper function for option selection
This commit is contained in:
parent
8e093a2b25
commit
f7ae14d50e
@ -1,4 +1,4 @@
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { useState } from 'react'
|
||||
import GenericTable from '../generic-table'
|
||||
@ -53,6 +53,16 @@ describe('GenericTable', () => {
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
const selectOption = async (triggerName: string, optionName: string) => {
|
||||
await act(async () => {
|
||||
fireEvent.click(screen.getByRole('button', { name: triggerName }))
|
||||
})
|
||||
|
||||
await act(async () => {
|
||||
fireEvent.click(await screen.findByRole('option', { name: optionName }))
|
||||
})
|
||||
}
|
||||
|
||||
it('should render an empty editable row and append a configured row when typing into the virtual row', async () => {
|
||||
const onChange = vi.fn()
|
||||
|
||||
@ -144,8 +154,7 @@ describe('GenericTable', () => {
|
||||
<ControlledTable />,
|
||||
)
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Choose method' }))
|
||||
await user.click(await screen.findByRole('option', { name: 'POST' }))
|
||||
await selectOption('Choose method', 'POST')
|
||||
|
||||
await waitFor(() => {
|
||||
expect(onChange).toHaveBeenCalledWith([{ method: 'post', preview: '' }])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user