1- import uiReducer from '../src/client/reducers/ui' ;
1+ import reducer , {
2+ setSidebarActiveTab ,
3+ setWorkspaceActiveTab ,
4+ setResponsePaneActiveTab ,
5+ toggleDarkMode ,
6+ } from '../src/client/features/ui/uiSlice.ts' ;
27
38describe ( 'UI Reducer' , ( ) => {
49 let state ;
510
611 beforeEach ( ( ) => {
712 state = {
8- composerDisplay : 'Request' ,
13+ isDark : false ,
914 sidebarActiveTab : 'composer' ,
1015 workspaceActiveTab : 'workspace' ,
1116 responsePaneActiveTab : 'events' ,
@@ -14,22 +19,57 @@ describe('UI Reducer', () => {
1419
1520 describe ( 'default state' , ( ) => {
1621 it ( 'should return a default state when given an undefined input' , ( ) => {
17- expect ( uiReducer ( undefined , { type : undefined } ) ) . toEqual ( state ) ;
22+ expect ( reducer ( undefined , { type : undefined } ) ) . toEqual ( state ) ;
1823 } ) ;
1924 it ( 'should return default state with unrecognized action types' , ( ) => {
20- expect ( uiReducer ( undefined , { type : 'BAD_TYPE' } ) ) . toEqual ( state ) ;
25+ expect ( reducer ( undefined , { type : 'BAD_TYPE' } ) ) . toEqual ( state ) ;
26+ } ) ;
27+ } ) ;
28+
29+ describe ( 'Set sidebar active tab' , ( ) => {
30+ const action = {
31+ payload : 'the active sidebar tab is this one!' ,
32+ } ;
33+
34+ it ( 'sets the sidebar active tab' , ( ) => {
35+ const { sidebarActiveTab } = reducer ( state , setSidebarActiveTab ( action . payload ) ) ;
36+ expect ( sidebarActiveTab ) . toEqual ( action . payload ) ;
37+ } ) ;
38+ } ) ;
39+
40+ describe ( 'Set workspace active tab' , ( ) => {
41+ const action = {
42+ payload : 'the active workspace tab is this one!' ,
43+ } ;
44+
45+ it ( 'sets the workspace active tab' , ( ) => {
46+ const { workspaceActiveTab } = reducer ( state , setWorkspaceActiveTab ( action . payload ) ) ;
47+ expect ( workspaceActiveTab ) . toEqual ( action . payload ) ;
2148 } ) ;
2249 } ) ;
2350
24- describe ( 'should handle SET_COMPOSER_DISPLAY ' , ( ) => {
51+ describe ( 'Set response pane active tab ' , ( ) => {
2552 const action = {
26- type : 'SET_COMPOSER_DISPLAY' ,
27- payload : 'warning' ,
53+ payload : 'the active response pane tab is this one!' ,
2854 } ;
2955
30- it ( 'should update the composerDisplay ' , ( ) => {
31- const { composerDisplay } = uiReducer ( state , action ) ;
32- expect ( composerDisplay ) . toEqual ( action . payload ) ;
56+ it ( 'sets the response pane active tab ' , ( ) => {
57+ const { responsePaneActiveTab } = reducer ( state , setResponsePaneActiveTab ( action . payload ) ) ;
58+ expect ( responsePaneActiveTab ) . toEqual ( action . payload ) ;
3359 } ) ;
3460 } ) ;
61+
62+ describe ( 'Toggle dark mode' , ( ) => {
63+ const action = {
64+ payload : true ,
65+ } ;
66+
67+ it ( 'Toggles dark mode' , ( ) => {
68+ const newState = reducer ( state , toggleDarkMode ( false ) ) ;
69+ expect ( newState . isDark ) . toEqual ( false ) ;
70+ const { isDark } = reducer ( newState , toggleDarkMode ( action . payload ) ) ;
71+ expect ( isDark ) . toEqual ( true ) ;
72+ } ) ;
73+ } ) ;
74+
3575} ) ;
0 commit comments