@@ -2,8 +2,8 @@ import FsProvider from '../../../../src/providers/generic/file/FsProvider';
2
2
import InMemoryFsProvider from '../stubs/providers/InMemory.FsProvider' ;
3
3
import {
4
4
buildConfigurationFileFromPath ,
5
- ConfigurationEntry , ConfigurationEntryDisplayType ,
6
- getSelectOptions
5
+ ConfigurationEntry , ConfigurationEntryDisplayType , ConfigurationFile ,
6
+ getSelectOptions , saveConfigurationFile
7
7
} from '../../../../src/utils/ConfigUtils' ;
8
8
import path from 'path' ;
9
9
@@ -237,3 +237,89 @@ describe('getSelectOptions', () => {
237
237
238
238
} ) ;
239
239
240
+ describe ( 'saveConfigurationFile' , ( ) => {
241
+
242
+ beforeAll ( ( ) => {
243
+ const fsProvider = new InMemoryFsProvider ( ) ;
244
+ FsProvider . provide ( ( ) => fsProvider ) ;
245
+ } ) ;
246
+
247
+ beforeEach ( ( ) => {
248
+ InMemoryFsProvider . clear ( ) ;
249
+ } ) ;
250
+
251
+ test ( 'saves' , async ( ) => {
252
+ const fileDirectory = path . join ( "config" , "saved" ) ;
253
+ const fileName = "configurationFileToSave.cfg" ;
254
+ const configurationFile : ConfigurationFile = {
255
+ filename : fileName ,
256
+ path : path . join ( fileDirectory , fileName ) ,
257
+ sections : [
258
+ {
259
+ sectionName : "First Section" ,
260
+ entries : [
261
+ {
262
+ entryName : "FirstSectionEntry" ,
263
+ value : "Saved value" ,
264
+ cachedValue : "Old value" ,
265
+ displayType : 'input' ,
266
+ commentLines : [ ] ,
267
+ }
268
+ ]
269
+ } ,
270
+ {
271
+ sectionName : "Second Section" ,
272
+ entries : [
273
+ {
274
+ entryName : "SecondSectionFirstEntry" ,
275
+ value : "First entry new value" ,
276
+ cachedValue : "First entry old value" ,
277
+ displayType : 'input' ,
278
+ commentLines : [
279
+ {
280
+ rawValue : '## First comment line' ,
281
+ displayValue : 'First comment line' ,
282
+ isDescription : true ,
283
+ } ,
284
+ {
285
+ rawValue : '# Metadata comment line' ,
286
+ displayValue : 'Metadata comment line' ,
287
+ isDescription : false ,
288
+ } ,
289
+ ] ,
290
+ } ,
291
+ {
292
+ entryName : "SecondSectionSecondEntry" ,
293
+ value : "Second entry new value" ,
294
+ cachedValue : "Second entry old value" ,
295
+ displayType : 'input' ,
296
+ commentLines : [ ] ,
297
+ }
298
+ ]
299
+ }
300
+ ]
301
+ }
302
+
303
+ await FsProvider . instance . mkdirs ( fileDirectory ) ;
304
+ await saveConfigurationFile ( configurationFile ) ;
305
+
306
+ const fileContent = ( await FsProvider . instance . readFile ( configurationFile . path ) ) . toString ( ) ;
307
+
308
+ expect ( fileContent ) . toEqual (
309
+ `[First Section]
310
+
311
+ FirstSectionEntry = Saved value
312
+
313
+ [Second Section]
314
+
315
+ ## First comment line
316
+ # Metadata comment line
317
+ SecondSectionFirstEntry = First entry new value
318
+
319
+ SecondSectionSecondEntry = Second entry new value
320
+
321
+ `
322
+ )
323
+ } )
324
+
325
+ } ) ;
0 commit comments