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

Set up cypress component testing #1106

Merged
merged 7 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion .github/workflows/frontend_pr_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,18 @@ jobs:
cd clients/ctl/admin-ui
npm install

- name: Cypress run
- name: Cypress E2E tests
uses: cypress-io/github-action@v4
with:
working-directory: clients/ctl/admin-ui
install: false
start: npm run cy:start
wait-on: "http://localhost:3000"
wait-on-timeout: 120

- name: Cypress component tests
uses: cypress-io/github-action@v4
with:
working-directory: clients/ctl/admin-ui
install: false
component: true
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The types of changes are:
* Add additional optional fields to system management forms [#1082](https://github.com/ethyca/fides/pull/1082)
* Delete a system through the UI [#1085](https://github.com/ethyca/fides/pull/1085)
* Edit a system through the UI [#1096](https://github.com/ethyca/fides/pull/1096)

* Cypress component testing [#1106](https://github.com/ethyca/fides/pull/1106)
### Changed

* Changed behavior of `load_default_taxonomy` to append instead of upsert [#1040](https://github.com/ethyca/fides/pull/1040)
Expand Down
9 changes: 9 additions & 0 deletions clients/ctl/admin-ui/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ export default defineConfig({
e2e: {
baseUrl: "http://localhost:3000",
},

defaultCommandTimeout: 5000,

retries: {
runMode: 3,
openMode: 0,
},

component: {
devServer: {
framework: "next",
bundler: "webpack",
},
},
});
28 changes: 28 additions & 0 deletions clients/ctl/admin-ui/cypress/components/DataCategoryInput.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as React from "react";

import DataCategoryInput from "~/features/dataset/DataCategoryInput";
import { MOCK_DATA_CATEGORIES } from "~/mocks/data";
import { DataCategory } from "~/types/api";

describe("DataCategoryInput", () => {
it("can check a category", () => {
const onCheckedSpy = cy.spy().as("onCheckedSpy");
cy.mount(
<DataCategoryInput
dataCategories={MOCK_DATA_CATEGORIES as DataCategory[]}
checked={["user"]}
onChecked={onCheckedSpy}
/>
);

cy.getByTestId("selected-categories").should("contain", "user");
cy.getByTestId("data-category-dropdown").click();
cy.getByTestId("expand-System Data").click();
cy.getByTestId("checkbox-Authentication Data").click();

cy.get("@onCheckedSpy").should("have.been.calledWith", [
"user",
"system.authentication",
]);
});
});
14 changes: 14 additions & 0 deletions clients/ctl/admin-ui/cypress/support/component-index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!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>
<!-- Used by Next.js to inject CSS. -->
<div id="__next_css__DO_NOT_USE__"></div>
</head>
<body>
<div data-cy-root></div>
</body>
</html>
48 changes: 48 additions & 0 deletions clients/ctl/admin-ui/cypress/support/component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// ***********************************************************
// 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";
import "@fontsource/inter/400.css";
import "@fontsource/inter/500.css";
import "@fontsource/inter/700.css";

import { ChakraProvider } from "@chakra-ui/react";
// Alternatively you can use CommonJS syntax:
// require('./commands')
// eslint-disable-next-line import/no-extraneous-dependencies
import { mount } from "cypress/react";
import * as React from "react";

import theme from "../../src/theme";

// 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", (jsx, options) =>
mount(React.createElement(ChakraProvider, { theme }, jsx), options)
);

// Example use:
// cy.mount(<MyComponent />)
9 changes: 7 additions & 2 deletions clients/ctl/admin-ui/cypress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"compilerOptions": {
"jsx": "react",
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "node"]
"types": ["cypress", "node"],
"baseUrl": "..",
"paths": {
"~/*": ["src/*"]
}
},
"include": ["**/*.ts", "../cypress.config.ts"]
"include": ["**/*.ts", "**/*.tsx", "../cypress.config.ts"]
}
1 change: 1 addition & 0 deletions clients/ctl/admin-ui/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ module.exports = {
"/node_modules/",
"^.+\\.module\\.(css|sass|scss)$",
],
watchPathIgnorePatterns: ["node_modules"],
};
7 changes: 6 additions & 1 deletion clients/ctl/admin-ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,10 @@
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.d.ts"],
"exclude": ["node_modules", "cypress/**/*.ts", "cypress.config.ts"]
"exclude": [
"node_modules",
"cypress/**/*.ts",
"cypress/**/*.tsx",
"cypress.config.ts"
]
}