Skip to content

Commit ff15854

Browse files
committed
feat: first atempt write tests applying screenplay pattern
1 parent 7066d0c commit ff15854

File tree

8 files changed

+149
-0
lines changed

8 files changed

+149
-0
lines changed

cypress/fixtures/repositorios.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"lista": [
3+
"thiagojacinto/es6-review",
4+
"cypress-io/cypress-example-recipes",
5+
"rust-lang/rust",
6+
"hapijs/hapi",
7+
"cli/cli"
8+
]
9+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Tarefa, Agente } from "../../../../support/screenplay"; //eslint-disable-line
2+
/**
3+
* @class {Tarefa} que representa navegar para homescreen.
4+
*/
5+
export class AcessarHome extends Tarefa {
6+
/**
7+
* Navega para a homescreen.
8+
* @param {Agente} agente
9+
* @returns {Agente} agente
10+
*/
11+
executaComo(agente) {
12+
cy.visit(""); // cypress.json setting baseUrl
13+
cy.viewport("samsung-note9");
14+
return agente;
15+
}
16+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Agente from "../../../../support/screenplay/agente/Agente"; //eslint-disable-line
2+
import { Tarefa } from "../../../../support/screenplay/tarefa";
3+
import { ELEMENTS } from "../../componentes/home.componentes";
4+
/**
5+
* @class {Tarefa} que retorna os repositórios expostos na lista.
6+
*/
7+
export class ExibirLista extends Tarefa {
8+
/**
9+
* Insere o número esperado a ser exibido na lista
10+
* @param {number} quantidade de repositórios a serem exibidos
11+
* @default 1
12+
*/
13+
contendo(numero = 1) {
14+
this.numero = numero;
15+
}
16+
17+
/**
18+
* Ver.
19+
* @param {Agente} agente
20+
* @returns {Agente} agente
21+
*/
22+
executaComo(agente) {
23+
cy.get(ELEMENTS.listItems, { timeout: 3000 }).should(
24+
"have.length",
25+
this.numero || 1
26+
);
27+
return agente;
28+
}
29+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { ExibirLista } from "./ExibirLista.tarefa";
2+
/**
3+
* @class ExibirListaContendoTresItems
4+
* @classdesc extende o comportamento da class ExibirLista e verifica se a lista apresenta 3 items.
5+
*/
6+
export class ExibirListaContendoTres extends ExibirLista {
7+
constructor() {
8+
super();
9+
this.numero = 3;
10+
}
11+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import Agente from "../../../../support/screenplay/agente/Agente"; //eslint-disable-line
2+
import { Tarefa } from "../../../../support/screenplay/tarefa";
3+
import { ELEMENTS } from "../../componentes/home.componentes";
4+
/**
5+
* @class {Tarefa} que representa inserir novo repositório a lista.
6+
*/
7+
export class InserirNovoRepositorio extends Tarefa {
8+
/**
9+
* Insere o username do usuário do GitHub
10+
* @param {string} username do usuario no GitHub
11+
* @default "cypress-io"
12+
*/
13+
doUsuario(usuario = "cypress-io") {
14+
this.usuario = usuario;
15+
return this;
16+
}
17+
/**
18+
* Insere o repositório do usuário disponível publicamente no GitHub
19+
* @param {string} repositorio mesmo nome público do repositório disponível no GitHub
20+
* @default "cypress-example-recipes"
21+
*/
22+
comNome(repositorio = "cypress-example-recipes") {
23+
this.repositorio = repositorio;
24+
return this;
25+
}
26+
27+
/**
28+
* Adiciona novo repositório.
29+
* @param {Agente} agente
30+
* @returns {Agente} agente
31+
*/
32+
executaComo(agente) {
33+
cy.fixture("repositorios.json").then(data => {
34+
let random = Math.floor(Math.random() * data.lista.length);
35+
// let [usuario, repositorio] = data.lista[random].split("/");
36+
// cy.get(ELEMENTS.input).type(`${usuario}/${repositorio}`);
37+
cy.get(ELEMENTS.input).type(data.lista[random]);
38+
});
39+
cy.get(ELEMENTS.submitButton)
40+
.focus()
41+
.click()
42+
.wait(200);
43+
cy.get(ELEMENTS.listItems, { timeout: 3000 });
44+
return agente;
45+
}
46+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from "./AcessarHome.tarefa";
2+
export * from "./InserirNovoRepositorio.tarefa";
3+
export * from "./ExibirLista.tarefa";
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* eslint-disable no-undef */
2+
/// <reference types="cypress" />
3+
import { e, dado, quando, entao, Usuario } from "../../../support/screenplay";
4+
import { AcessarHome, ExibirLista, InserirNovoRepositorio } from "./Tarefas";
5+
import { ExibirListaContendoTres } from "./Tarefas/ExibirListaContendoTres.tarefa";
6+
7+
describe("Adicionar", () => {
8+
describe("Dado que esteja na home", () => {
9+
const usuario = new Usuario("Thiago");
10+
11+
beforeEach(() => {
12+
dado(usuario).tenta(AcessarHome);
13+
});
14+
15+
it("Adicionar repositório a lista", () => {
16+
quando(usuario).tenta(InserirNovoRepositorio);
17+
entao(usuario).deve(ExibirLista);
18+
});
19+
20+
it("Adicionar mais de um repositório a lista", () => {
21+
quando(usuario).tenta(InserirNovoRepositorio);
22+
e(usuario).tenta(InserirNovoRepositorio);
23+
e(usuario).tenta(InserirNovoRepositorio);
24+
entao(usuario).deve(ExibirListaContendoTres);
25+
});
26+
});
27+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export const ELEMENTS = {
2+
input: "input#repository__input",
3+
submitButton: "button#btn__add",
4+
clearButton: "button#btn__clear_all",
5+
unorderedList: "ul#repo__list",
6+
listItems: "ul#repo__list li",
7+
listItemRemoveButton: `[name="btn__remove"]`
8+
};

0 commit comments

Comments
 (0)