Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions packages/query-devtools/src/__tests__/Devtools.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -575,4 +575,73 @@ describe('Devtools', () => {
)
})
})

describe('mutation details', () => {
it('should open the mutation details panel when a mutation row is clicked', async () => {
const rendered = renderDevtools({ initialIsOpen: true })

fireEvent.click(rendered.getByText('Mutations'))

const mutation = queryClient.getMutationCache().build(queryClient, {
mutationKey: ['mutation-detail'],
mutationFn: () => Promise.resolve('ok'),
})
mutation.execute({})
await vi.advanceTimersByTimeAsync(0)

fireEvent.click(rendered.getByLabelText(/Mutation submitted at/))

expect(rendered.getByText('Mutation Details')).toBeInTheDocument()
})
})

describe('mutation sort order', () => {
it('should toggle the mutation sort order in the mutations view', () => {
const rendered = renderDevtools({ initialIsOpen: true })
fireEvent.click(rendered.getByText('Mutations'))

fireEvent.click(rendered.getByLabelText(/Sort order/))
const afterFirstToggle = localStorage.getItem(
'TanstackQueryDevtools.mutationSortOrder',
)
expect(afterFirstToggle).not.toBeNull()

fireEvent.click(rendered.getByLabelText(/Sort order/))
const afterSecondToggle = localStorage.getItem(
'TanstackQueryDevtools.mutationSortOrder',
)
expect(afterSecondToggle).not.toBe(afterFirstToggle)
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.
})

describe('mutation filter', () => {
it('should filter mutations by their "mutationKey"', async () => {
const rendered = renderDevtools({ initialIsOpen: true })
fireEvent.click(rendered.getByText('Mutations'))

const matching = queryClient.getMutationCache().build(queryClient, {
mutationKey: ['filter-match'],
mutationFn: () => Promise.resolve('ok'),
})
const other = queryClient.getMutationCache().build(queryClient, {
mutationKey: ['filter-other'],
mutationFn: () => Promise.resolve('ok'),
})
matching.execute({})
other.execute({})
await vi.advanceTimersByTimeAsync(0)

expect(rendered.getAllByLabelText(/Mutation submitted at/)).toHaveLength(
2,
)

fireEvent.input(rendered.getByLabelText('Filter queries by query key'), {
target: { value: 'filter-match' },
})

expect(rendered.getAllByLabelText(/Mutation submitted at/)).toHaveLength(
1,
)
})
})
})
Loading