mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 18:08:07 +08:00
test: improve coverage parameters for some files in base (#33207)
This commit is contained in:
@ -238,6 +238,32 @@ describe('ErrorBoundary', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should not reset when resetKeys reference changes but values are identical', async () => {
|
||||
const onReset = vi.fn()
|
||||
|
||||
const StableKeysHarness = () => {
|
||||
const [keys, setKeys] = React.useState<Array<string | number>>([1, 2])
|
||||
return (
|
||||
<>
|
||||
<button onClick={() => setKeys([1, 2])}>Update keys same values</button>
|
||||
<ErrorBoundary resetKeys={keys} onReset={onReset}>
|
||||
<ThrowOnRender shouldThrow={true} />
|
||||
</ErrorBoundary>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
render(<StableKeysHarness />)
|
||||
await screen.findByText('Something went wrong')
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Update keys same values' }))
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Something went wrong')).toBeInTheDocument()
|
||||
})
|
||||
expect(onReset).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should reset after children change when resetOnPropsChange is true', async () => {
|
||||
const ResetOnPropsHarness = () => {
|
||||
const [shouldThrow, setShouldThrow] = React.useState(true)
|
||||
@ -269,6 +295,24 @@ describe('ErrorBoundary', () => {
|
||||
expect(screen.getByText('second child')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
it('should call window.location.reload when Reload Page is clicked', async () => {
|
||||
const reloadSpy = vi.fn()
|
||||
Object.defineProperty(window, 'location', {
|
||||
value: { ...window.location, reload: reloadSpy },
|
||||
writable: true,
|
||||
})
|
||||
|
||||
render(
|
||||
<ErrorBoundary>
|
||||
<ThrowOnRender shouldThrow={true} />
|
||||
</ErrorBoundary>,
|
||||
)
|
||||
|
||||
fireEvent.click(await screen.findByRole('button', { name: 'Reload Page' }))
|
||||
|
||||
expect(reloadSpy).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@ -358,6 +402,16 @@ describe('ErrorBoundary utility exports', () => {
|
||||
|
||||
expect(Wrapped.displayName).toBe('withErrorBoundary(NamedComponent)')
|
||||
})
|
||||
|
||||
it('should fallback displayName to Component when wrapped component has no displayName and empty name', () => {
|
||||
const Nameless = (() => <div>nameless</div>) as React.FC
|
||||
Object.defineProperty(Nameless, 'displayName', { value: undefined, configurable: true })
|
||||
Object.defineProperty(Nameless, 'name', { value: '', configurable: true })
|
||||
|
||||
const Wrapped = withErrorBoundary(Nameless)
|
||||
|
||||
expect(Wrapped.displayName).toBe('withErrorBoundary(Component)')
|
||||
})
|
||||
})
|
||||
|
||||
// Validate simple fallback helper component.
|
||||
|
||||
Reference in New Issue
Block a user