Skip to content

Add Cypress tests for UI interactions and form validations#2

Open
brunonf15 wants to merge 10 commits intowlsf82:mainfrom
brunonf15:main
Open

Add Cypress tests for UI interactions and form validations#2
brunonf15 wants to merge 10 commits intowlsf82:mainfrom
brunonf15:main

Conversation

@brunonf15
Copy link

@brunonf15 brunonf15 commented Mar 15, 2025

Updated Pull Request Description:

Summary:
This PR enhances and refines Cypress tests to validate key UI functionalities, including form validations, messenger interactions, footer verification, and responsive table behavior.

Changes include:

  • 🛠 Improved button selection strategies using CSS attribute selectors instead of relying on data-testid.
  • 📩 Enhanced messenger interactions (open, close, submit, reset behavior).
  • 🔍 More robust footer link verification (ensuring correct attributes and behavior).
  • 📱 Updated responsive table test (confirming correct columns are shown/hidden in mobile view).

How to Test:

  1. Run npm run cypress:open or npx cypress run.
  2. Verify that all tests pass in the Cypress Test Runner.

Why?

  • Improves test reliability by using CSS attribute selectors instead of relying solely on data-testid.
  • Ensures the UI behaves correctly across different scenarios.
  • Helps catch regressions in future updates.

Reviewer Notes:

  • Focus on how I mapped the buttons without data-testid, using:
    cy.get('[class^="Messenger_openCloseButton"]') 

Copy link
Owner

@wlsf82 wlsf82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bom trabalho @brunonf15! 🎉

No entanto, deixei uma série de comentários ao longo do seu código, os quais creio que lhe ajudarão a melhorar o design do mesmo.

Obs.: Só faça novas alterações depois do encontro de hoje da Test Design Masterclass.

@brunonf15 brunonf15 requested a review from wlsf82 March 21, 2025 16:01
Copy link
Owner

@wlsf82 wlsf82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bom trabalho @brunonf15! 👏🏻 👏🏻

No entanto, deixei novos comentários, os quais creio que lhe ajudarão a melhorar ainda mais o design dos testes.

Lembre-se de aplicar as mudanças sugeridas somente após o terceiro encontro da Test Design Masterclass da TAT.

Adding new scripts to run API and gui tests
Adding new scripts to run Cypress tests
Rename api and gui tests
Updating the readme
Renaming the tests cases acording to the list
Adding some extra spactes to improve the readbility of the tests
Using a command
Adding more spaces to improve the readability of the code
Copy link
Owner

@wlsf82 wlsf82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bom demais @brunonf15! Com ajustes de pequenos detalhes essa suíte de testes ficará 🔝

👏🏻 👏🏻 👏🏻

### Installing Cypress

1. Install Cypress as a development dependency by running:
```bash
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```bash
```bash

```bash
npm install
```

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uma linha em branco já é o suficiente.

Suggested change


- **API Tests**: Located in `cypress/e2e/api/engageSphere.cy.js`.
- **GUI Tests**: Located in `cypress/e2e/gui/engageSphere.cy.js`.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O mesmo aqui.

Suggested change

```bash
npm test
```

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

```bash
npm run test:api
```

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

cy.getByClassThatStartsWith('Messenger_success')
.should('be.visible')
.and('contain', 'Your message has been sent.');
cy.tick(3000);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cy.tick(3000);
cy.tick(3000);

Deixando uma linha pra separar o assert.

});

it('Limpa todos os campos do formulário do messenger ao preenchê-los, fechar o messenger e abri-lo novamente', () => {
cy.getByClassThatStartsWith('Messenger_openCloseButton').click();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cy.getByClassThatStartsWith('Messenger_openCloseButton').click();
// Arrange
cy.getByClassThatStartsWith('Messenger_openCloseButton').click();
// Act

cy.getByClassThatStartsWith('Messenger_openCloseButton').click();
cy.getByClassThatStartsWith('Messenger_openCloseButton').click();

cy.get('#messenger-name').should('have.value', '');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E então:

Suggested change
cy.get('#messenger-name').should('have.value', '');
// Assert
cy.get('#messenger-name').should('have.value', '');

cy.contains('th', 'Size').should('not.be.visible');
});

it('Bug - Edit name bloquado apos filtro não retornar dados', () => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A descrição do caso de teste deve ser do comportamento sendo testado, não a descrição do bug.

Algo como:

Suggested change
it('Bug - Edit name bloquado apos filtro não retornar dados', () => {
it('Reativa o campo de entrada ao retornar de um filtro de estado vazio para um não vazio', () => {

@@ -0,0 +1,3 @@
Cypress.Commands.add('getByClassThatStartsWith', classPart => {
cy.get(`[class^="${classPart}"]`)
}) No newline at end of file
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
})
})

});
});

it('Trata requisições inválidas (por exemplo, página negativa)', () => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Que tal criar também casos de testes para os cenários onde page e limit são iguais a 0?

}
}).then((response) => {
const totalCustomers = response.body.pageInfo.totalCustomers;
const expectedTotalPages = Math.ceil(totalCustomers / limit);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicarei com detalhes esse teste no encontro de amanhã.

module.exports = defineConfig({
e2e: {
baseUrl: "http://localhost:3000",
supportFile: false,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Visto que você criou o comando customizado, remova esta configuração, crie o arquivo cypress/support/e2e.js e dentro dele importe o arquivo cypress/support/commands.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants