Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

infinite-query-property-order.utils.test.ts

79 lines2.1 KB

1import { describe, expect, test } from 'vitest'
2import { sortDataByOrder } from '../rules/infinite-query-property-order/infinite-query-property-order.utils'
3​
4describe('create-route-property-order utils', () => {
5 describe('sortDataByOrder', () => {
6 const testCases = [
7 {
8 data: [{ key: 'a' }, { key: 'c' }, { key: 'b' }],
9 orderArray: [
10 [['a'], ['b']],
11 [['b'], ['c']],
12 ],
13 key: 'key',
14 expected: [{ key: 'a' }, { key: 'b' }, { key: 'c' }],
15 },
16 {
17 data: [{ key: 'b' }, { key: 'a' }, { key: 'c' }],
18 orderArray: [
19 [['a'], ['b']],
20 [['b'], ['c']],
21 ],
22 key: 'key',
23 expected: [{ key: 'a' }, { key: 'b' }, { key: 'c' }],
24 },
25 {
26 data: [{ key: 'a' }, { key: 'b' }, { key: 'c' }],
27 orderArray: [
28 [['a'], ['b']],
29 [['b'], ['c']],
30 ],
31 key: 'key',
32 expected: null,
33 },
34 {
35 data: [{ key: 'a' }, { key: 'b' }, { key: 'c' }, { key: 'd' }],
36 orderArray: [
37 [['a'], ['b']],
38 [['b'], ['c']],
39 ],
40 key: 'key',
41 expected: null,
42 },
43 {
44 data: [{ key: 'a' }, { key: 'b' }, { key: 'd' }, { key: 'c' }],
45 orderArray: [
46 [['a'], ['b']],
47 [['b'], ['c']],
48 ],
49 key: 'key',
50 expected: null,
51 },
52 {
53 data: [{ key: 'd' }, { key: 'a' }, { key: 'b' }, { key: 'c' }],
54 orderArray: [
55 [['a'], ['b']],
56 [['b'], ['c']],
57 ],
58 key: 'key',
59 expected: null,
60 },
61 {
62 data: [{ key: 'd' }, { key: 'b' }, { key: 'a' }, { key: 'c' }],
63 orderArray: [
64 [['a'], ['b']],
65 [['b'], ['c']],
66 ],
67 key: 'key',
68 expected: [{ key: 'd' }, { key: 'a' }, { key: 'b' }, { key: 'c' }],
69 },
70 ] as const
71 test.each(testCases)(
72 '$data $orderArray $key $expected',
73 ({ data, orderArray, key, expected }) => {
74 const sortedData = sortDataByOrder(data, orderArray, key)
75 expect(sortedData).toEqual(expected)
76 },
77 )
78 })
79})