Skip to content

Commit

Permalink
Merge pull request #152 from wizelineacademy/pruebas-julio
Browse files Browse the repository at this point in the history
chore: Added configurations for cypress login and subscription functions
  • Loading branch information
JulioEmmmanuel authored Jun 11, 2024
2 parents 99ae01c + 6b81e95 commit 77c20a3
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 60 deletions.
25 changes: 2 additions & 23 deletions cypress/e2e/CreateChallenge.cy.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
/// <reference types="cypress" />

describe('CreateChallenge Component', () => {
beforeEach(() => {
// Intercepta la llamada de autenticación de Google y devuelve una respuesta simulada
cy.intercept('GET', '/api/auth/session', (req) => {
req.reply({
statusCode: 200,
body: {
user: {
name: 'Test User',
email: 'test@example.com',
},
expires: '2099-01-01T00:00:00.000Z',
},
})
}).as('googleLogin')

cy.visit('/login')

// Simula el inicio de sesión con Google
cy.get('button').contains('Continuar con Google').click()

// Espera a que la solicitud de inicio de sesión sea interceptada y respondida
cy.wait('@googleLogin')
cy.login()
cy.visit('/home/createChallenge')
cy.getSubscription()
})

it('should submit the form with valid input', () => {
Expand Down
90 changes: 90 additions & 0 deletions cypress/e2e/InputSleepHours.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/// <reference types="cypress" />

describe('Sleep hours', () => {
beforeEach(() => {
cy.login()
// Visitar página de ingresar horas de sueño
cy.visit('/sleep/records')
cy.getSubscription()
})

it('should submit the form with valid input', () => {
cy.intercept('POST', '/api/records', {}).as('sendRecord')

// Llena los inputs con valores válidos
const sleepInput = cy
.get('label')
.contains('¿A qué hora te acostaste?')
.next()
.find('input')
sleepInput.type('22:00')

const wakeupInput = cy
.get('label')
.contains('¿A qué hora te levantaste?')
.next()
.find('input')
wakeupInput.type('06:00')

//Hacer click en el botón de enviar
cy.get('button').contains('Enviar').click()

// Verifica que se muestre un mensaje de éxito después de enviar el formulario
cy.contains('Éxito').should('be.visible')
})

it('should calculate the correct amount of sleep hours for valid input', () => {
cy.intercept('POST', '/api/records', {}).as('sendRecord')

// Llena los inputs con valores válidos
const sleepInput = cy
.get('label')
.contains('¿A qué hora te acostaste?')
.next()
.find('input')
sleepInput.type('22:00')

const wakeupInput = cy
.get('label')
.contains('¿A qué hora te levantaste?')
.next()
.find('input')
wakeupInput.type('06:00')

//Hacer click en el botón de enviar
cy.get('button').contains('Enviar').click()

// Verifica que se muestre la cantidad de horas correcta
cy.contains('8.0 horas').should('be.visible')
})

it('should return an error if the second time is less than the first time', () => {
cy.intercept('POST', '/api/records', {}).as('sendRecord')

// Llenar los inputs con una hora de hoy
const sleepInput = cy
.get('label')
.contains('¿A qué hora te acostaste?')
.next()
.find('input')
sleepInput.type('22:00')
sleepInput.siblings('button').contains('Hoy').click()

// Llenar los inputs con una hora de ayer
const wakeupInput = cy
.get('label')
.contains('¿A qué hora te levantaste?')
.next()
.find('input')
wakeupInput.type('06:00')
wakeupInput.siblings('button').contains('Ayer').click()

//Hacer click en el botón de enviar
cy.get('button').contains('Enviar').click()

// Verifica que se muestre un mensaje de error
cy.contains(
'La cantidad de horas de sueño debe ser mayor o igual a 0',
).should('be.visible')
})
})
73 changes: 37 additions & 36 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
/// <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>
// }
// }
// }

Cypress.Commands.add('login', () => {
// Intercepta la llamada de autenticación de Google y devuelve una respuesta simulada
cy.intercept('GET', '/api/auth/session', (req) => {
req.reply({
statusCode: 200,
body: {
user: {
name: 'Test User',
email: 'test@example.com',
},
expires: '2099-01-01T00:00:00.000Z',
},
})
}).as('googleLogin')

cy.visit('/login')

// Simula el inicio de sesión con Google
cy.get('button').contains('Continuar con Google').click()

// Espera a que la solicitud de inicio de sesión sea interceptada y respondida
cy.wait('@googleLogin')
})

Cypress.Commands.add('getSubscription', () => {
cy.intercept('GET', '/api/subscription', (req) => {
req.reply({
statusCode: 200,
body: {
plan: 'Bienestar Total',
status: 'active',
end: null,
},
})
})
})
2 changes: 1 addition & 1 deletion cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
// require('./commands')
9 changes: 9 additions & 0 deletions cypress/support/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// support/index.d.ts
/// <reference types="cypress" />

declare namespace Cypress {
interface Chainable {
login(): void
getSubscription(): void
}
}

0 comments on commit 77c20a3

Please sign in to comment.