diff --git a/angular.json b/angular.json index 8454122..3d6ce39 100644 --- a/angular.json +++ b/angular.json @@ -159,4 +159,4 @@ "@angular-eslint/schematics" ] } -} +} \ No newline at end of file diff --git a/karma.conf.js b/karma.conf.js index d05dca4..0ee00ad 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -50,4 +50,4 @@ module.exports = function (config) { singleRun: false, restartOnFileChange: true }); -}; +}; \ No newline at end of file diff --git a/src/app/screen/screen.component.spec.ts b/src/app/screen/screen.component.spec.ts index 30af2de..fab7612 100644 --- a/src/app/screen/screen.component.spec.ts +++ b/src/app/screen/screen.component.spec.ts @@ -33,8 +33,8 @@ import { ModalService, PlaceholderService } from 'carbon-components-angular'; import { IJSFunctionService } from 'src/common/js-functions/ijs-functions.service'; import { JSMethodsService } from 'src/common/js-functions/js-methods.service'; import { KeyboardMappingService } from '../services/keyboard-mapping.service'; - - + + describe('ScreenComponent', () => { let component: ScreenComponent; let fixture: ComponentFixture<ScreenComponent>; @@ -99,7 +99,6 @@ beforeEach(async () => { screenProcessorService = TestBed.inject(ScreenProcessorService); screenLockerService = TestBed.inject(ScreenLockerService); logger = TestBed.inject(NGXLogger); - spyOn(navigationService, 'setSendableField').and.callThrough(); spyOn(screenService, 'getScreen').and.returnValue(of()); spyOn(screenHolderService, 'setRuntimeScreen').and.callThrough(); @@ -107,6 +106,33 @@ beforeEach(async () => { spyOn(screenProcessorService, 'processTable').and.callThrough(); spyOn(screenLockerService, 'setLocked').and.callThrough(); }); + + it('should call getScreen when ngOnInit is called', () => { + component.ngOnInit(); + expect(screenService.getScreen).toHaveBeenCalled(); + }); + + + it('should call postGetScreen when screenId is different from current screenId & newScreenId', () => { + const incomingScreen: GetScreenResponse = { + screenId: 2, + name: 'newScreen', + screenSize: {}, + cursor: { position: { row: 1, column: 1 } }, + fields: [], + transformations: [] + }; + + component.m_screen = { screenId: 1 } as GetScreenResponse; + spyOn(component as any, 'postGetScreen'); + + // Manually trigger the BehaviorSubject + navigationService.screenObjectUpdated = new BehaviorSubject<GetScreenResponse>(null); + component.ngOnInit(); + navigationService.screenObjectUpdated.next(incomingScreen); + + expect((component as any).postGetScreen).toHaveBeenCalledWith(incomingScreen); + }); it('should not call setSendableField when ignored elements are processed', () => { const event = { @@ -229,3 +255,4 @@ beforeEach(async () => { }); }); + \ No newline at end of file diff --git a/src/app/screen/screen.component.ts b/src/app/screen/screen.component.ts index b06fcea..41adcce 100644 --- a/src/app/screen/screen.component.ts +++ b/src/app/screen/screen.component.ts @@ -137,10 +137,11 @@ export class ScreenComponent implements OnInit, OnChanges, AfterViewInit, OnDest } this.screenObjectUpdatedSubscription = this.navigationService.screenObjectUpdated.subscribe(newScreen => { - if (newScreen) { + if (newScreen) { + if(newScreen.screenId !== this.m_screen.screenId){ + this.postGetScreen (newScreen); + } this.navigationService.screenObjectUpdated.next(null); - this.postGetScreen (newScreen); - //this.screenHolderService.setRawScreenData(newScreen) this.getRawScreenData() } }); @@ -172,7 +173,7 @@ export class ScreenComponent implements OnInit, OnChanges, AfterViewInit, OnDest }); } - getRawScreenData(): void { + public getRawScreenData(): void { const req = new GetScreenRequest(); this.userExitsEventThrower.firePreGetScreen(req); this.getScreenSubscription = this.screenService.getScreen(this.storageService.getAuthToken(), req).subscribe( diff --git a/src/test.ts b/src/test.ts index 5fbfc06..6e29c28 100644 --- a/src/test.ts +++ b/src/test.ts @@ -27,4 +27,4 @@ import 'zone.js/testing' getTestBed().initTestEnvironment( BrowserDynamicTestingModule, platformBrowserDynamicTesting() -); +); \ No newline at end of file