Skip to content

Commit

Permalink
e2e testing
Browse files Browse the repository at this point in the history
  • Loading branch information
vvaldesc committed Jun 18, 2024
1 parent 0155f8b commit 42db30b
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 133 deletions.
Binary file removed TFC_gestor_academia.rar
Binary file not shown.
1 change: 0 additions & 1 deletion auth.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Facebook from '@auth/core/providers/facebook';
import Google from '@auth/core/providers/google';

import { defineConfig } from 'auth-astro';
Expand Down
17 changes: 15 additions & 2 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import { defineConfig } from 'cypress'

export default defineConfig({
chromeWebSecurity: false,
e2e: {
supportFile: false
}
baseUrl: 'https://localhost:4322',
// supportFile: "cypress/support/commands.js",
supportFile: false,
},
// env: {
// googleRefreshToken: 'xxxxxxx',
// googleClientId: 'xxxxxxx',
// googleClientSecret: 'xxxxxxx',
// },
video: false,
retries: {
runMode: 2,
openMode: 0,
},
})
19 changes: 15 additions & 4 deletions cypress/e2e/index.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
it('titles are correct', () => {
const page = cy.visit('https://localhost:4322');
page.get('title').should('have.text');
// page.get('h1').should('hytave.text');
describe('Página de inicio', () => {
beforeEach(() => {
// Visita la página de inicio antes de cada prueba
cy.visit('/')
})

it('El título de la página no está vacío', () => {
// Verifica que el título de la página no esté vacío
cy.title().should('not.be.empty');
});

it('El título de la página es correcto', () => {
// Verifica que el título de la página sea igual a 'Home'
cy.title().should('eq', 'Home');
});
});
80 changes: 80 additions & 0 deletions cypress/e2e/layout.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
const cookieValue = {
sessionState: 2,
sessionInfo: {
OAuth: { user: {
id: 1,
name: 'Víctor',
email: '[email protected]',
image: 'https://lh3.googleusercontent.com/a/ACg8ocKzfoTnzs-nio7LCynxeRM-_zVyswLSKkOOgStQ3fhxKbgzizZl1Q=s96-c',
}, expires: '2024-07-18T18:33:37.885Z' },
profile: {
id: 1,
name: 'Víctor',
surname: 'Valdés Cobos',
email: '[email protected]',
phone_number: '123459789',
address: '123 Main St',
city: 'New York',
bornDate: '1990-01-01T00:00:00.000Z',
created_at: '2024-06-08T23:11:00.000Z',
updated_at: '2024-06-08T23:11:00.000Z',
username: 'johndoedd',
image: '',
active: true
},
role: 'Clients',
profilePhotoSrc: 'https://lh3.googleusercontent.com/a/ACg8ocKzfoTnzs-nio7LCynxeRM-_zVyswLSKkOOgStQ3fhxKbgzizZl1Q=s96-c'
}
};

const APP_SELECTOR = '#App';
const HEADER_SELECTOR = 'header';
const FOOTER_SELECTOR = 'footer';
const PROFILETHUMB_SELECTOR = '#profileThumb_header';

describe('Layout', () => {
beforeEach(() => {
// Visita la página inicial antes de cada prueba
cy.visit('/')
cy.setCookie('sessionInfoState', JSON.stringify(cookieValue));
cy.visit('/')
})

it('Los títulos no están vacíos', () => {
// Verifica que el título de la página no esté vacío
cy.title().should('not.be.empty');
});

it('Main container is in DOM', () => {
// Verifica que el contenedor principal exista y sea visible
cy.get(APP_SELECTOR).should('exist').and('be.visible');
});

it('Header set', () => {
// Verifica que el encabezado exista
cy.get(HEADER_SELECTOR).should('exist').and('be.visible');
})

it('Footer set', () => {
// Verifica que el pie de página exista
cy.get(FOOTER_SELECTOR).should('exist').and('be.visible')
})

it('Profilephoto exists', () => {
// Verifica que la imagen exista
cy.get('#profileThumb_header')
.should('be.visible')
})
})

it('Profilephoto src is set', () => {
// Verifica que el atributo src del elemento img del encabezado exista
cy.visit('/')
cy.setCookie('sessionInfoState', JSON.stringify(cookieValue));
cy.visit('/')
cy.intercept('GET', 'https://lh3.googleusercontent.com/a/ACg8ocKzfoTnzs-nio7LCynxeRM-_zVyswLSKkOOgStQ3fhxKbgzizZl1Q=s96-c').as('getProfilePhoto');
cy.wait('@getProfilePhoto');
cy.get('#profileThumb_header')
.should('have.attr', 'srcset')
.and('be.a', 'image');
});
45 changes: 45 additions & 0 deletions cypress/e2e/perfil.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const cookieValue = {
sessionState: 2,
sessionInfo: {
OAuth: { user: {
id: 1,
name: 'Víctor',
email: '[email protected]',
image: 'https://lh3.googleusercontent.com/a/ACg8ocKzfoTnzs-nio7LCynxeRM-_zVyswLSKkOOgStQ3fhxKbgzizZl1Q=s96-c',
}, expires: '2024-07-18T18:33:37.885Z' },
profile: {
id: 1,
name: 'Víctor',
surname: 'Valdés Cobos',
email: '[email protected]',
phone_number: '123459789',
address: '123 Main St',
city: 'New York',
bornDate: '1990-01-01T00:00:00.000Z',
created_at: '2024-06-08T23:11:00.000Z',
updated_at: '2024-06-08T23:11:00.000Z',
username: 'johndoedd',
image: '',
active: true
},
role: 'Clients',
profilePhotoSrc: 'https://lh3.googleusercontent.com/a/ACg8ocKzfoTnzs-nio7LCynxeRM-_zVyswLSKkOOgStQ3fhxKbgzizZl1Q=s96-c'
}
};

const APP_SELECTOR = '#App';
const HEADER_SELECTOR = 'header';
const FOOTER_SELECTOR = 'footer';
const PROFILETHUMB_SELECTOR = '#profileThumb_registro';

describe('Perfil', () => {
beforeEach(() => {
cy.visit('/')
cy.setCookie('sessionInfoState', JSON.stringify(cookieValue));
cy.visit('/perfil')
});

it('should have main thumbnail', () => {
cy.get(PROFILETHUMB_SELECTOR).should('exist').and('be.visible');
});
});
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Cypress.Commands.add('loginByGoogleApi', () => {
cy.log('Logging in to Google')
cy.request({
method: 'POST',
url: 'https://www.googleapis.com/oauth2/v4/token',
body: {
grant_type: 'refresh_token',
client_id: Cypress.env('googleClientId'),
client_secret: Cypress.env('googleClientSecret'),
refresh_token: Cypress.env('googleRefreshToken'),
},
}).then(({ body }) => {
const { access_token, id_token } = body

cy.request({
method: 'GET',
url: 'https://www.googleapis.com/oauth2/v3/userinfo',
headers: { Authorization: `Bearer ${access_token}` },
}).then(({ body }) => {
cy.log(body)
const userItem = {
token: id_token,
user: {
googleId: body.sub,
email: body.email,
givenName: body.given_name,
familyName: body.family_name,
imageUrl: body.picture,
},
}

window.localStorage.setItem('googleCypress', JSON.stringify(userItem))
cy.visit('/')
})
})
})
Loading

0 comments on commit 42db30b

Please sign in to comment.