diff --git a/cypress/e2e/integrations/companies.cy.js b/cypress/e2e/integrations/companies.cy.js index ae1a07d..837a281 100644 --- a/cypress/e2e/integrations/companies.cy.js +++ b/cypress/e2e/integrations/companies.cy.js @@ -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); }); @@ -54,4 +49,4 @@ describe("Página de Empresas", () => { cy.get("table").should("exist"); cy.get("form").should("not.exist"); }); -}); +}); \ No newline at end of file diff --git a/cypress/e2e/integrations/connections.cy.js b/cypress/e2e/integrations/connections.cy.js index 33cad2c..80c9880 100644 --- a/cypress/e2e/integrations/connections.cy.js +++ b/cypress/e2e/integrations/connections.cy.js @@ -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); }); @@ -53,4 +49,4 @@ describe("Página de Conexões", () => { cy.get("table").should("exist"); cy.get("form").should("not.exist"); }); -}); +}); \ No newline at end of file diff --git a/cypress/e2e/integrations/contacts.cy.js b/cypress/e2e/integrations/contacts.cy.js index 8830381..85bb893 100644 --- a/cypress/e2e/integrations/contacts.cy.js +++ b/cypress/e2e/integrations/contacts.cy.js @@ -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); }); @@ -58,4 +49,4 @@ describe("Página de Contatos", () => { cy.get("table").should("exist"); cy.get("form").should("not.exist"); }); -}); +}); \ No newline at end of file diff --git a/cypress/e2e/integrations/messages.cy.js b/cypress/e2e/integrations/messages.cy.js index bc94872..89b3dcd 100644 --- a/cypress/e2e/integrations/messages.cy.js +++ b/cypress/e2e/integrations/messages.cy.js @@ -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); }); @@ -54,4 +49,4 @@ describe("Página de Mensagens", () => { cy.get("table").should("exist"); cy.get("form").should("not.exist"); }); -}); +}); \ No newline at end of file diff --git a/cypress/e2e/integrations/plans.cy.js b/cypress/e2e/integrations/plans.cy.js index 9a2c43e..575a42b 100644 --- a/cypress/e2e/integrations/plans.cy.js +++ b/cypress/e2e/integrations/plans.cy.js @@ -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); }); diff --git a/cypress/e2e/integrations/tags.cy.js b/cypress/e2e/integrations/tags.cy.js index 0c3d1e2..5f85936 100644 --- a/cypress/e2e/integrations/tags.cy.js +++ b/cypress/e2e/integrations/tags.cy.js @@ -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"); + }); +}); \ No newline at end of file diff --git a/cypress/e2e/integrations/tasks.cy.js b/cypress/e2e/integrations/tasks.cy.js index 2d4ae95..f7e93f2 100644 --- a/cypress/e2e/integrations/tasks.cy.js +++ b/cypress/e2e/integrations/tasks.cy.js @@ -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"); + }); });