Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
58 changes: 45 additions & 13 deletions sol/src/sol.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
})
})
20 changes: 5 additions & 15 deletions sol/src/sol.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Comment thread
rsdmike marked this conversation as resolved.
} else if (this.redirector != null) {
Comment thread
rsdmike marked this conversation as resolved.
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)
Expand Down Expand Up @@ -121,7 +111,7 @@ export class SOLComponent implements OnDestroy, AfterViewInit {
}

startSol(): void {
if (this.redirector !== null) {
if (this.redirector != null) {
this.redirector.start(WebSocket)
}
}
Expand Down