Skip to content

Commit

Permalink
Cypress new patter for testing entities
Browse files Browse the repository at this point in the history
  • Loading branch information
suissa committed Jan 20, 2024
1 parent 702702a commit a345f46
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 112 deletions.
23 changes: 9 additions & 14 deletions cypress/e2e/integrations/companies.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,30 @@ const LOGIN_URL = `${BASE_URL}:9000/login`
const API_URL = `${BASE_URL}:9000/companies`
const TEST_URL = `${BASE_URL}:3000/companies`
const BUTTON = "Nova Empresa"
const ENTITY = { _id: "1", name: "Empresa 1", phone: "123456789", status: "Ativo", dueDate: "16/01/2024", recurrence: "Mensal"}
const ENTITY_PLURAL_NAME = "Mensagens"
const TEST_NAME = `Página de ${ENTITY_PLURAL_NAME}`

describe("Página de Empresas", () => {
describe(TEST_NAME, () => {
beforeEach(() => {

cy.fixture("token").then((token) => {
console.log(token);
cy.intercept("POST", `${LOGIN_URL}`, {
statusCode: 200,
body: {
token: token.token
}
body: { token: token.token }
});

cy.intercept("GET", `${API_URL}`, {
statusCode: 200,
body: [
{ _id: "1", name: "Empresa 1", phone: "123456789", status: "Ativo", dueDate: "16/01/2024", recurrence: "Mensal"},
]
}).as("getCompanies");
body: [ ENTITY ]
}).as("getPlans");

localStorage.setItem("token", token.token);
cy.visit(`${TEST_URL}`);

cy.wait("@getCompanies");
})

});

it("deve exibir uma lista de empresas", () => {
it(`deve exibir uma lista de ${ENTITY_PLURAL_NAME}`, () => {
cy.get("table").should("exist");
cy.get("table tbody tr").should("have.length.at.least", 1);
});
Expand All @@ -54,4 +49,4 @@ describe("Página de Empresas", () => {
cy.get("table").should("exist");
cy.get("form").should("not.exist");
});
});
});
24 changes: 10 additions & 14 deletions cypress/e2e/integrations/connections.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,30 @@ const LOGIN_URL = `${BASE_URL}:9000/login`
const API_URL = `${BASE_URL}:9000/connections`
const TEST_URL = `${BASE_URL}:3000/connections`
const BUTTON = "Nova Conexão"
const ENTITY = { _id: "1", name: "Conexão 1", phone: "123456789", instanceName: "Conexao_1-123456789" }
const ENTITY_PLURAL_NAME = "Mensagens"
const TEST_NAME = `Página de ${ENTITY_PLURAL_NAME}`

describe("Página de Conexões", () => {
describe(TEST_NAME, () => {
beforeEach(() => {
cy.fixture("token").then((token) => {
console.log(token);
cy.intercept("POST", `${LOGIN_URL}`, {
statusCode: 200,
body: {
token: token.token
}
body: { token: token.token }
});

cy.intercept("GET", `${API_URL}`, {
statusCode: 200,
body: [
{ _id: "1", name: "Conexão 1", phone: "123456789", instanceName: "Conexao_1-123456789" },
]
}).as("getConnections");
body: [ ENTITY ]
}).as("getPlans");

localStorage.setItem("token", token.token);
cy.visit(`${TEST_URL}`);

// Espera a requisição GET /api/connections ser chamada
// cy.wait("@getConnections", { timeout: 10000 });
});
})
});

it("deve exibir uma lista de conexões", () => {
it(`deve exibir uma lista de ${ENTITY_PLURAL_NAME}`, () => {
cy.get("table").should("exist");
cy.get("table tbody tr").should("have.length.at.least", 1);
});
Expand All @@ -53,4 +49,4 @@ describe("Página de Conexões", () => {
cy.get("table").should("exist");
cy.get("form").should("not.exist");
});
});
});
27 changes: 9 additions & 18 deletions cypress/e2e/integrations/contacts.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,30 @@ const LOGIN_URL = `${BASE_URL}:9000/login`
const API_URL = `${BASE_URL}:9000/contacts`
const TEST_URL = `${BASE_URL}:3000/contacts`
const BUTTON = "Novo Contato"
const ENTITY = { _id: "1", name: "Contato 1", phone: "123456789"}
const ENTITY_PLURAL_NAME = "Mensagens"
const TEST_NAME = `Página de ${ENTITY_PLURAL_NAME}`

describe("Página de Contatos", () => {
describe(TEST_NAME, () => {
beforeEach(() => {

cy.fixture("token").then((token) => {
console.log(token);
cy.intercept("POST", `${LOGIN_URL}`, {
statusCode: 200,
body: {
token: token.token
}
body: { token: token.token }
});

cy.intercept("GET", `${API_URL}`, {
statusCode: 200,
body: [
{ _id: "1", name: "Contato 1", phone: "123456789"},
]
}).as("getContacts");
body: [ ENTITY ]
}).as("getPlans");

localStorage.setItem("token", token.token);
cy.visit(`${TEST_URL}`);

cy.wait("@getContacts");
})

});

Cypress.on("uncaught:exception", (err, runnable) => {
console.log("uncaught:exception:", err);
return false;
});
it("deve exibir uma lista de contatos", () => {
it(`deve exibir uma lista de ${ENTITY_PLURAL_NAME}`, () => {
cy.get("table").should("exist");
cy.get("table tbody tr").should("have.length.at.least", 1);
});
Expand All @@ -58,4 +49,4 @@ describe("Página de Contatos", () => {
cy.get("table").should("exist");
cy.get("form").should("not.exist");
});
});
});
25 changes: 10 additions & 15 deletions cypress/e2e/integrations/messages.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,30 @@ const LOGIN_URL = `${BASE_URL}:9000/login`
const API_URL = `${BASE_URL}:9000/messages`
const TEST_URL = `${BASE_URL}:3000/messages`
const BUTTON = "Nova Mensagem"
const ENTITY = { _id: "1", title: "Mensagem 1", text: "mensagem 1" }
const ENTITY_PLURAL_NAME = "Mensagens"
const TEST_NAME = `Página de ${ENTITY_PLURAL_NAME}`

describe("Página de Mensagens", () => {
describe(TEST_NAME, () => {
beforeEach(() => {


cy.fixture("token").then((token) => {
console.log(token);
cy.intercept("POST", `${LOGIN_URL}`, {
statusCode: 200,
body: {
token: token.token
}
body: { token: token.token }
});

cy.intercept("GET", `${API_URL}`, {
statusCode: 200,
body: [
{ _id: "1", title: "Mensagem 1", text: "mensagem 1" },
]
}).as("getMessages");
body: [ ENTITY ]
}).as("getPlans");

localStorage.setItem("token", token.token);
cy.visit(`${TEST_URL}`);

cy.wait("@getMessages");
});
})
});

it("deve exibir uma lista de messages", () => {
it(`deve exibir uma lista de ${ENTITY_PLURAL_NAME}`, () => {
cy.get("table").should("exist");
cy.get("table tbody tr").should("have.length.at.least", 1);
});
Expand All @@ -54,4 +49,4 @@ describe("Página de Mensagens", () => {
cy.get("table").should("exist");
cy.get("form").should("not.exist");
});
});
});
21 changes: 8 additions & 13 deletions cypress/e2e/integrations/plans.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,31 @@ const BASE_URL = ENV == "development" ? BASE_URL_DEV : BASE_URL_PROD
const LOGIN_URL = `${BASE_URL}:9000/login`
const API_URL = `${BASE_URL}:9000/plans/active`
const TEST_URL = `${BASE_URL}:3000/plans`
const BUTTON = "Nova Mensagem"
const BUTTON = "Novo Plan"
const ENTITY = { _id: "1", name: "Plano 1", users: 1, connections: 1, queues: 1, value: 1}
const ENTITY_PLURAL_NAME = "Planos"
const TEST_NAME = `Página de ${ENTITY_PLURAL_NAME}`

describe("Página de Planos", () => {
describe(TEST_NAME, () => {
beforeEach(() => {

cy.fixture("token").then((token) => {
console.log(token);
cy.intercept("POST", `${LOGIN_URL}`, {
statusCode: 200,
body: {
token: token.token
}
body: { token: token.token }
});

cy.intercept("GET", `${API_URL}`, {
statusCode: 200,
body: [
{ _id: "1", name: "Plano 1", users: 1, connections: 1, queues: 1, value: 1},
]
body: [ ENTITY ]
}).as("getPlans");

localStorage.setItem("token", token.token);
cy.visit(`${TEST_URL}`);

// cy.wait("@getPlans", {timeout: 20000});
})

});

it("deve exibir uma lista de empresas", () => {
it(`deve exibir uma lista de ${ENTITY_PLURAL_NAME}`, () => {
cy.get("table").should("exist");
cy.get("table tbody tr").should("have.length.at.least", 1);
});
Expand Down
52 changes: 33 additions & 19 deletions cypress/e2e/integrations/tags.cy.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
describe("Página de tags", () => {
beforeEach(() => {
// const ENV = "development"
const ENV = "production"
const BASE_URL_DEV = "http://localhost"
const BASE_URL_PROD = "http://137.184.81.207"
const BASE_URL = ENV == "development" ? BASE_URL_DEV : BASE_URL_PROD
const LOGIN_URL = `${BASE_URL}:9000/login`
const API_URL = `${BASE_URL}:9000/tags/active`
const TEST_URL = `${BASE_URL}:3000/tags`
const BUTTON = "Nova Tag"
const ENTITY = { _id: "1", name: "Tag 1", color: "#000000" }
const ENTITY_PLURAL_NAME = "Tags"
const TEST_NAME = `Página de ${ENTITY_PLURAL_NAME}`

describe(TEST_NAME, () => {
beforeEach(() => {
cy.fixture("token").then((token) => {
console.log(token);
cy.intercept("POST", "http://137.184.81.207:9000/login", {
cy.intercept("POST", `${LOGIN_URL}`, {
statusCode: 200,
body: {
token: token.token
}
body: { token: token.token }
});

cy.intercept("GET", "http://137.184.81.207:9000/tags", {
cy.intercept("GET", `${API_URL}`, {
statusCode: 200,
body: [
{ _id: "1", name: "Tag 1", color: "#000000" },
]
}).as("getTags");
body: [ ENTITY ]
}).as("getPlans");

localStorage.setItem("token", token.token);
cy.visit("http://137.184.81.207:3000/tags");

cy.wait("@getTags");
});
cy.visit(`${TEST_URL}`);
})
});

it("deve exibir uma lista de tags", () => {
it(`deve exibir uma lista de ${ENTITY_PLURAL_NAME}`, () => {
cy.get("table").should("exist");
cy.get("table tbody tr").should("have.length.at.least", 1);
});

it("deve mudar da tabela para o formulário ao clicar em Nova Tag", () => {
cy.get("button").contains("Nova Tag").click();
it(`deve mudar da tabela para o formulário ao clicar em ${BUTTON}`, () => {
cy.get("button").contains(BUTTON).click();
cy.get("form").should("exist");
cy.get("table").should("not.exist");
});

});
it("deve mudar do formulário para a tabela ao clicar em Cancelar", () => {
cy.get("button").contains(BUTTON).click();
cy.get("form").should("exist");
cy.get("table").should("not.exist");
cy.get("button").contains("Cancelar").click();
cy.get("table").should("exist");
cy.get("form").should("not.exist");
});
});
51 changes: 32 additions & 19 deletions cypress/e2e/integrations/tasks.cy.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
describe("Página de Tarefas", () => {
beforeEach(() => {
// const ENV = "development"
const ENV = "production"
const BASE_URL_DEV = "http://localhost"
const BASE_URL_PROD = "http://137.184.81.207"
const BASE_URL = ENV == "development" ? BASE_URL_DEV : BASE_URL_PROD
const LOGIN_URL = `${BASE_URL}:9000/login`
const API_URL = `${BASE_URL}:9000/tasks`
const TEST_URL = `${BASE_URL}:3000/tasks`
const BUTTON = "Nova Tarefa"
const ENTITY = { _id: "1", text: "Tarefa 1" }
const ENTITY_PLURAL_NAME = "Planos"
const TEST_NAME = `Página de ${ENTITY_PLURAL_NAME}`

describe(TEST_NAME, () => {
beforeEach(() => {
cy.fixture("token").then((token) => {
console.log(token);
cy.intercept("POST", "http://137.184.81.207:9000/login", {
cy.intercept("POST", `${LOGIN_URL}`, {
statusCode: 200,
body: {
token: token.token
}
body: { token: token.token }
});

cy.intercept("GET", "http://137.184.81.207:9000/tasks/actives", {
cy.intercept("GET", `${API_URL}`, {
statusCode: 200,
body: [
{ _id: "1", text: "Tarefa 1" },
]
}).as("getTasks");
body: [ ENTITY ]
}).as("getPlans");

localStorage.setItem("token", token.token);
cy.visit("http://137.184.81.207:3000/tasks");

cy.wait("@getTasks");
});
cy.visit(`${TEST_URL}`);
})
});

it("deve exibir uma lista de tarefas", () => {
it(`deve exibir uma lista de ${ENTITY_PLURAL_NAME}`, () => {
cy.get("table").should("exist");
cy.get("table tbody tr").should("have.length.at.least", 1);
});

it("deve mudar da tabela para o formulário ao clicar em Nova Tarefa", () => {
cy.get("button").contains("Nova Tarefa").click();
it(`deve mudar da tabela para o formulário ao clicar em ${BUTTON}`, () => {
cy.get("button").contains(BUTTON).click();
cy.get("form").should("exist");
cy.get("table").should("not.exist");
});

// Adicione mais testes conforme necessário...
it("deve mudar do formulário para a tabela ao clicar em Cancelar", () => {
cy.get("button").contains(BUTTON).click();
cy.get("form").should("exist");
cy.get("table").should("not.exist");
cy.get("button").contains("Cancelar").click();
cy.get("table").should("exist");
cy.get("form").should("not.exist");
});
});

0 comments on commit a345f46

Please sign in to comment.