Add cypress to client for component and frontend tests
This commit is contained in:
parent
d6b45f9f7f
commit
5922678363
|
|
@ -0,0 +1,10 @@
|
||||||
|
import { defineConfig } from "cypress";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
component: {
|
||||||
|
devServer: {
|
||||||
|
framework: "vue",
|
||||||
|
bundler: "vite",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"baseUrl": "http://localhost:5050"
|
|
||||||
}
|
|
||||||
|
|
@ -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"
|
||||||
|
}
|
||||||
|
|
@ -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>
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
@ -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>
|
||||||
|
|
@ -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)
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -15,7 +15,8 @@
|
||||||
"prettier:check": "prettier . --check",
|
"prettier:check": "prettier . --check",
|
||||||
"tailwind": "tailwindcss -i tailwind.css -o ../server/vbv_lernwelt/static/css/tailwind.css --watch",
|
"tailwind": "tailwindcss -i tailwind.css -o ../server/vbv_lernwelt/static/css/tailwind.css --watch",
|
||||||
"storybook": "storybook dev -p 6006",
|
"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": {
|
"dependencies": {
|
||||||
"@headlessui/tailwindcss": "^0.1.2",
|
"@headlessui/tailwindcss": "^0.1.2",
|
||||||
|
|
@ -24,6 +25,7 @@
|
||||||
"@sentry/vue": "^7.20.0",
|
"@sentry/vue": "^7.20.0",
|
||||||
"@urql/vue": "^1.0.2",
|
"@urql/vue": "^1.0.2",
|
||||||
"@vueuse/core": "^9.13.0",
|
"@vueuse/core": "^9.13.0",
|
||||||
|
"cypress": "^12.9.0",
|
||||||
"d3": "^7.6.1",
|
"d3": "^7.6.1",
|
||||||
"dayjs": "^1.11.7",
|
"dayjs": "^1.11.7",
|
||||||
"graphql": "^16.6.0",
|
"graphql": "^16.6.0",
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -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],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue