-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor/companies dynamic #46
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3825f1d
feat/add dynamic contacts for companies
jimmacur 454a5e3
feat/add dynamic application status
jimmacur 697f464
feat/add placeholders to all fields in new company and remove requireβ¦
jimmacur 52e9de4
test/updates compa
jimmacur 556ff08
test/updates intercepts to all tests for companies spec
jimmacur 7a2f88e
test/updates company show spec
jimmacur 60fa6d5
test/updates new company spec
jimmacur 0664b0f
Merge branch 'main' into refactor/companies-dynamic
jimmacur File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ import { mockCompanies } from "../fixtures/mockCompanies.js"; | |
import { mockEmptyCompanies } from "../fixtures/emptyMockCompanies.js"; | ||
|
||
describe("Companies page after logging in", () => { | ||
const userId = 2; | ||
|
||
beforeEach(() => { | ||
// Intercept the login POST request | ||
cy.intercept("POST", "http://localhost:3001/api/v1/sessions", { | ||
|
@@ -10,7 +12,7 @@ describe("Companies page after logging in", () => { | |
token: "fake-token", | ||
user: { | ||
data: { | ||
id: 2, | ||
id: userId, | ||
type: "user", | ||
attributes: { | ||
name: "Test User", | ||
|
@@ -23,14 +25,22 @@ describe("Companies page after logging in", () => { | |
}).as("mockSession"); | ||
|
||
// Intercept the GET request to fetch companies | ||
cy.intercept("GET", "http://localhost:3001/api/v1/users/2/companies", { | ||
cy.intercept("GET", `http://localhost:3001/api/v1/users/${userId}/companies`, { | ||
statusCode: 200, | ||
body: mockCompanies, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}).as("getCompanies"); | ||
|
||
// Intercept the GET request to fetch job applications | ||
cy.intercept("GET", `http://localhost:3001/api/v1/users/${userId}/job_applications`,{ | ||
statusCode: 200, | ||
body: { | ||
data: [], | ||
}, | ||
}) | ||
|
||
// Visit the login page and perform login | ||
cy.visit("http://localhost:3000/"); | ||
cy.get("#email").type("[email protected]"); | ||
|
@@ -90,6 +100,8 @@ describe("Companies page after logging in", () => { | |
}); | ||
|
||
describe("Companies page with no companies", () => { | ||
const userId = 2; | ||
|
||
beforeEach(() => { | ||
// Intercept the login POST request | ||
cy.intercept("POST", "http://localhost:3001/api/v1/sessions", { | ||
|
@@ -98,7 +110,7 @@ describe("Companies page with no companies", () => { | |
token: "fake-token", | ||
user: { | ||
data: { | ||
id: 2, | ||
id: userId, | ||
type: "user", | ||
attributes: { | ||
name: "Test User", | ||
|
@@ -111,14 +123,22 @@ describe("Companies page with no companies", () => { | |
}).as("mockSession"); | ||
|
||
// Intercept the GET request with empty companies | ||
cy.intercept("GET", "http://localhost:3001/api/v1/users/2/companies", { | ||
cy.intercept("GET", `http://localhost:3001/api/v1/users/${userId}/companies`, { | ||
statusCode: 200, | ||
body: mockEmptyCompanies, | ||
headers: { | ||
"Content-Type": "application/json", | ||
} | ||
}).as("getEmptyCompanies"); | ||
|
||
// Intercept the GET request to fetch job applications | ||
cy.intercept("GET", `http://localhost:3001/api/v1/users/${userId}/job_applications`,{ | ||
statusCode: 200, | ||
body: { | ||
data: [], | ||
}, | ||
}) | ||
|
||
// Visit the login page and perform login | ||
cy.visit("http://localhost:3000/"); | ||
cy.get("#email").type("[email protected]"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { mockCompanies } from "../fixtures/mockCompanies.js"; | ||
|
||
describe("Company Show Page", () => { | ||
const userId = 2; | ||
|
||
beforeEach(() => { | ||
// Intercept the login POST request | ||
cy.intercept("POST", "http://localhost:3001/api/v1/sessions", { | ||
|
@@ -9,7 +11,7 @@ describe("Company Show Page", () => { | |
token: "fake-token", | ||
user: { | ||
data: { | ||
id: 2, | ||
id: userId, | ||
type: "user", | ||
attributes: { | ||
name: "Test User", | ||
|
@@ -36,10 +38,38 @@ describe("Company Show Page", () => { | |
}, | ||
}, | ||
}, | ||
contacts: { | ||
data: [ | ||
{ | ||
id: "101", // Change to string to match interface | ||
type: "contact", // Add type field | ||
attributes: { | ||
first_name: "John", | ||
last_name: "Doe", | ||
email: "[email protected]", | ||
phone_number: "555-1234", // Changed from phone to phone_number | ||
notes: "", | ||
user_id: userId | ||
}, | ||
}, | ||
{ | ||
id: "102", | ||
type: "contact", | ||
attributes: { | ||
first_name: "Jane", | ||
last_name: "Smith", | ||
email: "[email protected]", | ||
phone_number: "555-5678", | ||
notes: "", | ||
user_id: userId | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
// Intercept the GET request to fetch companies list | ||
cy.intercept("GET", "http://localhost:3001/api/v1/users/2/companies", { | ||
cy.intercept("GET", `http://localhost:3001/api/v1/users/${userId}/companies`, { | ||
statusCode: 200, | ||
body: mockCompanies, | ||
headers: { | ||
|
@@ -48,35 +78,28 @@ describe("Company Show Page", () => { | |
}, | ||
}).as("getCompanies"); | ||
|
||
// Intercept the GET request to fetch job applications | ||
cy.intercept("GET", `http://localhost:3001/api/v1/users/${userId}/job_applications`,{ | ||
statusCode: 200, | ||
body: { | ||
data: [], | ||
}, | ||
}) | ||
|
||
// Intercept the GET request to fetch company details with Authorization header | ||
cy.intercept("GET", "http://localhost:3001/api/v1/users/2/companies/1/contacts", { | ||
cy.intercept("GET", `http://localhost:3001/api/v1/users/${userId}/companies/1/contacts`, { | ||
statusCode: 200, | ||
body: mockCompany, | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: "Bearer fake-token", | ||
}, | ||
}).as("getCompany"); | ||
|
||
// Visit the login page and perform login | ||
cy.visit("http://localhost:3000/"); | ||
cy.visit("/"); | ||
cy.get("#email").type("[email protected]"); | ||
cy.get("#password").type("jerseyMikesRox7"); | ||
cy.get('[data-testid="login-button"]').click(); | ||
cy.wait("@mockSession"); | ||
|
||
// Store the token in localStorage | ||
cy.window().then((win) => { | ||
win.localStorage.setItem("token", "fake-token"); | ||
}); | ||
|
||
// Navigate to the Companies page | ||
cy.get('[data-testid="companies-iconD"]').click(); | ||
cy.get('a[href="/companies"]').click(); | ||
cy.wait("@getCompanies"); | ||
|
||
cy.log("Navigating to the company details page"); | ||
|
||
// Click on the first company in the table (assuming it's "Google") | ||
cy.get("table tbody tr").first().click(); | ||
cy.wait("@getCompany"); | ||
}); | ||
|
@@ -110,12 +133,17 @@ describe("Company Show Page", () => { | |
}); | ||
}); | ||
|
||
it("Should display the contacts correctly", () => { | ||
cy.get("h2").contains("Contacts").should("exist"); | ||
it("Should display the dynamic contacts correctly", () => { | ||
cy.contains("Contacts").should("exist"); | ||
|
||
const contacts = [ | ||
{ name: "John Doe", link: "/contacts/101" }, | ||
{ name: "Jane Smith", link: "/contacts/102" }, | ||
]; | ||
|
||
cy.contains("John Doe").should("have.attr", "href", "/contacts/101"); | ||
cy.contains("Jane Smith").should("have.attr", "href", "/contacts/102"); | ||
cy.contains("Alice Johnson").should("have.attr", "href", "/contacts/103"); | ||
contacts.forEach((contact) => { | ||
cy.contains(contact.name).should("have.attr", "href", contact.link); | ||
}); | ||
}); | ||
|
||
it("Should navigate to the correct contact detail page when a contact is clicked", () => { | ||
|
@@ -126,11 +154,6 @@ describe("Company Show Page", () => { | |
|
||
cy.contains("Jane Smith").click(); | ||
cy.url().should("include", "/contacts/102"); | ||
|
||
cy.go("back"); | ||
|
||
cy.contains("Alice Johnson").click(); | ||
cy.url().should("include", "/contacts/103"); | ||
}); | ||
|
||
it("Should navigate back to the companies page when clicking 'Back to Companies'", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage of an Interfaces file(and an api fetch file since it's the same idea) for all component usage is mega SRP. Perhaps an issue can be made to migrate all interfaces to this file?