Add cypress

This commit is contained in:
2022-07-23 17:16:23 +02:00
parent 43285a06c7
commit 338eb2e30d
10 changed files with 3380 additions and 15 deletions

View File

@@ -0,0 +1,38 @@
describe("Claculator", () => {
beforeEach(() => {
cy.visit("/");
});
it("shows default calculation", () => {
cy.get("[data-test=matrix] input").should("have.length", 16);
cy.get("[data-test=kernel] input").should("have.length", 9);
cy.get("[data-test=result] input").should("have.length", 16);
});
it("shows result when matrix changes", () => {
cy.get("[data-test=matrix] input").first().type(2);
cy.get("[data-test=result] input").first().should("have.value", 5);
});
it("shows result when kernel changes", () => {
cy.get("[data-test=kernel] input").first().type(2);
cy.get("[data-test=result] input").last().should("have.value", 5);
});
it("can change matrix size", () => {
cy.get("[data-test=matrix-size] input").first().type(2);
cy.get("[data-test=matrix-size] input").last().type(2);
cy.get("[data-test=matrix] input").should("have.length", 4);
});
it("can change kernel size", () => {
cy.get("[data-test=kernel-size] input").first().type(2);
cy.get("[data-test=kernel-size] input").last().type(2);
cy.get("[data-test=kernel] input").should("have.length", 4);
});
it("can toggle padding", () => {
cy.get("[data-test=padding]").click();
cy.get("[data-test=result] input").should("have.length", 4);
});
});

45
cypress/e2e/theme.cy.js Normal file
View File

@@ -0,0 +1,45 @@
const visit = (darkAppearance) =>
cy.visit("/", {
onBeforeLoad(win) {
cy.stub(win, "matchMedia")
.withArgs("(prefers-color-scheme: dark)")
.returns({
matches: darkAppearance,
addEventListener: () => {},
removeEventListener: () => {},
});
},
});
const isDarkMode = () => {
cy.get("html").should("have.attr", "theme", "dark");
cy.get("html").should("have.css", "background-color", "rgb(51, 51, 51)");
cy.get("html").should("have.css", "color", "rgb(238, 238, 238)");
};
const isLightMode = () => {
cy.get("html").should("have.attr", "theme", "light");
cy.get("html").should("have.css", "background-color", "rgb(255, 255, 255)");
cy.get("html").should("have.css", "color", "rgb(51, 51, 51)");
};
describe("Theme", () => {
it("is dark by default", () => {
cy.visit("/");
isDarkMode();
});
it("is light if user has set it in the browser", () => {
visit(false);
isLightMode();
});
it("can toggle", () => {
visit(true);
isDarkMode();
cy.get("[data-test=toggle-theme]").click();
isLightMode();
cy.get("[data-test=toggle-theme]").click();
isDarkMode();
});
});

View File

@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}

View File

@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js 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) => { ... })

20
cypress/support/e2e.js Normal file
View File

@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.js 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')