Add cypress to client for component and frontend tests

This commit is contained in:
Ramon Wenger 2023-04-06 14:57:01 +02:00
parent d6b45f9f7f
commit 5922678363
10 changed files with 1512 additions and 257 deletions

10
client/cypress.config.ts Normal file
View File

@ -0,0 +1,10 @@
import { defineConfig } from "cypress";
export default defineConfig({
component: {
devServer: {
framework: "vue",
bundler: "vite",
},
},
});

View File

@ -1,3 +0,0 @@
{
"baseUrl": "http://localhost:5050"
}

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,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>
// }
// }
// }

View File

@ -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>

View File

@ -0,0 +1,54 @@
// ***********************************************************
// 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 "../../tailwind.css";
import "./commands";
// Alternatively you can use CommonJS syntax:
// require('./commands')
import { setupI18n } from "@/i18n.ts";
import router from "@/router";
import { mount } from "cypress/vue";
import { createPinia } from "pinia";
// 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", (component, options = {}) => {
options.global = options.global || {};
options.global.plugins = options.global.plugins || [];
options.global.plugins.push(setupI18n());
options.global.plugins.push(createPinia());
if (!options.router) {
options.router = router;
}
return mount(component, options);
});
// Example use:
// cy.mount(MyComponent)

1582
client/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,8 @@
"prettier:check": "prettier . --check",
"tailwind": "tailwindcss -i tailwind.css -o ../server/vbv_lernwelt/static/css/tailwind.css --watch",
"storybook": "storybook dev -p 6006",
"build-storybook": "rm -rf ../server/vbv_lernwelt/static/storybook/* && storybook build -o ../server/vbv_lernwelt/static/storybook"
"build-storybook": "rm -rf ../server/vbv_lernwelt/static/storybook/* && storybook build -o ../server/vbv_lernwelt/static/storybook",
"cypress:open": "cypress open"
},
"dependencies": {
"@headlessui/tailwindcss": "^0.1.2",
@ -24,6 +25,7 @@
"@sentry/vue": "^7.20.0",
"@urql/vue": "^1.0.2",
"@vueuse/core": "^9.13.0",
"cypress": "^12.9.0",
"d3": "^7.6.1",
"dayjs": "^1.11.7",
"graphql": "^16.6.0",

View File

@ -0,0 +1,40 @@
import avatar from "../../../.storybook/uk1.patrizia.huggel.jpg";
import AccountMenuContent from "./AccountMenuContent.vue";
const bern = {
id: 1,
title: "Bern 2023 a",
};
let selectedSession = bern;
const courseSessions = [
bern,
{
id: 2,
title: "Zürich 2023 a",
},
];
const user = {
first_name: "Vreni",
last_name: "Schmid",
email: "vreni.schmid@example.com",
avatar_url: avatar,
loggedIn: true,
};
const selectCourseSession = (session) => {
selectedSession = session;
console.log("session");
};
describe("<AccountMenuContent />", () => {
it("renders", () => {
// see: https://on.cypress.io/mounting-vue
cy.mount(AccountMenuContent, {
props: {
user,
courseSessions,
selectedCourseSession: selectedSession,
onSelectCourseSession: selectCourseSession,
},
});
});
});

View File

@ -0,0 +1,22 @@
import router from "@/router";
import { createPinia } from "pinia";
import { markRaw } from "vue";
import MainNavigationBar from "./MainNavigationBar.vue";
describe("<MainNavigationBar />", () => {
it("renders", async () => {
const pinia = createPinia();
pinia.use(({ store }) => {
store.router = markRaw(router);
});
router.push("/");
await router.isReady();
// see: https://on.cypress.io/mounting-vue
cy.mount(MainNavigationBar, {
router: router,
global: {
plugins: [pinia],
},
});
});
});