mirror of
https://github.com/bookorbit/bookorbit.git
synced 2026-11-03 08:21:39 -06:00
fix(smart-scope): refresh sidebar counts after saving
Return matching item counts with create and update responses so the sidebar can display the saved scope count without requiring a page reload. Reuse the listing count logic and verify visibility and shared sidebar state.
This commit is contained in:
@@ -41,27 +41,30 @@ describe('useSmartScopes', () => {
|
||||
apiMock.mockReset()
|
||||
})
|
||||
|
||||
it('replaces the smartScope array when creating a smartScope', async () => {
|
||||
const created = makeSmartScope()
|
||||
it('adds the created scope and its book count to the shared sidebar state', async () => {
|
||||
const created = makeSmartScope({ bookCount: 7 })
|
||||
apiMock.mockResolvedValueOnce(makeResponse(created))
|
||||
|
||||
const { useSmartScopes } = await import('../useSmartScopes')
|
||||
const { smartScopes, createSmartScope } = useSmartScopes()
|
||||
const previous = smartScopes.value
|
||||
const sidebar = useSmartScopes()
|
||||
|
||||
await createSmartScope({ name: created.name, icon: 'Aperture', defaultSort: [] })
|
||||
|
||||
expect(smartScopes.value).toEqual([created])
|
||||
expect(smartScopes.value).not.toBe(previous)
|
||||
expect(sidebar.bookScopes.value[0]?.bookCount).toBe(7)
|
||||
})
|
||||
|
||||
it('replaces the smartScope array when updating a smartScope', async () => {
|
||||
const created = makeSmartScope()
|
||||
const updated = makeSmartScope({ name: 'Updated SmartScope' })
|
||||
it('replaces the cached book count with the count returned after an update', async () => {
|
||||
const created = makeSmartScope({ bookCount: 7 })
|
||||
const updated = makeSmartScope({ name: 'Updated SmartScope', bookCount: 3 })
|
||||
apiMock.mockResolvedValueOnce(makeResponse(created)).mockResolvedValueOnce(makeResponse(updated))
|
||||
|
||||
const { useSmartScopes } = await import('../useSmartScopes')
|
||||
const { smartScopes, createSmartScope, updateSmartScope } = useSmartScopes()
|
||||
const sidebar = useSmartScopes()
|
||||
|
||||
await createSmartScope({ name: created.name, icon: 'Aperture', defaultSort: [] })
|
||||
const previous = smartScopes.value
|
||||
@@ -69,6 +72,7 @@ describe('useSmartScopes', () => {
|
||||
|
||||
expect(smartScopes.value).toEqual([updated])
|
||||
expect(smartScopes.value).not.toBe(previous)
|
||||
expect(sidebar.bookScopes.value[0]?.bookCount).toBe(3)
|
||||
})
|
||||
|
||||
it('patches the sharing flag and reflects the shared scope returned by the server', async () => {
|
||||
|
||||
Reference in New Issue
Block a user