Skip to content

Commit 2b93620

Browse files
committed
feat(calm-hub-ui): add e2e testing framework and test specs
1 parent 5fa302a commit 2b93620

File tree

14 files changed

+1304
-18
lines changed

14 files changed

+1304
-18
lines changed

calm-hub-ui/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ You may also see any lint errors in the console.
1919
Launches the test runner in the interactive watch mode.\
2020
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
2121

22+
### `npm e2e`
23+
24+
2225
### `npm run build`
2326

2427
Builds the app for production to the `build` folder.\

calm-hub-ui/cypress.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from "cypress";
2+
3+
export default defineConfig({
4+
e2e: {
5+
setupNodeEvents(on, config) {
6+
// implement node event listeners here
7+
},
8+
baseUrl: 'http://localhost:5173',
9+
},
10+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const expectedNamespace = "finos"
2+
const expectedArchitectureId = 1;
3+
const expectedArchitectureVersion = "1.0.0";
4+
5+
describe('Architecture Tests', () => {
6+
beforeEach(() => {
7+
cy.intercept("/calm/namespaces", {"values": [expectedNamespace]});
8+
cy.intercept("/calm/namespaces/finos/architectures", {"values": [expectedArchitectureId]});
9+
cy.intercept("/calm/namespaces/finos/architectures/1/versions", {"values": [expectedArchitectureVersion]});
10+
cy.intercept("/calm/namespaces/finos/architectures/1/versions/1.0.0", {
11+
fixture: "three-tier-calm.json"
12+
});
13+
})
14+
15+
it("Displays architecture JSON successfully", () => {
16+
cy.visit("/");
17+
cy.findByText(expectedNamespace).click();
18+
cy.findByText(/architectures/i).click();
19+
cy.findByText(/1/i).click();
20+
cy.findByText(/1.0.0/i).click();
21+
22+
cy.findByText(/relationship descriptions/i).should("exist");
23+
cy.findByText(/node descriptions/i).should("exist");
24+
25+
cy.findByRole("tab", { name: /json/i}).click();
26+
cy.contains(/web-client/i);
27+
cy.fixture('three-tier-calm').then(data => {
28+
cy.contains(/\$schema/i)
29+
cy.contains(data.$schema)
30+
31+
cy.contains(/nodes/i);
32+
cy.get('[data-cy="json-renderer"]').scrollTo("bottom")
33+
});
34+
})
35+
})

calm-hub-ui/cypress/e2e/home.cy.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {namespaces, resourceTypes} from "../fixtures/constants.js";
2+
3+
4+
describe('Home page tests', () => {
5+
beforeEach(() => {
6+
cy.intercept("/calm/namespaces", {"values": namespaces})
7+
})
8+
9+
it('Loads initial screen successfully', () => {
10+
cy.visit('/');
11+
cy.findByText("Explore").should("exist");
12+
cy.findByText("Namespaces").should("exist");
13+
namespaces.forEach(namespace => cy.findByText(namespace).should("exist"));
14+
cy.findByText(namespaces[0]).click();
15+
resourceTypes.forEach(resourceType => { cy.findByText(resourceType).should("exist"); });
16+
})
17+
18+
context("Wide screen tests", () => {
19+
it("Finds navigation items", () => {
20+
cy.viewport('macbook-16')
21+
cy.visit('/');
22+
cy.findByRole("link", { name: "Hub" })
23+
cy.findByRole("link", { name: "Visualizer" })
24+
})
25+
26+
})
27+
28+
context("Collapsed screen tests", () => {
29+
it("Finds navigation items", () => {
30+
cy.viewport(1000, 600)
31+
cy.visit('/');
32+
cy.findByRole("button", { name: "Open Menu" }).click();
33+
cy.findByRole("link", { name: "Hub" })
34+
cy.findByRole("link", { name: "Visualizer" })
35+
})
36+
})
37+
})
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const namespaces = ["finos","workshop","traderx","osff2025", "e2e"];
2+
export const resourceTypes = ['Architectures', 'Patterns', 'Flows', 'ADRs'];
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "hello@cypress.io",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"$schema": "https://calm.finos.org/draft/2025-03/meta/calm.json",
3+
"nodes": [
4+
{
5+
"unique-id": "web-client",
6+
"node-type": "webclient",
7+
"name": "Web Client",
8+
"description": "Browser based web interface for TraderX",
9+
"data-classification": "Confidential",
10+
"run-as": "user"
11+
},
12+
{
13+
"unique-id": "web-service",
14+
"node-type": "service",
15+
"name": "Web Service",
16+
"description": "Allows employees to manage accounts and book trades",
17+
"data-classification": "Confidential",
18+
"run-as": "systemId"
19+
},
20+
{
21+
"unique-id": "app-db",
22+
"node-type": "database",
23+
"name": "App DB",
24+
"description": "Database which stores account, trade and position state",
25+
"data-classification": "Confidential",
26+
"run-as": "systemId"
27+
},
28+
{
29+
"unique-id": "internal-bank-network",
30+
"node-type": "network",
31+
"name": "Bank ABC Internal Network",
32+
"description": "Internal network for Bank ABC",
33+
"instance": "Internal Network"
34+
}
35+
],
36+
"relationships": [
37+
{
38+
"unique-id": "client-to-service",
39+
"description": "Calls web service",
40+
"relationship-type": {
41+
"connects": {
42+
"source": {
43+
"node": "web-client"
44+
},
45+
"destination": {
46+
"node": "web-service"
47+
}
48+
}
49+
},
50+
"protocol": "HTTPS"
51+
},
52+
{
53+
"unique-id": "service-to-database",
54+
"description": "Persist data in and retrieve data from",
55+
"relationship-type": {
56+
"connects": {
57+
"source": {
58+
"node": "web-service"
59+
},
60+
"destination": {
61+
"node": "app-db"
62+
}
63+
}
64+
},
65+
"protocol": "HTTPS"
66+
},
67+
{
68+
"unique-id": "traderx-system-is-deployed-in-internal-bank-network",
69+
"relationship-type": {
70+
"deployed-in": {
71+
"container": "internal-bank-network",
72+
"nodes": [
73+
"web-client",
74+
"web-service",
75+
"app-db"
76+
]
77+
}
78+
}
79+
}
80+
]
81+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
// }
38+
import '@testing-library/cypress/add-commands'
39+

calm-hub-ui/cypress/support/e2e.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// ***********************************************************
2+
// This example support/e2e.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'

calm-hub-ui/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"devDependencies": {
4747
"@eslint/js": "^9.25.0",
4848
"@tailwindcss/typography": "^0.5.16",
49+
"@testing-library/cypress": "^10.1.0",
4950
"@testing-library/jest-dom": "^6.6.3",
5051
"@testing-library/react": "^16.2.0",
5152
"@testing-library/user-event": "^14.6.1",
@@ -55,6 +56,7 @@
5556
"@types/react-dom": "^19.1.2",
5657
"@vitejs/plugin-react": "^4.3.4",
5758
"autoprefixer": "^10.4.20",
59+
"cypress": "^15.7.0",
5860
"daisyui": "^5.0.0",
5961
"eslint": "^9.25.0",
6062
"eslint-plugin-react": "^7.37.2",

0 commit comments

Comments
 (0)