forked from 47ng/nuqs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuseQueryStates.cy.js
111 lines (99 loc) · 3.38 KB
/
useQueryStates.cy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/// <reference types="cypress" />
function runTest() {
cy.contains('#hydration-marker', 'hydrated').should('be.hidden')
cy.get('#json').should(
'have.text',
'{"string":null,"int":null,"float":null,"index":null,"bool":null}'
)
cy.get('#string').should('be.empty')
cy.get('#int').should('be.empty')
cy.get('#float').should('be.empty')
cy.get('#index').should('be.empty')
cy.get('#bool').should('be.empty')
cy.location('search').should('be.empty')
cy.contains('Set string').click()
cy.location('search').should('eq', '?string=Hello')
cy.get('#string').should('have.text', 'Hello')
cy.get('#json').should(
'have.text',
'{"string":"Hello","int":null,"float":null,"index":null,"bool":null}'
)
cy.contains('Set int').click()
cy.location('search').should('include', 'int=42')
cy.get('#int').should('have.text', '42')
cy.get('#json').should(
'have.text',
'{"string":"Hello","int":42,"float":null,"index":null,"bool":null}'
)
cy.contains('Set float').click()
cy.location('search').should('include', 'float=3.14159')
cy.get('#float').should('have.text', '3.14159')
cy.get('#json').should(
'have.text',
'{"string":"Hello","int":42,"float":3.14159,"index":null,"bool":null}'
)
cy.contains('Set index').click()
cy.location('search').should('include', 'index=9')
cy.get('#index').should('have.text', '8')
cy.get('#json').should(
'have.text',
'{"string":"Hello","int":42,"float":3.14159,"index":8,"bool":null}'
)
cy.contains('Toggle bool').click()
cy.location('search').should('include', 'bool=true')
cy.get('#bool').should('have.text', 'true')
cy.get('#json').should(
'have.text',
'{"string":"Hello","int":42,"float":3.14159,"index":8,"bool":true}'
)
cy.contains('Toggle bool').click()
cy.location('search').should('include', 'bool=false')
cy.get('#bool').should('have.text', 'false')
cy.get('#json').should(
'have.text',
'{"string":"Hello","int":42,"float":3.14159,"index":8,"bool":false}'
)
cy.get('#clear-string').click()
cy.location('search').should('not.include', 'string=Hello')
cy.get('#string').should('be.empty')
cy.get('#json').should(
'have.text',
'{"string":null,"int":42,"float":3.14159,"index":8,"bool":false}'
)
cy.get('#clear').click()
cy.location('search').should('not.include', 'string')
cy.location('search').should('not.include', 'int')
cy.location('search').should('not.include', 'float')
cy.location('search').should('not.include', 'index')
cy.location('search').should('not.include', 'bool')
cy.get('#json').should(
'have.text',
'{"string":null,"int":null,"float":null,"index":null,"bool":null}'
)
cy.get('#string').should('be.empty')
cy.get('#int').should('be.empty')
cy.get('#float').should('be.empty')
cy.get('#index').should('be.empty')
cy.get('#bool').should('be.empty')
cy.location('search').should('be.empty')
}
describe('useQueryStates (app router)', () => {
it('uses string by default', () => {
cy.visit('/app/useQueryStates')
runTest()
})
it('should work with dynamic routes', () => {
cy.visit('/app/useQueryStates/dynamic/route')
runTest()
})
})
describe('useQueryStates (pages router)', () => {
it('uses string by default', () => {
cy.visit('/pages/useQueryStates')
runTest()
})
it('should work with dynamic routes', () => {
cy.visit('/pages/useQueryStates/dynamic/route')
runTest()
})
})