From b43b11d7c768e806f18f0af51e94ac58777eab3f Mon Sep 17 00:00:00 2001 From: Alex_Bellamy Date: Wed, 18 Nov 2020 12:53:17 +0100 Subject: [PATCH 1/2] writing intiial tests for show contractor --- cypress/fixtures/contractor_show.json | 13 ++++++ cypress/fixtures/contractors_index.json | 10 +--- .../adminCanSeeSpecificContractor.feature.js | 46 +++++++++++++++++++ 3 files changed, 61 insertions(+), 8 deletions(-) create mode 100644 cypress/fixtures/contractor_show.json create mode 100644 cypress/integration/adminCanSeeSpecificContractor.feature.js diff --git a/cypress/fixtures/contractor_show.json b/cypress/fixtures/contractor_show.json new file mode 100644 index 0000000..37c4432 --- /dev/null +++ b/cypress/fixtures/contractor_show.json @@ -0,0 +1,13 @@ +{ + "contractors": [ + { + "id": 1, + "name": "Jacks AB", + "contact_person": "Sam Peters", + "address": "Frejgatan 16113 49 Stockholm", + "telephone": "0767856789", + "email": "peter@mail.com", + "company_number": "556785-7932" + } + ] +} \ No newline at end of file diff --git a/cypress/fixtures/contractors_index.json b/cypress/fixtures/contractors_index.json index 5a8f1a5..e9d2ff5 100644 --- a/cypress/fixtures/contractors_index.json +++ b/cypress/fixtures/contractors_index.json @@ -3,20 +3,14 @@ { "id": 1, "name": "Jacks AB", - "contact_person": "Sam Peters", - "address": "Frejgatan 16113 49 Stockholm", "telephone": "0767856789", - "email": "peter@mail.com", - "company_number": "556785-7932" + "email": "peter@mail.com" }, { "id": 2, "name": "Active AB", - "contact_person": "Simon Eriksson", - "address": "Frejgatan 16113 45 Stockholm", "telephone": "0767856666", - "email": "gary@mail.com", - "company_number": "556785-6556" + "email": "gary@mail.com" } ] } \ No newline at end of file diff --git a/cypress/integration/adminCanSeeSpecificContractor.feature.js b/cypress/integration/adminCanSeeSpecificContractor.feature.js new file mode 100644 index 0000000..5cb4f91 --- /dev/null +++ b/cypress/integration/adminCanSeeSpecificContractor.feature.js @@ -0,0 +1,46 @@ +describe("Admin can see specific contractor", () => { + beforeEach(() => { + cy.server(); + cy.route({ + method: "GET", + url: "http://localhost:3000/api/v1/admin/contractors", + response: "fixture:contractors_index.json", + }); + cy.route({ + method: "GET", + url: "http://localhost:3000/api/v1/contractors/1", + response: "fixture:contractor_show.json", + }); + cy.route({ + method: "POST", + url: "http://localhost:3000/api/v1/auth/sign_in", + response: "fixture:registration_response.json", + }); + cy.route({ + method: "GET", + url: "http://localhost:3000/api/v1/auth/**", + response: "fixture:registration_response.json", + }); + + cy.visit("/"); + cy.get("[data-cy=button]").contains("Admin").click({ force: true }); + cy.get("[data-cy=login-form]").within(() => { + cy.get("[data-cy=email]").type("admin@mail.com"); + cy.get("[data-cy=password]").type("password"); + cy.get("[data-cy=button]").contains("Login").click(); + }); + cy.get("#view-contractors").click(); + }); + + it("Admin can see content of contractor one", () => { + cy.get("[data-cy=contractor-1]").within(() => { + cy.get("[data-cy=name]").should("contain", "Jacks AB"); + cy.get("[data-cy=contactPerson]").should("contain", "Sam Peters"); + cy.get("[data-cy=address]").should("contain", "Frejgatan 16113 49 Stockholm"); + cy.get("[data-cy=telephone]").should("contain", "0767856789"); + cy.get("[data-cy=email]").should("contain", "peter@mail.com"); + cy.get("[data-cy=companyNumber]").should("contain", "556785-7932"); + }); + cy.get("[data-cy=contractor-2]").should("not.exist"); + }); +}); \ No newline at end of file From 1b98a17b4f53932cacdbfea1550a7e14de31bbc8 Mon Sep 17 00:00:00 2001 From: Sima Date: Wed, 18 Nov 2020 16:15:10 +0100 Subject: [PATCH 2/2] modifies the test and adds the button to show more details and render the full details of the contractors --- .../adminCanSeeSpecificContractor.feature.js | 1 + src/components/ViewContractors.jsx | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cypress/integration/adminCanSeeSpecificContractor.feature.js b/cypress/integration/adminCanSeeSpecificContractor.feature.js index 5cb4f91..78738b0 100644 --- a/cypress/integration/adminCanSeeSpecificContractor.feature.js +++ b/cypress/integration/adminCanSeeSpecificContractor.feature.js @@ -34,6 +34,7 @@ describe("Admin can see specific contractor", () => { it("Admin can see content of contractor one", () => { cy.get("[data-cy=contractor-1]").within(() => { + cy.get("[data-cy=button]").click(); cy.get("[data-cy=name]").should("contain", "Jacks AB"); cy.get("[data-cy=contactPerson]").should("contain", "Sam Peters"); cy.get("[data-cy=address]").should("contain", "Frejgatan 16113 49 Stockholm"); diff --git a/src/components/ViewContractors.jsx b/src/components/ViewContractors.jsx index 69290d7..4a724a2 100644 --- a/src/components/ViewContractors.jsx +++ b/src/components/ViewContractors.jsx @@ -1,9 +1,10 @@ import React, { useState, useEffect } from "react"; import axios from "axios"; -import { Card } from "semantic-ui-react"; +import { Card, Button } from "semantic-ui-react"; -const ContractorPage = () => { +const ContractorPage = (props) => { const [contractors, setContractors] = useState([]); + const [viewSingleContractor, setViewSingleContractor] = useState(false); useEffect(() => { getContractors(); @@ -20,12 +21,24 @@ const ContractorPage = () => { let content = contractors.map((contractor) => (
+ {contractor.name} {contractor.telephone} {contractor.email} + + {viewSingleContractor && + <> + {contractor.contact_person} + {contractor.address} + {contractor.company_number} + + } +