Skip to content

Commit 7aa3478

Browse files
committed
Introduced first simple cypress component test for entity Component
Removed call to onChangedValue method in entity-component.html
1 parent 8f2f895 commit 7aa3478

File tree

13 files changed

+1606
-62
lines changed

13 files changed

+1606
-62
lines changed

angular.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
"builder": "@angular-devkit/build-angular:application",
1515
"options": {
1616
"baseHref": "./",
17-
"outputPath": {
18-
"base": "dist"
19-
},
17+
"outputPath": "dist",
2018
"localize": true,
2119
"index": "src/index.html",
2220
"polyfills": ["zone.js", "@angular/localize/init"],

cypress.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { defineConfig } = require('cypress')
2+
module.exports = defineConfig({
3+
component: {
4+
devServer: {
5+
framework: "angular",
6+
bundler: "webpack",
7+
},
8+
specPattern: "**/*.cy.ts",
9+
},
10+
});

cypress/Entity.cy.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { provideHttpClient, withInterceptorsFromDi } from "@angular/common/http"
2+
import { NoopAnimationsModule } from "@angular/platform-browser/animations"
3+
import { ActivatedRoute, provideRouter } from "@angular/router"
4+
import { IdentifiedStates, ImodbusData, ImodbusEntity, Iselect } from "@modbus2mqtt/specification.shared"
5+
import { ISpecificationMethods } from "angular/src/app/services/specificationInterface"
6+
import { EntityComponent } from "angular/src/app/specification/entity/entity.component"
7+
import { Subject } from "rxjs"
8+
9+
let specificationMethods:ISpecificationMethods = {
10+
getCurrentMessage:()=>{return {type:0, category: 0}},
11+
getMqttLanguageName:()=>{return "english"},
12+
getNonVariableNumberEntities:()=>{ return []},
13+
getMqttNames: ()=> {return []},
14+
getSaveObservable:()=> {return new Subject<void>()},
15+
postModbusEntity:()=>{return new Subject<ImodbusData>()},
16+
postModbusWriteMqtt: ()=> {return new Subject<string>()},
17+
hasDuplicateVariableConfigurations: ()=>{ return false},
18+
canEditEntity: ()=>{return true},
19+
setEntitiesTouched:()=>{},
20+
addEntity:()=>{},
21+
deleteEntity:()=>{},
22+
copy2Translation:()=>{}
23+
};
24+
25+
let selectEntity:ImodbusEntity = {
26+
id: 1,
27+
modbusValue: [3],
28+
mqttValue:"3",
29+
identified:IdentifiedStates.identified,
30+
converter: {name:"select", registerTypes:[3,4] },
31+
readonly:false,
32+
registerType: 3,
33+
modbusAddress: 4,
34+
converterParameters: {
35+
36+
} as Iselect
37+
}
38+
39+
40+
describe('Entity Component tests', () => {
41+
beforeEach(() => {
42+
cy.intercept("GET", "**/converters",{
43+
fixture: "converters.json"
44+
})
45+
// This configures the rootUrl for /api... calls
46+
// they need to be relative in ingress scenarios,
47+
// but they must be absolute for cypress tests
48+
cy.window().then(win => {
49+
(win as any).configuration = { rootUrl: "/" }
50+
})
51+
});
52+
it('can mount', () => {
53+
54+
cy.mount(EntityComponent,{
55+
imports:[NoopAnimationsModule],
56+
providers: [provideHttpClient(withInterceptorsFromDi()), provideRouter([])],
57+
componentProperties: {
58+
specificationMethods: specificationMethods,
59+
entity: selectEntity,
60+
disabled:false
61+
}
62+
})
63+
})
64+
})

cypress/fixtures/converters.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{
3+
"name": "number",
4+
"registerTypes": [3, 4]
5+
},
6+
{
7+
"name": "select",
8+
"registerTypes": [3, 4, 1]
9+
},
10+
{
11+
"name": "text",
12+
"registerTypes": [3, 4]
13+
},
14+
{
15+
"name": "binary",
16+
"registerTypes": [1, 3]
17+
},
18+
{
19+
"name": "value",
20+
"registerTypes": [4, 3]
21+
}
22+
]

cypress/support/commands.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************
3+
// This example commands.ts shows you how to
4+
// create various custom commands and overwrite
5+
// existing commands.
6+
//
7+
// For more comprehensive examples of custom
8+
// commands please read more here:
9+
// https://on.cypress.io/custom-commands
10+
// ***********************************************
11+
//
12+
//
13+
// -- This is a parent command --
14+
// Cypress.Commands.add('login', (email, password) => { ... })
15+
//
16+
//
17+
// -- This is a child command --
18+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
19+
//
20+
//
21+
// -- This is a dual command --
22+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
23+
//
24+
//
25+
// -- This will overwrite an existing command --
26+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
27+
//
28+
// declare global {
29+
// namespace Cypress {
30+
// interface Chainable {
31+
// login(email: string, password: string): Chainable<void>
32+
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
33+
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
34+
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
35+
// }
36+
// }
37+
// }
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<title>Components App</title>
8+
</head>
9+
<body>
10+
<div data-cy-root></div>
11+
</body>
12+
</html>

cypress/support/component.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// ***********************************************************
2+
// This example support/component.ts is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
import { mount } from 'cypress/angular'
20+
21+
// Augment the Cypress namespace to include type definitions for
22+
// your custom command.
23+
// Alternatively, can be defined in cypress/support/component.d.ts
24+
// with a <reference path="./component" /> at the top of your spec.
25+
declare global {
26+
namespace Cypress {
27+
interface Chainable {
28+
mount: typeof mount
29+
}
30+
}
31+
}
32+
33+
Cypress.Commands.add('mount', mount)
34+
35+
// Example use:
36+
// cy.mount(MyComponent)

0 commit comments

Comments
 (0)