-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from wizelineacademy/pruebas-julio
chore: Added configurations for cypress login and subscription functions
- Loading branch information
Showing
5 changed files
with
139 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: '[email protected]', | ||
}, | ||
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', () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: '[email protected]', | ||
}, | ||
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, | ||
}, | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |