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..78738b0 --- /dev/null +++ b/cypress/integration/adminCanSeeSpecificContractor.feature.js @@ -0,0 +1,47 @@ +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=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"); + 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 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} + + } +