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

7
cypress.config.js Normal file
View File

@@ -0,0 +1,7 @@
const { defineConfig } = require("cypress");
module.exports = defineConfig({
e2e: {
baseUrl: "http://localhost:8080/",
},
});

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')

3215
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -6,11 +6,13 @@
"build": "rollup -c",
"dev": "rollup -c -w",
"start": "sirv public --no-clear",
"deploy": "gh-pages -d public"
"deploy": "gh-pages -d public",
"cypress:open": "cypress open"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.0.0",
"cypress": "^10.3.1",
"rollup": "^2.3.4",
"rollup-plugin-css-only": "^3.1.0",
"rollup-plugin-livereload": "^2.0.0",

View File

@@ -68,10 +68,10 @@
<h5 style="grid-area: matrix-title">Matrix</h5>
<h5 style="grid-area: kernel-title">Kernel</h5>
<h5 style="grid-area: result-title">Result</h5>
<div style="grid-area: matrix-size">
<div style="grid-area: matrix-size" data-test="matrix-size">
<MatrixSizeInput bind:matrixWidth bind:matrixHeight />
</div>
<div style="grid-area: kernel-size">
<div style="grid-area: kernel-size" data-test="kernel-size">
<MatrixSizeInput
bind:matrixWidth={kernelWidth}
bind:matrixHeight={kernelHeight}
@@ -80,14 +80,22 @@
<div style="grid-area: result-size">
{result[0].length} &times; {result.length}
</div>
<div style="grid-area: matrix"><Matrix bind:matrix /></div>
<div style="grid-area: kernel"><Matrix bind:matrix={kernel} /></div>
<div style="grid-area: result">
<div style="grid-area: matrix" data-test="matrix">
<Matrix bind:matrix />
</div>
<div style="grid-area: kernel" data-test="kernel">
<Matrix bind:matrix={kernel} />
</div>
<div style="grid-area: result" data-test="result">
<Matrix matrix={result} readonly="true" />
</div>
<div style="grid-area: padding">
<label>
<input type="checkbox" bind:checked={addPadding} />
<input
type="checkbox"
bind:checked={addPadding}
data-test="padding"
/>
Padding
</label>
<div>

View File

@@ -3,15 +3,15 @@
let { toggle, current } = getContext("theme");
</script>
<button on:click={toggle} title="Toggle Theme">
<button on:click={toggle} title="Toggle Theme" data-test="toggle-theme">
<slot>{$current}</slot>
</button>
<style>
button {
border: none;
background: none;
font-weight: 600;
cursor: pointer;
}
</style>
button {
border: none;
background: none;
font-weight: 600;
cursor: pointer;
}
</style>