@@ -5,52 +5,56 @@ import { getStateFromLocalStorage } from "./devtools-context";
55
66describe ( 'getStateFromLocalStorage' , ( ) => {
77 beforeEach ( ( ) => {
8- localStorage . clear ( ) ;
9- } ) ;
8+ localStorage . clear ( )
9+ } )
1010 it ( 'should return undefined when no data in localStorage' , ( ) => {
11- const state = getStateFromLocalStorage ( ) ;
12- expect ( state ) . toEqual ( undefined ) ;
13- } ) ;
11+ const state = getStateFromLocalStorage ( )
12+ expect ( state ) . toEqual ( undefined )
13+ } )
1414 it ( 'should return parsed state from localStorage and not remove valid plugins' , ( ) => {
1515 const mockState = {
1616 activePlugins : [ 'plugin1' ] ,
1717 settings : {
1818 theme : 'dark' ,
1919 } ,
20- } ;
21- localStorage . setItem ( TANSTACK_DEVTOOLS_STATE , JSON . stringify ( mockState ) ) ;
22- const state = getStateFromLocalStorage ( [ {
23- id : 'plugin1' , render : ( ) => { } , name : 'Plugin 1'
24- } ] ) ;
25- expect ( state ) . toEqual ( mockState ) ;
26- } ) ;
20+ }
21+ localStorage . setItem ( TANSTACK_DEVTOOLS_STATE , JSON . stringify ( mockState ) )
22+ const state = getStateFromLocalStorage ( [
23+ {
24+ id : 'plugin1' ,
25+ render : ( ) => { } ,
26+ name : 'Plugin 1' ,
27+ } ,
28+ ] )
29+ expect ( state ) . toEqual ( mockState )
30+ } )
2731 it ( 'should filter out inactive plugins' , ( ) => {
2832 const mockState = {
2933 activePlugins : [ 'plugin1' , 'plugin2' ] ,
3034 settings : {
3135 theme : 'dark' ,
3236 } ,
33- } ;
34- localStorage . setItem ( TANSTACK_DEVTOOLS_STATE , JSON . stringify ( mockState ) ) ;
35- const plugins = [ { id : 'plugin1' , render : ( ) => { } , name : 'Plugin 1' } ] ;
36- const state = getStateFromLocalStorage ( plugins ) ;
37- expect ( state ?. activePlugins ) . toEqual ( [ 'plugin1' ] ) ;
38- } ) ;
37+ }
38+ localStorage . setItem ( TANSTACK_DEVTOOLS_STATE , JSON . stringify ( mockState ) )
39+ const plugins = [ { id : 'plugin1' , render : ( ) => { } , name : 'Plugin 1' } ]
40+ const state = getStateFromLocalStorage ( plugins )
41+ expect ( state ?. activePlugins ) . toEqual ( [ 'plugin1' ] )
42+ } )
3943 it ( 'should return empty plugin state if all active plugins are invalid' , ( ) => {
4044 const mockState = {
4145 activePlugins : [ 'plugin1' , 'plugin2' ] ,
4246 settings : {
4347 theme : 'dark' ,
4448 } ,
45- } ;
46- localStorage . setItem ( TANSTACK_DEVTOOLS_STATE , JSON . stringify ( mockState ) ) ;
47- const plugins = [ { id : 'plugin3' , render : ( ) => { } , name : 'Plugin 3' } ] ;
48- const state = getStateFromLocalStorage ( plugins ) ;
49- expect ( state ?. activePlugins ) . toEqual ( [ ] ) ;
50- } ) ;
49+ }
50+ localStorage . setItem ( TANSTACK_DEVTOOLS_STATE , JSON . stringify ( mockState ) )
51+ const plugins = [ { id : 'plugin3' , render : ( ) => { } , name : 'Plugin 3' } ]
52+ const state = getStateFromLocalStorage ( plugins )
53+ expect ( state ?. activePlugins ) . toEqual ( [ ] )
54+ } )
5155 it ( 'should handle invalid JSON in localStorage gracefully' , ( ) => {
52- localStorage . setItem ( TANSTACK_DEVTOOLS_STATE , " invalid json" ) ;
53- const state = getStateFromLocalStorage ( ) ;
54- expect ( state ) . toEqual ( undefined ) ;
55- } ) ;
56- } ) ;
56+ localStorage . setItem ( TANSTACK_DEVTOOLS_STATE , ' invalid json' )
57+ const state = getStateFromLocalStorage ( )
58+ expect ( state ) . toEqual ( undefined )
59+ } )
60+ } )
0 commit comments