-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
hivemq-edge/src/frontend/src/components/rjsf/Form/useFormControlStore.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { expect } from 'vitest' | ||
import { act, renderHook } from '@testing-library/react' | ||
|
||
import { useFormControlStore } from '@/components/rjsf/Form/useFormControlStore.ts' | ||
import { FormControlStore } from '@/components/rjsf/Form/types.ts' | ||
|
||
describe('useWorkspaceStore', () => { | ||
beforeEach(() => { | ||
const { result } = renderHook<FormControlStore, undefined>(useFormControlStore) | ||
act(() => { | ||
result.current.reset() | ||
}) | ||
}) | ||
|
||
it('should start with a default store', async () => { | ||
const { result } = renderHook<FormControlStore, undefined>(useFormControlStore) | ||
|
||
expect(result.current.expandItems).toStrictEqual([]) | ||
expect(result.current.tabIndex).toStrictEqual(0) | ||
}) | ||
|
||
it('should change the selected tab', async () => { | ||
const { result } = renderHook<FormControlStore, undefined>(useFormControlStore) | ||
|
||
expect(result.current.expandItems).toStrictEqual([]) | ||
expect(result.current.tabIndex).toStrictEqual(0) | ||
|
||
act(() => { | ||
const { setTabIndex } = result.current | ||
setTabIndex(2) | ||
}) | ||
|
||
expect(result.current.expandItems).toStrictEqual([]) | ||
expect(result.current.tabIndex).toStrictEqual(2) | ||
}) | ||
|
||
it('should change the list of collapsed items', async () => { | ||
const { result } = renderHook<FormControlStore, undefined>(useFormControlStore) | ||
|
||
expect(result.current.expandItems).toStrictEqual([]) | ||
expect(result.current.tabIndex).toStrictEqual(0) | ||
|
||
act(() => { | ||
const { setExpandItems } = result.current | ||
setExpandItems(['first', 'second']) | ||
}) | ||
|
||
expect(result.current.expandItems).toStrictEqual(['first', 'second']) | ||
expect(result.current.tabIndex).toStrictEqual(0) | ||
}) | ||
|
||
it('should reset the store', async () => { | ||
const { result } = renderHook<FormControlStore, undefined>(useFormControlStore) | ||
|
||
expect(result.current.expandItems).toStrictEqual([]) | ||
expect(result.current.tabIndex).toStrictEqual(0) | ||
|
||
act(() => { | ||
const { setExpandItems, setTabIndex } = result.current | ||
setExpandItems(['first', 'second']) | ||
setTabIndex(2) | ||
}) | ||
|
||
expect(result.current.expandItems).toStrictEqual(['first', 'second']) | ||
expect(result.current.tabIndex).toStrictEqual(2) | ||
|
||
act(() => { | ||
const { reset } = result.current | ||
reset() | ||
}) | ||
|
||
expect(result.current.expandItems).toStrictEqual([]) | ||
expect(result.current.tabIndex).toStrictEqual(0) | ||
}) | ||
}) |