@@ -16,58 +16,58 @@ describe('useContextKeyStore', () => {
16
16
describe ( 'setContextKey' , ( ) => {
17
17
it ( 'sets a top-level key' , ( ) => {
18
18
const store = useContextKeyStore ( )
19
- store . setContextKey ( 'foo' , 'bar' )
20
- expect ( store . contextKeys ) . toEqual ( { foo : 'bar' } )
19
+ store . setContextKey ( 'foo' , true )
20
+ expect ( store . contextKeys ) . toEqual ( { foo : true } )
21
21
} )
22
22
23
23
it ( 'sets a nested key' , ( ) => {
24
24
const store = useContextKeyStore ( )
25
- store . setContextKey ( 'a.b.c' , 123 )
26
- expect ( store . contextKeys ) . toEqual ( { a : { b : { c : 123 } } } )
25
+ store . setContextKey ( 'a.b.c' , true )
26
+ expect ( store . contextKeys ) . toEqual ( { a : { b : { c : true } } } )
27
27
} )
28
28
29
29
it ( 'overwrites an existing key' , ( ) => {
30
30
const store = useContextKeyStore ( )
31
- store . setContextKey ( 'foo' , 'bar' )
32
- store . setContextKey ( 'foo' , 'baz' )
33
- expect ( store . contextKeys ) . toEqual ( { foo : 'baz' } )
31
+ store . setContextKey ( 'foo' , true )
32
+ store . setContextKey ( 'foo' , false )
33
+ expect ( store . contextKeys ) . toEqual ( { foo : false } )
34
34
} )
35
35
36
36
it ( 'overwrites an existing nested key' , ( ) => {
37
37
const store = useContextKeyStore ( )
38
- store . setContextKey ( 'a.b.c' , 123 )
39
- store . setContextKey ( 'a.b.c' , 456 )
40
- expect ( store . contextKeys ) . toEqual ( { a : { b : { c : 456 } } } )
38
+ store . setContextKey ( 'a.b.c' , true )
39
+ store . setContextKey ( 'a.b.c' , false )
40
+ expect ( store . contextKeys ) . toEqual ( { a : { b : { c : false } } } )
41
41
} )
42
42
43
43
it ( 'creates intermediate objects when setting nested keys' , ( ) => {
44
44
const store = useContextKeyStore ( )
45
- store . setContextKey ( 'x.y' , 'level2' )
46
- store . setContextKey ( 'x.z' , 'another level2' )
45
+ store . setContextKey ( 'x.y' , true )
46
+ store . setContextKey ( 'x.z' , false )
47
47
expect ( store . contextKeys ) . toEqual ( {
48
- x : { y : 'level2' , z : 'another level2' }
48
+ x : { y : true , z : false }
49
49
} )
50
50
} )
51
51
52
52
it ( 'handles overwriting a non-object with an object for nested keys' , ( ) => {
53
53
const store = useContextKeyStore ( )
54
- store . setContextKey ( 'a' , 1 )
55
- store . setContextKey ( 'a.b' , 'nested' )
56
- expect ( store . contextKeys ) . toEqual ( { a : { b : 'nested' } } )
54
+ store . setContextKey ( 'a' , true )
55
+ store . setContextKey ( 'a.b' , false )
56
+ expect ( store . contextKeys ) . toEqual ( { a : { b : false } } )
57
57
} )
58
58
} )
59
59
60
60
describe ( 'getContextKey' , ( ) => {
61
61
it ( 'gets a top-level key' , ( ) => {
62
62
const store = useContextKeyStore ( )
63
- store . setContextKey ( 'foo' , 'bar' )
64
- expect ( store . getContextKey ( 'foo' ) ) . toBe ( 'bar' )
63
+ store . setContextKey ( 'foo' , true )
64
+ expect ( store . getContextKey ( 'foo' ) ) . toBe ( true )
65
65
} )
66
66
67
67
it ( 'gets a nested key' , ( ) => {
68
68
const store = useContextKeyStore ( )
69
- store . setContextKey ( 'a.b.c' , 123 )
70
- expect ( store . getContextKey ( 'a.b.c' ) ) . toBe ( 123 )
69
+ store . setContextKey ( 'a.b.c' , true )
70
+ expect ( store . getContextKey ( 'a.b.c' ) ) . toBe ( true )
71
71
} )
72
72
73
73
it ( 'returns undefined for a non-existent top-level key' , ( ) => {
@@ -77,53 +77,53 @@ describe('useContextKeyStore', () => {
77
77
78
78
it ( 'returns undefined for a non-existent nested key' , ( ) => {
79
79
const store = useContextKeyStore ( )
80
- store . setContextKey ( 'a.b' , { } )
80
+ store . setContextKey ( 'a.b' , true )
81
81
expect ( store . getContextKey ( 'a.b.c' ) ) . toBeUndefined ( )
82
82
} )
83
83
84
84
it ( 'returns undefined when path segment does not exist' , ( ) => {
85
85
const store = useContextKeyStore ( )
86
- store . setContextKey ( 'a.b' , 1 )
86
+ store . setContextKey ( 'a.b' , true )
87
87
expect ( store . getContextKey ( 'a.x.c' ) ) . toBeUndefined ( )
88
88
} )
89
89
} )
90
90
91
91
describe ( 'removeContextKey' , ( ) => {
92
92
it ( 'removes a top-level key' , ( ) => {
93
93
const store = useContextKeyStore ( )
94
- store . setContextKey ( 'foo' , 'bar' )
95
- store . setContextKey ( 'baz' , 'qux' )
94
+ store . setContextKey ( 'foo' , true )
95
+ store . setContextKey ( 'baz' , false )
96
96
store . removeContextKey ( 'foo' )
97
- expect ( store . contextKeys ) . toEqual ( { baz : 'qux' } )
97
+ expect ( store . contextKeys ) . toEqual ( { baz : false } )
98
98
} )
99
99
100
100
it ( 'removes a nested key' , ( ) => {
101
101
const store = useContextKeyStore ( )
102
- store . setContextKey ( 'a.b.c' , 123 )
103
- store . setContextKey ( 'a.b.d' , 456 )
102
+ store . setContextKey ( 'a.b.c' , true )
103
+ store . setContextKey ( 'a.b.d' , false )
104
104
store . removeContextKey ( 'a.b.c' )
105
- expect ( store . contextKeys ) . toEqual ( { a : { b : { d : 456 } } } )
105
+ expect ( store . contextKeys ) . toEqual ( { a : { b : { d : false } } } )
106
106
} )
107
107
108
108
it ( 'prunes empty ancestor objects when removing a nested key' , ( ) => {
109
109
const store = useContextKeyStore ( )
110
- store . setContextKey ( 'a.b.c' , 123 )
110
+ store . setContextKey ( 'a.b.c' , true )
111
111
store . removeContextKey ( 'a.b.c' )
112
- expect ( store . contextKeys ) . toEqual ( { } ) // a and a.b should be pruned
112
+ expect ( store . contextKeys ) . toEqual ( { } )
113
113
} )
114
114
115
115
it ( 'prunes only up to the non-empty ancestor' , ( ) => {
116
116
const store = useContextKeyStore ( )
117
- store . setContextKey ( 'a.b.c' , 123 )
118
- store . setContextKey ( 'a.x' , 456 ) // Add another key under 'a'
117
+ store . setContextKey ( 'a.b.c' , true )
118
+ store . setContextKey ( 'a.x' , false )
119
119
store . removeContextKey ( 'a.b.c' )
120
- expect ( store . contextKeys ) . toEqual ( { a : { x : 456 } } ) // a.b pruned, but a remains
120
+ expect ( store . contextKeys ) . toEqual ( { a : { x : false } } )
121
121
} )
122
122
123
123
it ( 'does nothing if the key does not exist' , ( ) => {
124
124
const store = useContextKeyStore ( )
125
- store . setContextKey ( 'a.b' , 1 )
126
- const initialState = JSON . parse ( JSON . stringify ( store . contextKeys ) ) // Deep clone
125
+ store . setContextKey ( 'a.b' , true )
126
+ const initialState = JSON . parse ( JSON . stringify ( store . contextKeys ) )
127
127
store . removeContextKey ( 'nonexistent' )
128
128
expect ( store . contextKeys ) . toEqual ( initialState )
129
129
store . removeContextKey ( 'a.c' )
@@ -134,7 +134,7 @@ describe('useContextKeyStore', () => {
134
134
135
135
it ( 'does nothing if the path is empty' , ( ) => {
136
136
const store = useContextKeyStore ( )
137
- store . setContextKey ( 'a' , 1 )
137
+ store . setContextKey ( 'a' , true )
138
138
const initialState = JSON . parse ( JSON . stringify ( store . contextKeys ) )
139
139
store . removeContextKey ( '' )
140
140
expect ( store . contextKeys ) . toEqual ( initialState )
@@ -144,8 +144,8 @@ describe('useContextKeyStore', () => {
144
144
describe ( 'clearAllContextKeys' , ( ) => {
145
145
it ( 'clears all keys' , ( ) => {
146
146
const store = useContextKeyStore ( )
147
- store . setContextKey ( 'a' , 1 )
148
- store . setContextKey ( 'b.c' , 2 )
147
+ store . setContextKey ( 'a' , true )
148
+ store . setContextKey ( 'b.c' , false )
149
149
store . clearAllContextKeys ( )
150
150
expect ( store . contextKeys ) . toEqual ( { } )
151
151
} )
0 commit comments