Skip to content

Commit fd19b62

Browse files
committed
*
1 parent c57d1fa commit fd19b62

File tree

9 files changed

+178
-3
lines changed

9 files changed

+178
-3
lines changed

README.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,57 @@ Aplicação web utilizando framework Angular e JSON Server para registro de prod
44

55
## Projeto Final
66

7+
Instalção json-server
8+
9+
```bash
10+
npm i -g json-server
11+
```
12+
13+
Instalação App
14+
15+
```bash
16+
cd frontend
17+
npm i
18+
```
19+
20+
Instalação Cypress
21+
22+
```bash
23+
npx cypress run
24+
```
25+
26+
Executar testes com Jasmine
27+
728
```bash
829
npm run test:cover
930
```
31+
32+
Executar testes com Cypress
33+
34+
```bash
35+
npm run server:json
36+
ng serve
37+
npx cypress run
38+
ou
39+
yarn cypress open
40+
```
41+
1042
### App
1143

1244
![](assets/app.PNG)
1345

1446
### Tests
1547

16-
![](assets/karma.PNG)
48+
![](assets/amgular-karma.PNG)
1749

1850
### Coverage
1951

20-
![](assets/coverage.PNG)
52+
![](assets/angular-coverage.PNG)
53+
54+
55+
### Cypress
56+
57+
![](assets/angular-cypress.PNG)
2158

2259

2360
## Github
File renamed without changes.

assets/angular-cypress.PNG

102 KB
Loading
File renamed without changes.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
describe('example to-do app', () => {
2+
beforeEach(() => {
3+
// Cypress inicia com uma folha em branco para cada teste
4+
// então devemos dizer a ele para visitar nosso website com o comando `cy.visit ()`.
5+
// Como queremos visitar o mesmo URL no início de todos os nossos testes,
6+
// nós o incluímos em nossa função beforeEach para que seja executado antes de cada teste
7+
// https://docs.cypress.io/api/commands
8+
cy.visit('http://localhost:4200/')
9+
})
10+
11+
it('Verifica título da App', () => {
12+
// Além de usar o comando `get` para obter um elemento por seletor,
13+
// também podemos usar o comando `contains` para obter um elemento por seu conteúdo.
14+
// No entanto, isso resultará em <label>, que é o elemento de nível mais baixo que contém o texto.
15+
// Para verificar o item, encontraremos o elemento <input> para este <label>
16+
// percorrendo o dom até o elemento pai. A partir daí, podemos `encontrar`
17+
// o elemento <input> da caixa de seleção filho e use o comando `check` para verificá-lo.
18+
cy.contains('Angular Testing')
19+
.parent()
20+
.find('.title') // encontra por css
21+
.should('have.text', 'Angular Testing')
22+
23+
cy.contains('Angular Testing')
24+
.parent()
25+
.find('#title') // encontra por id
26+
.should('have.text', 'Angular Testing')
27+
})
28+
29+
it('Verifica se lista de itens contém itens por padrão', () => {
30+
// Usamos o comando `cy.get ()` para obter todos os elementos que correspondem ao seletor.
31+
// Então, usamos `deveria` para afirmar que existem dois itens correspondentes,
32+
// quais são os dois itens padrão.
33+
cy.get('tr').should('have.length', 9) // linhas da tabela contando com o Header deve ser igual a 9 linhas
34+
35+
// Podemos ir ainda mais longe e verificar se cada padrão todos contém
36+
// o texto correto. Usamos as funções `primeiro` e` último`
37+
// para obter apenas o primeiro e o último elemento correspondido individualmente,
38+
// e então realizar uma asserção com `deveria`.
39+
cy.get('td').first().should('have.text', ' 9fd43452-b17b-4671-8e9a-bd1b63d557e0 ')
40+
})
41+
42+
it('Verifica adição de item', () => {
43+
const produto = { name:'IPhone X', price: 1000, quantity: 1000 }
44+
45+
// Vamos pegar o elemento de entrada e usar o comando `type` para
46+
// insira nosso novo item de lista. Depois de digitar o conteúdo do nosso item,
47+
// também precisamos digitar a chave enter para enviar a entrada.
48+
// Melhores práticas: https://on.cypress.io/selecting-elements
49+
cy.get('#btnAdicionar').click()
50+
cy.get('#mat-input-1').type(`${produto.name}`)
51+
cy.get('#mat-input-2').type(`${produto.price}`)
52+
cy.get('#mat-input-3').type(`${produto.quantity}`)
53+
cy.get('#action-button').click()
54+
55+
// Agora que digitamos nosso novo item, vamos verificar se ele realmente foi adicionado à lista.
56+
// Por ser o item mais recente, ele deve existir como o último elemento da lista.
57+
// Além disso, com os 9 itens padrão, devemos ter um total de 10 elementos na lista.
58+
//cy.get('tr').should('have.length', 10) // linhas da tabela após adicionar item
59+
60+
//remove o item adicionado para deixar teste repetitível
61+
cy.wait(1000)
62+
//cy.wait('@actions')
63+
cy.get('tr').last().find('a').last().click()
64+
//cy.wait(5000)
65+
cy.get('#action-button').click()
66+
cy.get('tr').should('have.length', 9) // linhas da tabela contando com o Header deve ser igual a 9 linhas
67+
68+
69+
})
70+
71+
})

frontend/cypress/plugins/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************************
3+
// This example plugins/index.js can be used to load plugins
4+
//
5+
// You can change the location of this file or turn off loading
6+
// the plugins file with the 'pluginsFile' configuration option.
7+
//
8+
// You can read more here:
9+
// https://on.cypress.io/plugins-guide
10+
// ***********************************************************
11+
12+
// This function is called when a project is opened or re-opened (e.g. due to
13+
// the project's config changing)
14+
15+
/**
16+
* @type {Cypress.PluginConfig}
17+
*/
18+
// eslint-disable-next-line no-unused-vars
19+
module.exports = (on, config) => {
20+
// `on` is used to hook into various events Cypress emits
21+
// `config` is the resolved Cypress config
22+
}

frontend/cypress/support/commands.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ***********************************************
2+
// This example commands.js shows you how to
3+
// create various custom commands and overwrite
4+
// existing commands.
5+
//
6+
// For more comprehensive examples of custom
7+
// commands please read more here:
8+
// https://on.cypress.io/custom-commands
9+
// ***********************************************
10+
//
11+
//
12+
// -- This is a parent command --
13+
// Cypress.Commands.add('login', (email, password) => { ... })
14+
//
15+
//
16+
// -- This is a child command --
17+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
18+
//
19+
//
20+
// -- This is a dual command --
21+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
22+
//
23+
//
24+
// -- This will overwrite an existing command --
25+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })

frontend/cypress/support/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/index.js is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

frontend/src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<div class="container text-center">
1818

1919
<div class="btn-actions">
20-
<button mat-button (click)="openDialog('Adicionar',{})" mat-flat-button color="primary">Adicionar Produto</button>
20+
<button mat-button id="btnAdicionar" (click)="openDialog('Adicionar',{})" mat-flat-button color="primary">Adicionar Produto</button>
2121
</div>
2222

2323
<table mat-table [dataSource]="products" #mytable class="my-table mat-elevation-z8">

0 commit comments

Comments
 (0)