diff --git a/package-lock.json b/package-lock.json index 60ec72fe..e9fbadce 100644 --- a/package-lock.json +++ b/package-lock.json @@ -47,7 +47,7 @@ "zone.js": "~0.15.1" }, "peerDependencies": { - "@device-management-toolkit/ui-toolkit": "^3.3.3", + "@device-management-toolkit/ui-toolkit": "^3.3.4", "@xterm/xterm": "^5.5.0" } }, @@ -1243,9 +1243,9 @@ } }, "node_modules/@device-management-toolkit/ui-toolkit": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/@device-management-toolkit/ui-toolkit/-/ui-toolkit-3.3.3.tgz", - "integrity": "sha512-kJPRh+Dklqc/cFScFD48lRL8v4qGdI4wXWpRpbu0WXFJxYz8cFUKIRmgQILkwheLt8W918ShtmcWebIAgrM1ag==", + "version": "3.3.4", + "resolved": "https://registry.npmjs.org/@device-management-toolkit/ui-toolkit/-/ui-toolkit-3.3.4.tgz", + "integrity": "sha512-R6VYpf1j+W48j80JWFEwPB5REa9cZz/CRXQMrS2QZepQ/EjT1/9lpr5T1uhMcPmcl2CWVpr63H94mHBH5HTNow==", "license": "Apache-2.0", "peer": true, "dependencies": { diff --git a/package.json b/package.json index ada0c5f2..386d4472 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "access": "public" }, "peerDependencies": { - "@device-management-toolkit/ui-toolkit": "^3.3.3", + "@device-management-toolkit/ui-toolkit": "^3.3.4", "@xterm/xterm": "^5.5.0" }, "devDependencies": { diff --git a/sol/src/sol.component.spec.ts b/sol/src/sol.component.spec.ts index 0d0c7996..71d05b45 100644 --- a/sol/src/sol.component.spec.ts +++ b/sol/src/sol.component.spec.ts @@ -25,29 +25,31 @@ describe('SolComponent', () => { const setup = (): void => { fixture = TestBed.createComponent(SOLComponent) component = fixture.componentInstance - // Set deviceConnection to false first to prevent immediate effect trigger + // Set inputs first + fixture.componentRef.setInput('mpsServer', 'wss://localhost') + fixture.componentRef.setInput('authToken', 'testToken') + fixture.componentRef.setInput('deviceId', 'testDevice') fixture.componentRef.setInput('deviceConnection', false) - fixture.componentRef.setInput('mpsServer', '') - fixture.componentRef.setInput('authToken', '') - fixture.componentRef.setInput('deviceId', '') fixture.detectChanges() - // Now enable connection to trigger init + // Now enable connection to trigger instantiate and start fixture.componentRef.setInput('deviceConnection', true) fixture.detectChanges() } - const asyncSetup = fakeAsync(() => { + const asyncSetup = (): void => { fixture = TestBed.createComponent(SOLComponent) component = fixture.componentInstance fixture.componentRef.setInput('mpsServer', 'wss://localhost') fixture.componentRef.setInput('authToken', 'authToken') - fixture.componentRef.setInput('deviceId', '') - fixture.componentRef.setInput('deviceConnection', true) // Enable connection to trigger init - tick(4500) + fixture.componentRef.setInput('deviceId', 'testDevice') + fixture.componentRef.setInput('deviceConnection', false) fixture.detectChanges() - flush() - }) + + // Enable connection to trigger instantiate and start + fixture.componentRef.setInput('deviceConnection', true) + fixture.detectChanges() + } it('should create', () => { setup() @@ -111,11 +113,41 @@ describe('SolComponent', () => { expect(component.terminal.TermSendKeys).toHaveBeenCalled() }) - it('should autoconnect on page load', () => { + it('should instantiate redirector when deviceConnection becomes true', () => { asyncSetup() - spyOn(component.redirector, 'start') expect(component.redirector).not.toBeNull() expect(component.mpsServer()).toEqual('wss://localhost') expect(component.authToken()).toEqual('authToken') + expect(component.deviceId()).toEqual('testDevice') + }) + + it('should call startSol when deviceConnection becomes true', () => { + fixture = TestBed.createComponent(SOLComponent) + component = fixture.componentInstance + fixture.componentRef.setInput('mpsServer', 'wss://localhost') + fixture.componentRef.setInput('authToken', 'testToken') + fixture.componentRef.setInput('deviceId', 'testDevice') + fixture.componentRef.setInput('deviceConnection', false) + fixture.detectChanges() + + spyOn(component, 'startSol') + + // Enable connection to trigger effect + fixture.componentRef.setInput('deviceConnection', true) + fixture.detectChanges() + + expect(component.startSol).toHaveBeenCalled() + }) + + it('should call stopSol when deviceConnection becomes false', () => { + setup() // This sets deviceConnection to true and creates redirector + + spyOn(component, 'stopSol') + + // Disable connection to trigger effect + fixture.componentRef.setInput('deviceConnection', false) + fixture.detectChanges() + + expect(component.stopSol).toHaveBeenCalled() }) }) diff --git a/sol/src/sol.component.ts b/sol/src/sol.component.ts index c6816bea..4d41e088 100644 --- a/sol/src/sol.component.ts +++ b/sol/src/sol.component.ts @@ -31,7 +31,7 @@ import { TerminalComponent } from './terminal/terminal.component' encapsulation: ViewEncapsulation.None, imports: [TerminalComponent] }) -export class SOLComponent implements OnDestroy, AfterViewInit { +export class SOLComponent implements OnDestroy { private readonly destroyRef = inject(DestroyRef) terminal: AmtTerminal @@ -53,25 +53,15 @@ export class SOLComponent implements OnDestroy, AfterViewInit { const connected = this.deviceConnection() if (connected) { if (this.redirector == null) { - this.init() + this.instantiate() } - } else { + this.startSol() + } else if (this.redirector != null) { this.stopSol() } }) } - ngAfterViewInit(): void { - this.init() - } - - init(): void { - this.instantiate() - setTimeout(() => { - this.startSol() - }, 4000) - } - instantiate(): void { this.terminal = new AmtTerminal() this.dataProcessor = new TerminalDataProcessor(this.terminal) @@ -121,7 +111,7 @@ export class SOLComponent implements OnDestroy, AfterViewInit { } startSol(): void { - if (this.redirector !== null) { + if (this.redirector != null) { this.redirector.start(WebSocket) } }