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
4 changes: 3 additions & 1 deletion modules/ui/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -124,7 +125,7 @@ describe('AppComponent', () => {
'focusFirstElementInContainer',
]);
mockLiveAnnouncer = jasmine.createSpyObj('mockLiveAnnouncer', ['announce']);
mockMqttService = jasmine.createSpyObj(['getNetworkAdapters']);
mockMqttService = jasmine.createSpyObj(['getNetworkAdapters', 'getInfo']);

TestBed.configureTestingModule({
imports: [
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions modules/ui/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 16 additions & 1 deletion modules/ui/src/app/app.store.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } = {};
Expand Down Expand Up @@ -109,7 +110,7 @@ describe('AppStore', () => {
mockFocusManagerService = jasmine.createSpyObj([
'focusFirstElementInContainer',
]);
mockMqttService = jasmine.createSpyObj(['getNetworkAdapters']);
mockMqttService = jasmine.createSpyObj(['getNetworkAdapters', 'getInfo']);

TestBed.configureTestingModule({
providers: [
Expand Down Expand Up @@ -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 => {
Expand Down
13 changes: 13 additions & 0 deletions modules/ui/src/app/app.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -253,6 +254,18 @@ export class AppStore extends ComponentStore<AppComponentState> {
);
});

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`
Expand Down
6 changes: 5 additions & 1 deletion modules/ui/src/app/mocks/topic.mock.ts
Original file line number Diff line number Diff line change
@@ -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',
};
5 changes: 5 additions & 0 deletions modules/ui/src/app/model/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
22 changes: 21 additions & 1 deletion modules/ui/src/app/services/test-run-mqtt.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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<Type>(response: Type): IMqttMessage {
const enc = new TextEncoder();
const message = enc.encode(JSON.stringify(response));
Expand Down
6 changes: 5 additions & 1 deletion modules/ui/src/app/services/test-run-mqtt.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -32,6 +32,10 @@ export class TestRunMqttService {
);
}

getInfo(): Observable<Info> {
return this.topic<Info>(Topic.Info);
}

private topic<Type>(topicName: string): Observable<Type> {
return this.mqttService.observe(topicName).pipe(
map(
Expand Down
Loading