Skip to content

A01412492 - caso prueba porcentaje #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions projects/calculator/cypress/e2e/porc.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
describe('Prueba de porcentaje valida', () => {
it('passes', () => {
cy.visit('http://localhost:3001/')
cy.contains('AC').click()
cy.contains('2').click()
cy.contains('%').click()
cy.get('.component-display').first().should('have.text', '0.02')
})
})


describe('Prueba que de falso', () => {
it('passes', () => {
cy.visit('http://localhost:3001/')
cy.contains('AC').click()
cy.contains('3').click()
cy.contains('5').click()
cy.contains('x').click()
cy.contains('4').click()
cy.contains('=').click()
cy.get('.component-display').first().should('have.text', '10')
})
})

Cypress.Commands.add('click_bigger_number',(number) => {
const tmp = number.toString();
for (let i = 0; i < tmp.length; i++){
cy.get('.component-button-panel').contains(tmp[i]).click()
}
})


describe('Porcentaje con regla de tres', () => {
it('passes', () => {
cy.visit('http://localhost:3001/')

// Numero random del 1 al 50 se guarda en una variable para el primer operando
const operando = Math.floor(Math.random() * 50) + 1;
// Numero random del 1 al 100 se guarda la variable para el operador porcentual
const porcentual = Math.floor(Math.random() * 100) + 1;
// Por medio de regla de tres sacas el resultado y lo guardas en una variable
const resultado = (operando * porcentual) / 100;
// Utilizas la calculadora para obtener los porcentajes
cy.contains('AC').click()
cy.click_bigger_number(porcentual)
cy.contains('%').click()
cy.contains('x').click()
cy.click_bigger_number(operando)
cy.contains('=').click()
// Al final comparas el resultado de la regla de 3 contra lo obtenido en el display
cy.get('.component-display').first().should('have.text', resultado.toString())
})
})
Loading