Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cu 86bznvd1v dashboard end to end testing #283

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
17 changes: 17 additions & 0 deletions JeMPI_Apps/JeMPI_UI/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
baseUrl:'http://localhost:3001/',
setupNodeEvents(on, config) {
// implement node event listeners here
},
},

component: {
devServer: {
framework: "create-react-app",
bundler: "webpack",
},
},
});
85 changes: 85 additions & 0 deletions JeMPI_Apps/JeMPI_UI/cypress/e2e/dashboard.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
describe('Dashboard Component', () => {
beforeEach(() => {
cy.visit('/')
})

it('should display the dashboard tabs', () => {
cy.get('[aria-label="dashboard tabs"]').should('be.visible')
})

it('should navigate through tabs', () => {
// Check initial tab (Confusion Matrix)
cy.get('[id="dashboard-tab-0"]').click()
cy.get('#dashboard-tabpanel-0').should('be.visible')

// Switch to M & U Values tab
cy.get('[id="dashboard-tab-1"]').click()
cy.get('#dashboard-tabpanel-1').should('be.visible')
cy.get('#dashboard-tabpanel-0').should('not.be.visible')

// Switch to Import Process Status tab
cy.get('[id="dashboard-tab-2"]').click()
cy.get('#dashboard-tabpanel-2').should('be.visible')
cy.get('#dashboard-tabpanel-1').should('not.be.visible')
})

it('should display widgets in Confusion Matrix tab', () => {
cy.get('[id="dashboard-tab-0"]').click()
cy.get('#dashboard-tabpanel-0').within(() => {
cy.get('fieldset legend').contains('Records').should('be.visible')
cy.get('fieldset legend').contains('Notifications').should('be.visible')
cy.get('legend').contains('Confusion Matrix').should('be.visible')
})
})

it('should display M & U widget in M & U Values tab', () => {
cy.get('[id="dashboard-tab-1"]').click()
cy.get('#dashboard-tabpanel-1').within(() => {
cy.get('legend').contains('M & U Values').should('be.visible')
})
})


it('should render correctly with no data', () => {
// Mock the useDashboardData hook to return no data
cy.intercept('GET', '/api/dashboard-data', {
body: {
data: {
dashboardData: {}
}
}
})

// Visit the page and click on the dashboard tab
cy.visit('/')
cy.get('[id="dashboard-tab-0"]').click()

// Verify that the page renders correctly with no data
cy.get('#dashboard-tabpanel-0').within(() => {
cy.get('fieldset legend').contains('Records').should('be.visible')
cy.get('fieldset legend').contains('Notifications').should('be.visible')
cy.get('legend').contains('Confusion Matrix').should('be.visible')
})
})

it('should display loading state correctly', () => {
// Mock the useDashboardData hook to simulate loading state
cy.intercept('GET', '/api/dashboard-data', (req) => {
req.on('response', (res) => {
res.setDelay(1000)
})
})
cy.visit('/')
cy.get('[id="dashboard-tab-0"]').click()
})

it('should handle API errors', () => {
// Mock the useDashboardData hook to return an error
cy.intercept('GET', '/api/dashboard-data', {
statusCode: 500,
body: { error: 'Internal Server Error' }
})
cy.visit('/')
cy.get('[id="dashboard-tab-0"]').click()
})
})
37 changes: 37 additions & 0 deletions JeMPI_Apps/JeMPI_UI/cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
12 changes: 12 additions & 0 deletions JeMPI_Apps/JeMPI_UI/cypress/support/component-index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Components App</title>
</head>
<body>
<div data-cy-root></div>
</body>
</html>
39 changes: 39 additions & 0 deletions JeMPI_Apps/JeMPI_UI/cypress/support/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ***********************************************************
// This example support/component.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')

import { mount } from 'cypress/react18'

// Augment the Cypress namespace to include type definitions for
// your custom command.
// Alternatively, can be defined in cypress/support/component.d.ts
// with a <reference path="./component" /> at the top of your spec.
declare global {
namespace Cypress {
interface Chainable {
mount: typeof mount
}
}
}

Cypress.Commands.add('mount', mount)

// Example use:
// cy.mount(<MyComponent />)
20 changes: 20 additions & 0 deletions JeMPI_Apps/JeMPI_UI/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
Loading