Skip to content

Commit 999dc9f

Browse files
committed
Start testing select-slave
1 parent 8d74b4e commit 999dc9f

File tree

3 files changed

+65
-4
lines changed

3 files changed

+65
-4
lines changed

cypress/select-modbus.cy.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ImodbusEntityWithName } from "angular/src/app/services/specificationInterface";
2+
import { beforeEachHelper } from "./support/modbusSlaveHelper";
3+
4+
describe("Select Slave tests", () => {
5+
beforeEach(beforeEachHelper); // mounts entity and opens all expansion panels
6+
//afterEach(afterEachEntityHelper);
7+
it("mount", () => {
8+
cy.get('mat-select[formControlName="variableType"]')
9+
});
10+
});
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import {
2+
provideHttpClient,
3+
withInterceptorsFromDi,
4+
} from "@angular/common/http";
5+
import { EventEmitter } from "@angular/core";
6+
import { NoopAnimationsModule } from "@angular/platform-browser/animations";
7+
import { ActivatedRoute, provideRouter } from "@angular/router";
8+
import { apiUri } from "@modbus2mqtt/server.shared";
9+
import { SelectSlaveComponent } from "angular/src/app/select-slave/select-slave.component";
10+
import { from } from "rxjs";
11+
let ev = new EventEmitter<number | undefined>()
12+
// entityApiService.getConfiguration {mqttbasetopic rootUrl apiUri.configuration
13+
// entityApiService.getBus bus.connectionData, bus.busId apiUri.bus
14+
// entityApiService.getSlaves Islave[] apiUri.slaves
15+
// getSpecsForSlave IidentificationSpecification[] apiUri.specsForSlaveId
16+
// not implemented yet deleteSlave
17+
// not implemented yet postSlave
18+
19+
/**
20+
* mounts the specification-entity-component and opens all expansion panels
21+
*
22+
* The entity values must be changed in the UI using cypress methods
23+
*
24+
* The Modbus Value is a 32 bit array. It can be changed in specificationMethods.postModbusEntity if required
25+
*
26+
* If other initial values are required, a new test file is required
27+
*/
28+
export function beforeEachHelper() {
29+
cy.intercept("GET", "**/converters", {
30+
fixture: "converters.json",
31+
});
32+
// This configures the rootUrl for /api... calls
33+
// they need to be relative in ingress scenarios,
34+
// but they must be absolute for cypress tests
35+
cy.window().then((win) => {
36+
(win as any).configuration = { rootUrl: "/" };
37+
});
38+
cy.mount(SelectSlaveComponent, {
39+
imports: [NoopAnimationsModule],
40+
providers: [provideHttpClient(withInterceptorsFromDi()), provideRouter([]),{
41+
provide: ActivatedRoute,
42+
useValue: {
43+
params: from([{busid: 1}]),
44+
},
45+
},],
46+
componentProperties: {
47+
slaveidEventEmitter:ev
48+
},
49+
});
50+
}
51+

src/app/select-slave/select-slave.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export class SelectSlaveComponent extends SessionStorage implements OnInit {
217217
fc.setValue(slaveSpec);
218218
return spec;
219219
}
220-
private updateSlaves(bus: IBus, detectSpec?: boolean) {
220+
private updateSlaves( detectSpec?: boolean) {
221221
this.entityApiService.getSlaves(this.bus.busId).subscribe((slaves) => {
222222
this.uiSlaves = [];
223223
slaves.forEach((s) => {
@@ -370,7 +370,7 @@ export class SelectSlaveComponent extends SessionStorage implements OnInit {
370370

371371
showUnmatched() {
372372
this.showAllPublicSpecs.value;
373-
this.updateSlaves(this.bus, false);
373+
this.updateSlaves(false);
374374
}
375375
compareSpecificationIdentification(
376376
o1: IidentificationSpecification,
@@ -531,7 +531,7 @@ export class SelectSlaveComponent extends SessionStorage implements OnInit {
531531
);
532532
if (dIdx >= 0) {
533533
this.uiSlaves.splice(dIdx, 1);
534-
this.updateSlaves(this.bus, false);
534+
this.updateSlaves( false);
535535
}
536536
});
537537
}
@@ -564,7 +564,7 @@ export class SelectSlaveComponent extends SessionStorage implements OnInit {
564564
this.entityApiService
565565
.postSlave(this.bus.busId, { slaveid: slaveId })
566566
.subscribe(() => {
567-
this.updateSlaves(this.bus, detectSpec);
567+
this.updateSlaves( detectSpec);
568568
});
569569
}
570570
private static form2SlaveSetValue(uiSlave: IuiSlave, controlname: string) {

0 commit comments

Comments
 (0)