Skip to content

Commit 3e74fcb

Browse files
test(query-devtools/Devtools): add tests for sort dropdown, hide disabled queries, and sort order toggle (#10689)
* test(query-devtools/Devtools): add tests for sort dropdown, hide disabled queries, and sort order toggle * ci: apply automated fixes * test(query-devtools/Devtools): assert exact 'sortOrder' values ('1' and '-1') across consecutive toggles --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 7e45976 commit 3e74fcb

1 file changed

Lines changed: 73 additions & 1 deletion

File tree

packages/query-devtools/src/__tests__/Devtools.test.tsx

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2-
import { QueryClient, onlineManager } from '@tanstack/query-core'
2+
import { QueryClient, QueryObserver, onlineManager } from '@tanstack/query-core'
33
import { fireEvent, render } from '@solidjs/testing-library'
44
import { createLocalStorage } from '@solid-primitives/storage'
55
import { Devtools } from '../Devtools'
@@ -732,4 +732,76 @@ describe('Devtools', () => {
732732
)
733733
})
734734
})
735+
736+
describe('sort by', () => {
737+
it('should change sort key when the sort dropdown is changed in queries view', () => {
738+
const rendered = renderDevtools({ initialIsOpen: true })
739+
740+
fireEvent.change(rendered.getByLabelText('Sort queries by'), {
741+
target: { value: 'last updated' },
742+
})
743+
744+
expect(localStorage.getItem('TanstackQueryDevtools.sort')).toBe(
745+
'last updated',
746+
)
747+
})
748+
749+
it('should change sort key when the sort dropdown is changed in mutations view', () => {
750+
const rendered = renderDevtools({ initialIsOpen: true })
751+
fireEvent.click(rendered.getByText('Mutations'))
752+
753+
fireEvent.change(rendered.getByLabelText('Sort mutations by'), {
754+
target: { value: 'last updated' },
755+
})
756+
757+
expect(localStorage.getItem('TanstackQueryDevtools.mutationSort')).toBe(
758+
'last updated',
759+
)
760+
})
761+
762+
it('should hide disabled queries when "hideDisabledQueries" is enabled in localStorage', () => {
763+
const disabled = new QueryObserver(queryClient, {
764+
queryKey: ['hide-test-disabled'],
765+
queryFn: () => 'x',
766+
enabled: false,
767+
})
768+
const unsubscribe = disabled.subscribe(() => {})
769+
queryClient.setQueryData(['hide-test-disabled'], 'x')
770+
queryClient.setQueryData(['hide-test-active'], 'y')
771+
772+
try {
773+
const rendered = renderDevtools(
774+
{ initialIsOpen: true },
775+
{ 'TanstackQueryDevtools.hideDisabledQueries': 'true' },
776+
)
777+
778+
expect(
779+
rendered.queryByLabelText(/Query key \["hide-test-disabled"\]/),
780+
).not.toBeInTheDocument()
781+
expect(
782+
rendered.getByLabelText(/Query key \["hide-test-active"\]/),
783+
).toBeInTheDocument()
784+
} finally {
785+
unsubscribe()
786+
}
787+
})
788+
})
789+
790+
describe('sort order', () => {
791+
it('should toggle the sort order when the sort order button is clicked', () => {
792+
const rendered = renderDevtools({ initialIsOpen: true })
793+
794+
fireEvent.click(rendered.getByLabelText(/Sort order/))
795+
const afterFirstToggle = localStorage.getItem(
796+
'TanstackQueryDevtools.sortOrder',
797+
)
798+
expect(['1', '-1']).toContain(afterFirstToggle)
799+
800+
fireEvent.click(rendered.getByLabelText(/Sort order/))
801+
const afterSecondToggle = localStorage.getItem(
802+
'TanstackQueryDevtools.sortOrder',
803+
)
804+
expect(afterSecondToggle).toBe(afterFirstToggle === '1' ? '-1' : '1')
805+
})
806+
})
735807
})

0 commit comments

Comments
 (0)