@@ -4,7 +4,10 @@ import {
44 beforeEachHelper as beforeEachEntityHelper ,
55 mountEntityComponent ,
66 setOnEntityNameOrVariableFieldsChangeFunc ,
7+ setOnPostModbusEntityFunc
78} from "./support/entityHelper" ;
9+ import { ImodbusData , Inumber , Itext } from "@modbus2mqtt/specification.shared" ;
10+ import { Subject } from "rxjs" ;
811
912describe ( "Entity Component tests" , ( ) => {
1013 beforeEach ( beforeEachEntityHelper ) ; // mounts entity and opens all expansion panels
@@ -41,40 +44,74 @@ describe("Entity Component tests", () => {
4144 } ) ;
4245 it ( "No Variable Type => no variableConfiguration" , ( ) => {
4346 cy . get ( 'mat-select[formControlName="variableType"]' )
47+ . click ( )
48+ . get ( "mat-option" )
49+ . first ( )
50+ . click ( )
51+ cy . get ( 'input[formControlName="name"]' ) . type ( "test" )
52+ cy . get ( 'input[formControlName="icon"]' ) . click ( ) . then ( ( ) => { setOnEntityNameOrVariableFieldsChangeFunc ( ( entity ) => {
53+ expect ( entity . variableConfiguration ) . to . be . undefined ;
54+ expect ( ( entity as ImodbusEntityWithName ) . name ) . to . be . equal ( 'test' ) ;
55+ } ) } )
56+ cy . get ( 'mat-select[formControlName="variableEntity"]' ) . invoke ( 'val' )
57+ . then ( val => {
58+ const myVal = val ;
59+ expect ( myVal ) . to . equal ( '' ) ;
60+ } )
61+
62+ //cy.get('input[formControlName="name"]').should(
63+ // "not.be.null");
64+
65+ } ) ;
66+ it ( "Set Byte Order for Number" , ( ) => {
67+ cy . get ( 'mat-select[formControlName="converter"]' )
4468 . click ( )
4569 . get ( "mat-option" )
4670 . first ( )
47- . click ( ) ;
48- cy . get ( 'input[formControlName="name"]' ) . type ( "test" ) ;
49- cy . get ( 'input[formControlName="icon"]' )
71+ . click ( ) . then ( ( ) => {
72+ // Validation will be called after value change of any name or variable field
73+ // onVariableEntityValueChange or onEntityNameValueChange
74+ setOnPostModbusEntityFunc ( ( entity ) => {
75+ expect ( ( entity ! . converterParameters ! as Inumber ) . swapBytes ) . to . be . true ;
76+ return new Subject < ImodbusData > ( ) ;
77+ } ) ;
78+ } ) ; ;
79+ cy . openAllExpansionPanels ( )
80+ cy . get ( 'mat-slide-toggle[formControlName="swapBytes"]' )
81+ . click ( )
82+
83+ } ) ;
84+ it ( "Set Byte Order for Text" , ( ) => {
85+ cy . get ( 'mat-select[formControlName="converter"]' )
5086 . click ( )
51- . then ( ( ) => {
52- setOnEntityNameOrVariableFieldsChangeFunc ( ( entity ) => {
53- expect ( entity . variableConfiguration ) . to . be . undefined ;
54- expect ( ( entity as ImodbusEntityWithName ) . name ) . to . be . equal ( "test" ) ;
87+ . get ( "mat-option" )
88+ . eq ( 2 )
89+ . click ( ) . then ( ( ) => {
90+ // Validation will be called after value change of any name or variable field
91+ // onVariableEntityValueChange or onEntityNameValueChange
92+ setOnPostModbusEntityFunc ( ( entity ) => {
93+ expect ( ( entity ! . converterParameters ! as Itext ) . swapBytes , "swapBytes is not defined" ) . not . to . be . undefined ;
94+ expect ( ( entity ! . converterParameters ! as Itext ) . swapBytes ) . to . be . true ;
95+ return new Subject < ImodbusData > ( ) ;
5596 } ) ;
56- } ) ;
57- cy . get ( 'mat-select[formControlName="variableEntity"]' )
58- . invoke ( "val" )
59- . then ( ( val ) => {
60- const myVal = val ;
61- expect ( myVal ) . to . equal ( "" ) ;
62- } ) ;
63-
64- //cy.get('input[formControlName="name"]').should(
65- // "not.be.null");
97+
98+ } ) ; ;
99+ cy . openAllExpansionPanels ( )
100+ cy . get ( '[formControlName= "textSwapBytes"]' )
101+ . click ( )
102+
66103 } ) ;
67104} ) ;
68- describe ( "Test for Modbus Address" , ( ) => {
69- beforeEach ( ( ) => { mountEntityComponent ( true ) } ) ; // mounts entity and opens all expansion panels
70- afterEach ( afterEachEntityHelper ) ;
71- it ( "Modbus address in hex" , ( ) => {
72- const inputField = 'input[formControlName="modbusAddress"]'
73- const matField = 'mat-form-field input[formControlName="modbusAddress"]'
74- cy . get ( inputField ) . should ( 'have.value' , '0x4' ) ;
75- cy . get ( inputField ) . clear ( ) . type ( '1234' ) . blur ( ) . should ( 'have.value' , '0x4d2' ) ;
76- cy . get ( inputField ) . clear ( ) . type ( '0X12s32' ) . blur ( ) . should ( 'have.value' , '0x1232' ) ;
77- cy . get ( inputField ) . clear ( ) . type ( '0xx7' )
78- cy . get ( inputField ) . parent ( ) . get ( "mat-error" ) . should ( 'contain' , 'dec or hex' )
79- } )
80- } ) ;
105+ // describe("Test for Modbus Address", () => {
106+ // beforeEach(()=>{mountEntityComponent(true)}); // mounts entity and opens all expansion panels
107+ // afterEach(afterEachEntityHelper);
108+ // it("Modbus address in hex", () => {
109+ // const inputField='input[formControlName="modbusAddress"]'
110+ // const matField='mat-form-field input[formControlName="modbusAddress"]'
111+ // cy.get(inputField).should('have.value', '0x4');
112+ // cy.get(inputField).clear().type('1234').blur().should('have.value', '0x4d2');
113+ // cy.get(inputField).clear().type('0X12s32').blur().should('have.value', '0x1232');
114+ // cy.get(inputField).clear().type('0xx7')
115+ // cy.get(inputField).parent().get( "mat-error").should('contain', 'dec or hex')
116+ // })
117+ // });
0 commit comments