⚗️ Eksperimenterer litt med Cypress-testing for frontend
This commit is contained in:
parent
3cd3a5e933
commit
5fbe7eec72
8 changed files with 8454 additions and 408 deletions
43
frontend/cypress/e2e/testspec.cy.ts
Normal file
43
frontend/cypress/e2e/testspec.cy.ts
Normal 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()
|
||||
})
|
||||
})
|
||||
})
|
5
frontend/cypress/fixtures/example.json
Normal file
5
frontend/cypress/fixtures/example.json
Normal 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"
|
||||
}
|
37
frontend/cypress/support/commands.ts
Normal file
37
frontend/cypress/support/commands.ts
Normal 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>
|
||||
// }
|
||||
// }
|
||||
// }
|
20
frontend/cypress/support/e2e.ts
Normal file
20
frontend/cypress/support/e2e.ts
Normal 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')
|
Reference in a new issue