- )
- }
-
- renderWithClient(queryClient, )
-
- fireEvent.click(
- screen.getByRole('button', { name: /open react query devtools/i }),
- )
-
- const query1Hash =
- queryCache.find({ queryKey: ['query-1'] })?.queryHash ?? 'invalid hash'
- const query2Hash =
- queryCache.find({ queryKey: ['query-2'] })?.queryHash ?? 'invalid hash'
- const query3Hash =
- queryCache.find({ queryKey: ['query-3'] })?.queryHash ?? 'invalid hash'
-
- const sortSelect = screen.getByLabelText(/sort queries/i)
- let queries = []
-
- // When sorted by query hash the queries get sorted according
- // to just the number, with the order being -> query-1, query-2, query-3
- fireEvent.change(sortSelect, { target: { value: 'Query Hash' } })
-
- /** To check the order of the queries we can use regex to find
- * all the row items in an array and then compare the items
- * one by one in the order we expect it
- * @reference https://github.com/testing-library/react-testing-library/issues/313#issuecomment-625294327
- */
- queries = await screen.findAllByText(/\["query-[1-3]"\]/)
- expect(queries[0]?.textContent).toEqual(query1Hash)
- expect(queries[1]?.textContent).toEqual(query2Hash)
- expect(queries[2]?.textContent).toEqual(query3Hash)
-
- // Wait for the queries to be resolved
- await screen.findByText(/query-1-result query-2-result query-3-result/i)
-
- // When sorted by the last updated date the queries are sorted by the time
- // they were updated and since the query-2 takes longest time to complete
- // and query-1 the shortest, so the order is -> query-2, query-3, query-1
- fireEvent.change(sortSelect, { target: { value: 'Last Updated' } })
-
- queries = await screen.findAllByText(/\["query-[1-3]"\]/)
- expect(queries[0]?.textContent).toEqual(query2Hash)
- expect(queries[1]?.textContent).toEqual(query3Hash)
- expect(queries[2]?.textContent).toEqual(query1Hash)
-
- // When sorted by the status and then last updated date the queries
- // query-3 takes precedence because its stale time being infinity, it
- // always remains fresh, the rest of the queries are sorted by their last
- // updated time, so the resulting order is -> query-3, query-2, query-1
- fireEvent.change(sortSelect, {
- target: { value: 'Status > Last Updated' },
- })
-
- queries = await screen.findAllByText(/\["query-[1-3]"\]/)
- expect(queries[0]?.textContent).toEqual(query3Hash)
- expect(queries[1]?.textContent).toEqual(query2Hash)
- expect(queries[2]?.textContent).toEqual(query1Hash)
-
- // Switch the order form ascending to descending and expect the
- // query order to be reversed from previous state
- fireEvent.click(screen.getByRole('button', { name: /⬆ asc/i }))
-
- queries = await screen.findAllByText(/\["query-[1-3]"\]/)
- expect(queries[0]?.textContent).toEqual(query1Hash)
- expect(queries[1]?.textContent).toEqual(query2Hash)
- expect(queries[2]?.textContent).toEqual(query3Hash)
- })
-
- it('should initialize filtering and sorting values with defaults when they are not stored in localstorage', () => {
- localStorage.removeItem('reactQueryDevtoolsBaseSort')
- localStorage.removeItem('reactQueryDevtoolsSortFn')
- localStorage.removeItem('reactQueryDevtoolsFilter')
-
- const { queryClient } = createQueryClient()
-
- function Page() {
- const { data = 'default' } = useQuery({
- queryKey: ['check'],
- queryFn: async () => {
- await sleep(10)
- return 'test'
- },
- })
-
- return (
-