@@ -35,6 +35,8 @@ describe('PublicNoticeEditComponent', () => {
3535 let fixture : ComponentFixture < PublicNoticeEditComponent > ;
3636 let findOneMock : jest . Mock ;
3737 let findLatestMock : jest . Mock ;
38+ let createMock : jest . Mock ;
39+ let updateMock : jest . Mock ;
3840 let router : Router ;
3941
4042 const existingNotice = {
@@ -82,6 +84,8 @@ describe('PublicNoticeEditComponent', () => {
8284 beforeEach ( async ( ) => {
8385 findOneMock = jest . fn ( ) . mockReturnValue ( asyncOf ( existingNotice ) ) ;
8486 findLatestMock = jest . fn ( ) . mockReturnValue ( asyncOf ( clientLatestNotice ) ) ;
87+ createMock = jest . fn ( ) . mockReturnValue ( asyncOf ( { id : 101 } ) ) ;
88+ updateMock = jest . fn ( ) . mockReturnValue ( asyncOf ( { id : 55 } ) ) ;
8589
8690 await TestBed . configureTestingModule ( {
8791 imports : [ PublicNoticeEditComponent , NoopAnimationsModule ] ,
@@ -92,6 +96,8 @@ describe('PublicNoticeEditComponent', () => {
9296 useValue : {
9397 publicNoticeControllerFindOne : findOneMock ,
9498 publicNoticeControllerFindLatestPublicNotice : findLatestMock ,
99+ publicNoticeControllerCreate : createMock ,
100+ publicNoticeControllerUpdate : updateMock ,
95101 } ,
96102 } ,
97103 { provide : CognitoService , useValue : { getUser : ( ) => ( { isForestClient : true , isAuthorizedForClientId : ( ) => true } ) } } ,
@@ -165,13 +171,24 @@ describe('PublicNoticeEditComponent', () => {
165171 expect ( findOneMock ) . not . toHaveBeenCalled ( ) ;
166172 } ) ;
167173
168- it ( 'is treated as a new notice and renders an empty form' , ( ) => {
174+ it ( 'is treated as a new notice and renders an empty form with actions ' , ( ) => {
169175 expect ( component . isNewForm ) . toBe ( true ) ;
170176 expect ( component . isAddNewNotice ( ) ) . toBe ( true ) ;
171177 expect ( component . publicNoticeResponse ) . toBeNull ( ) ;
172178 expect ( component . formReady ( ) ) . toBe ( true ) ;
173179 expect ( component . publicNoticeFormGroup ) . toBeDefined ( ) ;
174180 expect ( fixture . nativeElement . querySelector ( 'form#publicNoticeForm' ) ) . not . toBeNull ( ) ;
181+ expect ( fixture . nativeElement . querySelector ( 'h1' ) . textContent ) . toContain ( 'New Online Public Notice' ) ;
182+ expect ( fixture . nativeElement . querySelector ( 'h1' ) . textContent ) . toContain ( 'FOM Number: 2' ) ;
183+ expect ( fixture . nativeElement . querySelector ( 'button[type="submit"]' ) ) . not . toBeNull ( ) ;
184+ } ) ;
185+
186+ it ( 'submits a new public notice on valid form submission and navigates back' , async ( ) => {
187+ const navSpy = jest . spyOn ( router , 'navigate' ) . mockResolvedValue ( true ) ;
188+ await component . onSubmit ( ) ;
189+ expect ( createMock ) . toHaveBeenCalledWith ( expect . objectContaining ( { projectId : 2 } ) ) ;
190+ expect ( updateMock ) . not . toHaveBeenCalled ( ) ;
191+ expect ( navSpy ) . toHaveBeenCalledWith ( [ '/a' , 2 ] ) ;
175192 } ) ;
176193 } ) ;
177194
0 commit comments