77 updateDashboardWidget ,
88} from './dashboards' ;
99import { defaultDashboard } from './defaultDashboard' ;
10+ import { DashboardLayout } from '@irdashies/types' ;
1011
1112const mockReadData = vi . hoisted ( ( ) => vi . fn ( ) ) ;
1213const mockWriteData = vi . hoisted ( ( ) => vi . fn ( ) ) ;
@@ -84,7 +85,7 @@ describe('dashboards', () => {
8485
8586 describe ( 'saveDashboard' , ( ) => {
8687 it ( 'should save a new dashboard' , ( ) => {
87- const newDashboard = { widgets : [ ] } ;
88+ const newDashboard : DashboardLayout = { widgets : [ ] , generalSettings : { fontSize : 'sm' } } ;
8889 mockReadData . mockReturnValue ( null ) ;
8990
9091 saveDashboard ( 'newDashboard' , newDashboard ) ;
@@ -96,7 +97,7 @@ describe('dashboards', () => {
9697
9798 it ( 'should update an existing dashboard' , ( ) => {
9899 const existingDashboards = { default : defaultDashboard } ;
99- const updatedDashboard = { widgets : [ ] } ;
100+ const updatedDashboard : DashboardLayout = { widgets : [ ] , generalSettings : { fontSize : 'lg' } } ;
100101 mockReadData . mockReturnValue ( existingDashboards ) ;
101102
102103 saveDashboard ( 'default' , updatedDashboard ) ;
@@ -133,15 +134,15 @@ describe('dashboards', () => {
133134 enabled : false ,
134135 layout : { x : 100 , y : 100 , width : 600 , height : 120 } ,
135136 } ;
136- const existingDashboard = { widgets : [ existingWidget ] } ;
137+ const existingDashboard : DashboardLayout = { widgets : [ existingWidget ] , generalSettings : { fontSize : 'sm' } } ;
137138 mockReadData . mockReturnValue ( {
138139 default : existingDashboard ,
139140 } ) ;
140141
141142 updateDashboardWidget ( updatedWidget ) ;
142143
143144 expect ( mockWriteData ) . toHaveBeenCalledWith ( 'dashboards' , {
144- default : { widgets : [ updatedWidget ] } ,
145+ default : { widgets : [ updatedWidget ] , generalSettings : { fontSize : 'sm' } } ,
145146 } ) ;
146147 } ) ;
147148
@@ -156,15 +157,15 @@ describe('dashboards', () => {
156157 enabled : true ,
157158 layout : { x : 100 , y : 100 , width : 600 , height : 120 } ,
158159 } ;
159- const existingDashboard = { widgets : [ existingWidget ] } ;
160+ const existingDashboard : DashboardLayout = { widgets : [ existingWidget ] , generalSettings : { fontSize : 'sm' } } ;
160161 mockReadData . mockReturnValue ( {
161162 custom : existingDashboard ,
162163 } ) ;
163164
164165 updateDashboardWidget ( updatedWidget , 'custom' ) ;
165166
166167 expect ( mockWriteData ) . toHaveBeenCalledWith ( 'dashboards' , {
167- custom : { widgets : [ updatedWidget ] } ,
168+ custom : { widgets : [ updatedWidget ] , generalSettings : { fontSize : 'sm' } } ,
168169 } ) ;
169170 } ) ;
170171
@@ -174,7 +175,7 @@ describe('dashboards', () => {
174175 enabled : true ,
175176 layout : { x : 100 , y : 100 , width : 600 , height : 120 } ,
176177 } ;
177- const existingDashboard = { widgets : [ ] } ;
178+ const existingDashboard : DashboardLayout = { widgets : [ ] , generalSettings : { fontSize : 'sm' } } ;
178179 mockReadData . mockReturnValue ( {
179180 default : existingDashboard ,
180181 } ) ;
@@ -209,6 +210,7 @@ describe('dashboards', () => {
209210
210211 it ( 'should add missing widgets to the default dashboard if some widgets are missing' , ( ) => {
211212 const incompleteDashboard = {
213+ generalSettings : { fontSize : 'sm' } ,
212214 widgets : defaultDashboard . widgets . slice ( 0 , 1 ) ,
213215 } ;
214216 mockReadData . mockReturnValue ( {
@@ -235,4 +237,28 @@ describe('dashboards', () => {
235237 expect ( mockWriteData ) . not . toHaveBeenCalled ( ) ;
236238 } ) ;
237239 } ) ;
240+
241+ describe ( 'generalSettings' , ( ) => {
242+ it ( 'should add general settings from the default dashboard if none exist' , ( ) => {
243+ const dashboard : DashboardLayout = { widgets : [ ] } ;
244+ mockReadData . mockReturnValue ( {
245+ default : dashboard ,
246+ } ) ;
247+
248+ const updatedDashboard = getOrCreateDefaultDashboard ( ) ;
249+
250+ expect ( updatedDashboard . generalSettings ) . toEqual ( { fontSize : 'sm' } ) ;
251+ } ) ;
252+
253+ it ( 'should preserve general settings from the existing dashboard' , ( ) => {
254+ const dashboard : DashboardLayout = { widgets : [ ] , generalSettings : { fontSize : 'lg' } } ;
255+ mockReadData . mockReturnValue ( {
256+ default : dashboard ,
257+ } ) ;
258+
259+ const updatedDashboard = getOrCreateDefaultDashboard ( ) ;
260+
261+ expect ( updatedDashboard . generalSettings ) . toEqual ( { fontSize : 'lg' } ) ;
262+ } ) ;
263+ } ) ;
238264} ) ;
0 commit comments