@@ -381,4 +381,88 @@ describe("AddEditV2Component", () => {
381381 expect ( navigate ) . toHaveBeenCalledWith ( [ "/tabs/vault" ] ) ;
382382 } ) ;
383383 } ) ;
384+
385+ describe ( "reloadAddEditCipherData" , ( ) => {
386+ beforeEach ( fakeAsync ( ( ) => {
387+ addEditCipherInfo$ . next ( {
388+ cipher : {
389+ name : "InitialName" ,
390+ type : CipherType . Login ,
391+ login : {
392+ password : "initialPassword" ,
393+ username : "initialUsername" ,
394+ uris : [ { uri : "https://initial.com" } ] ,
395+ } ,
396+ } ,
397+ } as AddEditCipherInfo ) ;
398+ queryParams$ . next ( { } ) ;
399+ tick ( ) ;
400+
401+ cipherServiceMock . setAddEditCipherInfo . mockClear ( ) ;
402+ } ) ) ;
403+
404+ it ( "replaces all initialValues with new data, clearing stale fields" , fakeAsync ( ( ) => {
405+ const newCipherInfo = {
406+ cipher : {
407+ name : "UpdatedName" ,
408+ type : CipherType . Login ,
409+ login : {
410+ password : "updatedPassword" ,
411+ uris : [ { uri : "https://updated.com" } ] ,
412+ } ,
413+ } ,
414+ } as AddEditCipherInfo ;
415+
416+ addEditCipherInfo$ . next ( newCipherInfo ) ;
417+
418+ const messageListener = component [ "messageListener" ] ;
419+ messageListener ( { command : "reloadAddEditCipherData" } ) ;
420+ tick ( ) ;
421+
422+ expect ( component . config . initialValues ) . toEqual ( {
423+ name : "UpdatedName" ,
424+ password : "updatedPassword" ,
425+ loginUri : "https://updated.com" ,
426+ } as OptionalInitialValues ) ;
427+
428+ expect ( cipherServiceMock . setAddEditCipherInfo ) . toHaveBeenCalledWith ( null , "UserId" ) ;
429+ } ) ) ;
430+
431+ it ( "does not reload data if config is not set" , fakeAsync ( ( ) => {
432+ component . config = null ;
433+
434+ const messageListener = component [ "messageListener" ] ;
435+ messageListener ( { command : "reloadAddEditCipherData" } ) ;
436+ tick ( ) ;
437+
438+ expect ( cipherServiceMock . setAddEditCipherInfo ) . not . toHaveBeenCalled ( ) ;
439+ } ) ) ;
440+
441+ it ( "does not reload data if latestCipherInfo is null" , fakeAsync ( ( ) => {
442+ addEditCipherInfo$ . next ( null ) ;
443+
444+ const messageListener = component [ "messageListener" ] ;
445+ messageListener ( { command : "reloadAddEditCipherData" } ) ;
446+ tick ( ) ;
447+
448+ expect ( component . config . initialValues ) . toEqual ( {
449+ name : "InitialName" ,
450+ password : "initialPassword" ,
451+ username : "initialUsername" ,
452+ loginUri : "https://initial.com" ,
453+ } as OptionalInitialValues ) ;
454+
455+ expect ( cipherServiceMock . setAddEditCipherInfo ) . not . toHaveBeenCalled ( ) ;
456+ } ) ) ;
457+
458+ it ( "ignores messages with different commands" , fakeAsync ( ( ) => {
459+ const initialValues = component . config . initialValues ;
460+
461+ const messageListener = component [ "messageListener" ] ;
462+ messageListener ( { command : "someOtherCommand" } ) ;
463+ tick ( ) ;
464+
465+ expect ( component . config . initialValues ) . toBe ( initialValues ) ;
466+ } ) ) ;
467+ } ) ;
384468} ) ;
0 commit comments