Skip to content

Commit

Permalink
test(27766): add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vanch3d committed Nov 18, 2024
1 parent cf190a0 commit 558a9e4
Showing 1 changed file with 75 additions and 0 deletions.
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)
})
})

0 comments on commit 558a9e4

Please sign in to comment.