⚗️ Eksperimenterer litt med Cypress-testing for frontend

This commit is contained in:
Sindre Kjelsrud 2023-07-21 15:24:39 +02:00
parent 3cd3a5e933
commit 5fbe7eec72
8 changed files with 8454 additions and 408 deletions

View file

@ -0,0 +1,9 @@
import { defineConfig } from "cypress";
export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});

View file

@ -0,0 +1,43 @@
import { slowCypressDown } from 'cypress-slow-down'
// Notat: Husk å kjør opp frontend før tester
slowCypressDown() // gjør at testene ikke kjører dritfort
describe('Landingsside loader ordentlig', () => {
context('Resolution er 1080p', () => {
beforeEach(() => {
cy.viewport(1920, 1080)
})
it('passes', () => {
cy.visit('http://localhost:5173/')
})
})
})
describe('Klarer å navigere frem og tilbake til/fra "Meld inn feil"-side', () => {
context('Går til "Meld inn feil"-siden', () => {
beforeEach(() => {
cy.viewport(1920, 1080)
})
it('passes', () => {
cy.visit('http://localhost:5173/')
cy.contains('Meld inn feil').click()
})
})
context('Går tilbake til hovedsiden', () => {
beforeEach(() => {
cy.viewport(1920, 1080)
})
it('passes', () => {
cy.visit('http://localhost:5173/nyfeil')
cy.contains('Gå tilbake til hovedmenyen').click()
})
})
})

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,20 @@
// ***********************************************************
// This example support/e2e.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'
// Alternatively you can use CommonJS syntax:
// require('./commands')

6860
frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -10,32 +10,36 @@
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.14.0",
"axios": "^1.4.0",
"@navikt/aksel-icons": "^4.4.2", "@navikt/aksel-icons": "^4.4.2",
"@navikt/ds-css": "^4.4.2", "@navikt/ds-css": "^4.4.2",
"@navikt/ds-react": "^4.4.2", "@navikt/ds-react": "^4.4.2",
"@navikt/ds-tailwind": "^4.6.1", "@navikt/ds-tailwind": "^4.6.1",
"@navikt/ds-tokens": "^4.6.1", "@navikt/ds-tokens": "^4.6.1",
"tailwindcss": "3.3.2",
"swr": "^2.2.0",
"autoprefixer": "10.4.14", "autoprefixer": "10.4.14",
"postcss": "8.4.6" "axios": "^1.4.0",
"postcss": "8.4.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.14.0",
"swr": "^2.2.0",
"tailwindcss": "3.3.2"
}, },
"devDependencies": { "devDependencies": {
"@navikt/aksel-stylelint": "^4.5.0",
"@types/jest": "^29.5.3",
"@types/mocha": "^10.0.1",
"@types/react": "^18.2.14", "@types/react": "^18.2.14",
"@types/react-dom": "^18.2.6", "@types/react-dom": "^18.2.6",
"@typescript-eslint/eslint-plugin": "^5.61.0", "@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.61.0", "@typescript-eslint/parser": "^5.61.0",
"@vitejs/plugin-react": "^4.0.1", "@vitejs/plugin-react": "^4.0.1",
"cypress": "^12.17.2",
"cypress-slow-down": "^1.2.1",
"eslint": "^8.44.0", "eslint": "^8.44.0",
"eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.1", "eslint-plugin-react-refresh": "^0.4.1",
"stylelint": "^15.10.1",
"typescript": "^5.0.2", "typescript": "^5.0.2",
"vite": "^4.4.0", "vite": "^4.4.0"
"@navikt/aksel-stylelint": "^4.5.0",
"stylelint": "^15.10.1"
} }
} }

File diff suppressed because it is too large Load diff