Skip to content

Commit 4a8b0d4

Browse files
authored
Merge pull request bcgov#1548 from dinesh-aot/1535
Basic setup for unit test
2 parents 8f5e259 + b339100 commit 4a8b0d4

File tree

11 files changed

+2150
-56
lines changed

11 files changed

+2150
-56
lines changed

epictrack-web/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ npm-debug.log*
2222
yarn-debug.log*
2323
yarn-error.log*
2424
.vscode/
25+
26+
cypress/downloads

epictrack-web/cypress.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig } from "cypress";
2+
3+
export default defineConfig({
4+
supportFolder: "cypress/support",
5+
component: {
6+
supportFile: "cypress/support/component.tsx",
7+
devServer: {
8+
framework: "create-react-app",
9+
bundler: "webpack",
10+
},
11+
},
12+
});
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: 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>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
import { Provider } from "react-redux";
19+
import { MemoryRouterProps } from "react-router-dom";
20+
import { EnhancedStore } from "@reduxjs/toolkit";
21+
import { RootState, store } from "../../src/store";
22+
23+
// Alternatively you can use CommonJS syntax:
24+
// require("./commands")
25+
26+
import { MountOptions, MountReturn, mount } from "cypress/react";
27+
import { BaseTheme } from "../../src/styles/theme";
28+
import { StyledEngineProvider, ThemeProvider } from "@mui/material";
29+
30+
// Augment the Cypress namespace to include type definitions for
31+
// your custom command.
32+
// Alternatively, can be defined in cypress/support/component.d.ts
33+
// with a <reference path="./component" /> at the top of your spec.
34+
declare global {
35+
namespace Cypress {
36+
interface Chainable {
37+
/**
38+
* Mounts a React node
39+
* @param component React Node to mount
40+
* @param options Additional options to pass into mount
41+
*/
42+
mount(
43+
component: React.ReactNode,
44+
options?: MountOptions & { routerProps?: MemoryRouterProps } & { reduxStore?: EnhancedStore<RootState> }
45+
): Cypress.Chainable<MountReturn>
46+
}
47+
}
48+
}
49+
50+
Cypress.Commands.add("mount", (component, options = {}) => {
51+
const { routerProps = { initialEntries: ["/"] }, reduxStore = store, ...mountOptions } = options
52+
53+
const wrapped = <Provider store={reduxStore}>
54+
<ThemeProvider theme={BaseTheme}>
55+
<StyledEngineProvider injectFirst>
56+
{component}
57+
</StyledEngineProvider>
58+
</ThemeProvider>
59+
</Provider>
60+
61+
return mount(wrapped, mountOptions)
62+
})
63+
64+
// Example use:
65+
// cy.mount(<MyComponent />)

0 commit comments

Comments
 (0)