diff --git a/modules/ui/src/app/app.component.spec.ts b/modules/ui/src/app/app.component.spec.ts index 7c785743f..19b9ea807 100644 --- a/modules/ui/src/app/app.component.spec.ts +++ b/modules/ui/src/app/app.component.spec.ts @@ -77,6 +77,7 @@ import { TestingCompleteComponent } from './components/testing-complete/testing- import { VersionComponent } from './components/version/version.component'; import { MOCK_MODULES } from './mocks/device.mock'; import { HelpTips } from './model/tip-config'; +import { MOCK_INFO } from './mocks/topic.mock'; const windowMock = { location: { @@ -124,7 +125,7 @@ describe('AppComponent', () => { 'focusFirstElementInContainer', ]); mockLiveAnnouncer = jasmine.createSpyObj('mockLiveAnnouncer', ['announce']); - mockMqttService = jasmine.createSpyObj(['getNetworkAdapters']); + mockMqttService = jasmine.createSpyObj(['getNetworkAdapters', 'getInfo']); TestBed.configureTestingModule({ imports: [ @@ -203,6 +204,7 @@ describe('AppComponent', () => { mockService.fetchDevices.and.returnValue(of([])); mockService.getTestModules.and.returnValue(of([...MOCK_MODULES])); mockMqttService.getNetworkAdapters.and.returnValue(of(MOCK_ADAPTERS)); + mockMqttService.getInfo.and.returnValue(of(MOCK_INFO)); store = TestBed.inject(MockStore); fixture = TestBed.createComponent(AppComponent); component = fixture.componentInstance; diff --git a/modules/ui/src/app/app.component.ts b/modules/ui/src/app/app.component.ts index 6aec0a277..7116aaa51 100644 --- a/modules/ui/src/app/app.component.ts +++ b/modules/ui/src/app/app.component.ts @@ -213,6 +213,7 @@ export class AppComponent implements AfterViewInit { this.appStore.getNetworkAdapters(); this.appStore.getInterfaces(); this.appStore.getSystemConfig(); + this.appStore.getInfo(); this.matIconRegistry.addSvgIcon( 'device_run', this.domSanitizer.bypassSecurityTrustResourceUrl(DEVICES_RUN_URL) diff --git a/modules/ui/src/app/app.store.spec.ts b/modules/ui/src/app/app.store.spec.ts index efd238325..8c5deae4e 100644 --- a/modules/ui/src/app/app.store.spec.ts +++ b/modules/ui/src/app/app.store.spec.ts @@ -56,6 +56,7 @@ import { TestRunMqttService } from './services/test-run-mqtt.service'; import { MOCK_ADAPTERS } from './mocks/settings.mock'; import { TestingType } from './model/device'; import { ResultOfTestrun, StatusOfTestrun } from './model/testrun-status'; +import { MOCK_INFO } from './mocks/topic.mock'; const mock = (() => { let store: { [key: string]: string } = {}; @@ -109,7 +110,7 @@ describe('AppStore', () => { mockFocusManagerService = jasmine.createSpyObj([ 'focusFirstElementInContainer', ]); - mockMqttService = jasmine.createSpyObj(['getNetworkAdapters']); + mockMqttService = jasmine.createSpyObj(['getNetworkAdapters', 'getInfo']); TestBed.configureTestingModule({ providers: [ @@ -341,6 +342,20 @@ describe('AppStore', () => { }); }); + describe('getInfo', () => { + const info = MOCK_INFO; + + beforeEach(() => { + mockMqttService.getInfo.and.returnValue(of(info)); + }); + + it('should notify about new info', () => { + appStore.getInfo(); + + expect(mockNotificationService.notify).toHaveBeenCalledWith('message'); + }); + }); + describe('setCloseCallout', () => { it('should update store', done => { appStore.viewModel$.pipe(skip(1), take(1)).subscribe(store => { diff --git a/modules/ui/src/app/app.store.ts b/modules/ui/src/app/app.store.ts index 6ef18b791..d2d3211b1 100644 --- a/modules/ui/src/app/app.store.ts +++ b/modules/ui/src/app/app.store.ts @@ -71,6 +71,7 @@ import { map } from 'rxjs/internal/operators/map'; import { TestrunDialogService } from './services/testrun-dialog.service'; import { Routes } from './model/routes'; import { Router } from '@angular/router'; +import { Info } from './model/topic'; export const CONSENT_SHOWN_KEY = 'CONSENT_SHOWN'; export const CALLOUT_STATE_KEY = 'CALLOUT_STATE'; @@ -253,6 +254,18 @@ export class AppStore extends ComponentStore { ); }); + getInfo = this.effect(trigger$ => { + return trigger$.pipe( + exhaustMap(() => { + return this.testRunMqttService.getInfo().pipe( + tap((info: Info) => { + this.notificationService.notify(info.message); + }) + ); + }) + ); + }); + private notifyAboutTheAdapters(adapters: SystemInterfaces) { this.notificationService.notify( `New network adapter(s) ${Object.keys(adapters).join(', ')} has been detected. You can switch to using it in the System settings menu` diff --git a/modules/ui/src/app/mocks/topic.mock.ts b/modules/ui/src/app/mocks/topic.mock.ts index 4309ae84f..382f56705 100644 --- a/modules/ui/src/app/mocks/topic.mock.ts +++ b/modules/ui/src/app/mocks/topic.mock.ts @@ -1,5 +1,9 @@ -import { InternetConnection } from '../model/topic'; +import { Info, InternetConnection } from '../model/topic'; export const MOCK_INTERNET: InternetConnection = { connection: false, }; + +export const MOCK_INFO: Info = { + message: 'message', +}; diff --git a/modules/ui/src/app/model/topic.ts b/modules/ui/src/app/model/topic.ts index d330dbb82..701153135 100644 --- a/modules/ui/src/app/model/topic.ts +++ b/modules/ui/src/app/model/topic.ts @@ -2,8 +2,13 @@ export enum Topic { NetworkAdapters = 'events/adapter', InternetConnection = 'events/internet', Status = 'status', + Info = 'info', } export interface InternetConnection { connection: boolean | null; } + +export interface Info { + message: string; +} diff --git a/modules/ui/src/app/services/test-run-mqtt.service.spec.ts b/modules/ui/src/app/services/test-run-mqtt.service.spec.ts index 7ffb12443..3198430da 100644 --- a/modules/ui/src/app/services/test-run-mqtt.service.spec.ts +++ b/modules/ui/src/app/services/test-run-mqtt.service.spec.ts @@ -6,7 +6,7 @@ import SpyObj = jasmine.SpyObj; import { of } from 'rxjs'; import { MOCK_ADAPTERS } from '../mocks/settings.mock'; import { Topic } from '../model/topic'; -import { MOCK_INTERNET } from '../mocks/topic.mock'; +import { MOCK_INFO, MOCK_INTERNET } from '../mocks/topic.mock'; import { MOCK_PROGRESS_DATA_IN_PROGRESS } from '../mocks/testrun.mock'; import { TestRunService } from './test-run.service'; @@ -97,6 +97,26 @@ describe('TestRunMqttService', () => { }); }); + describe('getInfo', () => { + beforeEach(() => { + mockService.observe.and.returnValue(of(getResponse(MOCK_INFO))); + }); + + it('should subscribe the topic', done => { + service.getInfo().subscribe(() => { + expect(mockService.observe).toHaveBeenCalledWith(Topic.Info); + done(); + }); + }); + + it('should return object of type', done => { + service.getInfo().subscribe(res => { + expect(res).toEqual(MOCK_INFO); + done(); + }); + }); + }); + function getResponse(response: Type): IMqttMessage { const enc = new TextEncoder(); const message = enc.encode(JSON.stringify(response)); diff --git a/modules/ui/src/app/services/test-run-mqtt.service.ts b/modules/ui/src/app/services/test-run-mqtt.service.ts index c0d78390d..276c1c6b6 100644 --- a/modules/ui/src/app/services/test-run-mqtt.service.ts +++ b/modules/ui/src/app/services/test-run-mqtt.service.ts @@ -4,7 +4,7 @@ import { catchError, Observable, of } from 'rxjs'; import { map } from 'rxjs/operators'; import { Adapters } from '../model/setting'; import { TestrunStatus } from '../model/testrun-status'; -import { InternetConnection, Topic } from '../model/topic'; +import { Info, InternetConnection, Topic } from '../model/topic'; import { TestRunService } from './test-run.service'; @Injectable({ @@ -32,6 +32,10 @@ export class TestRunMqttService { ); } + getInfo(): Observable { + return this.topic(Topic.Info); + } + private topic(topicName: string): Observable { return this.mqttService.observe(topicName).pipe( map(