Skip to content

Commit

Permalink
Merge branch 'main' of github.com:turingschool/tracker-crm-fe into st…
Browse files Browse the repository at this point in the history
…yling/applications-index

Updating branch with most current main.
  • Loading branch information
SmilodonP committed Feb 20, 2025
2 parents 787aee4 + 02b874e commit c2daf0d
Show file tree
Hide file tree
Showing 15 changed files with 237 additions and 95 deletions.
Binary file modified cypress/downloads/downloads.html
Binary file not shown.
102 changes: 86 additions & 16 deletions cypress/e2e/dashBoardSpec.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {mockCompanies} from "../fixtures/mockCompanies";
describe('Dash Board after loggging in', () => {
describe('Dash Board after loggging in with recent jobs, contacts and companies', () => {
beforeEach(()=>{
cy.intercept("POST", "http://localhost:3001/api/v1/sessions", {
statusCode: 200,
Expand Down Expand Up @@ -32,15 +31,15 @@ describe('Dash Board after loggging in', () => {
})

it("Should have a header with the users name once data is loaded", () => {
cy.get("h1").should("have.text", "Welcome,Danny DeVito");
cy.get("h1").should("have.text", "Welcome, Danny DeVito");
});

it("Should show how many job applications where submitted in the week", () => {
it("Should show how many job applications were submitted in the week", () => {
cy.get('.ml-2 > :nth-child(1)').should("exist")
cy.get('.ml-2 > :nth-child(1) > :nth-child(1)').should("exist")
cy.get('.ml-2 > :nth-child(1) > :nth-child(1)').should("have.text","Jobs")
cy.get('[data-cy="dashJobNum"]').should("exist")
cy.get('[data-cy="dashJobNum"]').should("have.text",2)
cy.get('[data-cy="dashNum"]').should("exist")
cy.get('[data-cy="dashNum"]').should("have.text",222)
cy.get('.ml-2 > :nth-child(1) > :nth-child(3)').should("exist")
cy.get('.ml-2 > :nth-child(1) > :nth-child(3)').should("have.text","Apps submitted this week")
});
Expand All @@ -49,26 +48,97 @@ describe('Dash Board after loggging in', () => {
cy.get('.m-24').should("exist")
cy.get('.m-24 > .mt-2').should("exist")
cy.get('.m-24 > .mt-2').should("have.text","Contacts")
cy.get('[data-cy="dashConNum"]').should("exist")
cy.get('[data-cy="dashConNum"]').should("have.text",2)
cy.get('[data-cy="conLabel"]').should("exist")
cy.get('[data-cy="conLabel"]').should("have.text","New connections this week")
cy.get('[data-cy="dashNum"]').should("exist")
cy.get('[data-cy="dashNum"]').should("have.text",222)
cy.get('.ml-2 > :nth-child(2) > :nth-child(3)').should("exist")
cy.get('.ml-2 > :nth-child(2) > :nth-child(3)').should("have.text","New connections this week")
});

it("Should show how many companies where submitted in the week", () => {
cy.get('.ml-2 > :nth-child(3)').should("exist")
cy.get(':nth-child(3) > .mt-2').should("exist")
cy.get(':nth-child(3) > .mt-2').should("have.text","Companies")
cy.get('[data-cy="dashCompNum"]').should("exist")
cy.get('[data-cy="dashCompNum"]').should("have.text",2)
cy.get(':nth-child(3) > .bg-cyan-600').should("exist")
cy.get(':nth-child(3) > .bg-cyan-600').should("have.text","Add new company")
cy.get('[data-cy="dashNum"]').should("exist")
cy.get('[data-cy="dashNum"]').should("have.text",222)
cy.get('.ml-2 > :nth-child(3) > :nth-child(3)').should("exist")
cy.get('.ml-2 > :nth-child(3) > :nth-child(3)').should("have.text","New companies this week")
});
})

describe('Dash Board after loggging in with zero recent jobs, contacts and companies', () => {
beforeEach(()=>{
cy.intercept("POST", "http://localhost:3001/api/v1/sessions", {
statusCode: 200,
body: {
token: 'fake-token',
user: {
data: {
id: 1,
type: 'user',
attributes: {
name: 'Danny DeVito',
email: '[email protected]',
companies: []
}
}
}
}
}).as("mockSession2");

cy.intercept(
'GET',
'http://localhost:3001/api/v1/users/1/dashboard',
{ statusCode: 200, fixture: 'mockDashBoardNoJobsContactsOrCompanies' }
);

cy.visit("http://localhost:3000/");
cy.get("#email").type("[email protected]")
cy.get("#password").type("jerseyMikesRox7")
cy.get('[data-testid="login-button"]').click();
})

it("Should show how many job applications were submitted in the week", () => {
cy.get('.ml-2 > :nth-child(1)').should("exist")
cy.get('.ml-2 > :nth-child(1) > :nth-child(1)').should("exist")
cy.get('.ml-2 > :nth-child(1) > :nth-child(1)').should("have.text","Jobs")
cy.get('[data-cy="dashNum"]').should("exist")
cy.get('[data-cy="dashNum"]').should("have.text","000")
cy.get('.ml-2 > :nth-child(1) > :nth-child(3)').should("exist")
cy.get('.ml-2 > :nth-child(1) > :nth-child(3)').should("have.text","Add new job application")
});

it("Should show how many connections were submitted in the week", () => {
cy.get('.m-24').should("exist")
cy.get('.m-24 > .mt-2').should("exist")
cy.get('.m-24 > .mt-2').should("have.text","Contacts")
cy.get('[data-cy="dashNum"]').should("exist")
cy.get('[data-cy="dashNum"]').should("have.text","000")
cy.get('.ml-2 > :nth-child(2) > :nth-child(3)').should("exist")
cy.get('.ml-2 > :nth-child(2) > :nth-child(3)').should("have.text","Add new contact")
});

it("Should show how many companies were submitted in the week", () => {
cy.get('.ml-2 > :nth-child(3)').should("exist")
cy.get(':nth-child(3) > .mt-2').should("exist")
cy.get(':nth-child(3) > .mt-2').should("have.text","Companies")
cy.get('[data-cy="dashNum"]').should("exist")
cy.get('[data-cy="dashNum"]').should("have.text","000")
cy.get('.ml-2 > :nth-child(3) > :nth-child(3)').should("exist")
cy.get('.ml-2 > :nth-child(3) > :nth-child(3)').should("have.text","Add new company")
});

it("Should have a clickable button to route you to add a new job application", () => {
cy.get(':nth-child(1) > .bg-cyan-600').click();
cy.url().should('include', 'http://localhost:3000/jobapplications/new');
});

it("Should have a clickable button to route you to add a new contact", () => {
cy.get(':nth-child(2) > .bg-cyan-600').click();
cy.url().should('include', 'http://localhost:3000/contacts/new');
});

it("Should have a clickable button to route you to add a new company", () => {
cy.get(':nth-child(3) > .bg-cyan-600').click();
cy.url().should('include', 'http://localhost:3000/companies/new');
});


})
File renamed without changes.
15 changes: 0 additions & 15 deletions cypress/e2e/jobsApplicationSpec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,14 +679,6 @@ describe("Editability of specific job application fields", () => {
"Talked with recruiter, sounds like a great opportunity to learn new things"
);
cy.get('[data-testid="edit-modal-form-submit-button"]').click();

cy.reload();
cy.get("#email").type("[email protected]");
cy.get("#password").type("jerseyMikesRox7");
cy.get('[data-testid="login-button"]').click();
cy.get('[data-testid="applications-iconD"]').click();
cy.get("tbody > tr").contains("Creative").click();

cy.wait("@updateJobApp");

cy.get('[data-testid="job-Title"]').should("contain", "Frontend Developer");
Expand Down Expand Up @@ -729,13 +721,6 @@ describe("Editability of specific job application fields", () => {
cy.get('[data-testid="edit-modal-form-submit-button"]').click();
cy.wait("@showSingleJobAppEmptyFields");

cy.reload();
cy.get("#email").type("[email protected]");
cy.get("#password").type("jerseyMikesRox7");
cy.get('[data-testid="login-button"]').click();
cy.get('[data-testid="applications-iconD"]').click();
cy.get("tbody > tr").contains("Creative").click();

cy.wait("@getJobApplications");
cy.wait("@showSingleJobApp");

Expand Down
34 changes: 34 additions & 0 deletions cypress/e2e/LoginSpec.cy.js → cypress/e2e/loginSpec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,38 @@ describe('testing for Login page', () => {
.get('.login-form-wrap > .form-inputs > .failed-login').should('be.visible')
.get('.login-form-wrap > .form-inputs > .failed-login').should('contain', 'Error in Login: Invalid login credentials')
});

it('persists login after a refresh', () => {
cy.intercept("POST", "http://localhost:3001/api/v1/sessions", {
statusCode: 200,
body: {
token: 'fake-token',
user: {
data: {
id: 1,
type: 'user',
attributes: {
name: 'Danny DeVito',
email: '[email protected]',
companies: []
}
}
}
}
}).as("mockSession");

cy.intercept(
'GET',
'http://localhost:3001/api/v1/users/1/dashboard',
{ statusCode: 200, fixture: 'mockDashBoard' }
);

cy.visit("http://localhost:3000/");
cy.get("#email").type("[email protected]")
cy.get("#password").type("jerseyMikesRox7")
cy.get('[data-testid="login-button"]').click();
cy.get("h1").should("have.text", "Welcome,Danny DeVito");
cy.reload();
cy.get("h1").should("have.text", "Welcome,Danny DeVito");
})
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions cypress/fixtures/mockDashBoardNoJobsContactsOrCompanies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"data": {
"id": "1",
"type": "dashboard",
"attributes": {
"id": 1,
"name": "Danny DeVito",
"email": "[email protected]",
"dashboard": {
"weekly_summary": {
"job_applications": [
],
"contacts": [
],
"companies": [
]
}
}
}
}
}
63 changes: 34 additions & 29 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,42 @@ import DashBoard from "./components/dashboard/dashboard";
function App() {
const { isLoggedIn, userData } = useUserLoggedContext()
return (
<Routes>
<Route // Public Route
path="/"
element={isLoggedIn ? <Navigate to="/home" replace /> : <LoginForm />}
/>

{/* Protected layout using MenuBar */}
<Route element={isLoggedIn ? <MenuBar /> : <Navigate to="/" replace />}>
<Route
path="/home"
element={
<DashBoard/>
}
/>
<Route path="/jobapplications/new" element={<NewJobApplication />} />
<Route path="/companies" element={<Companies />} />
<Route path="/companies/new" element={<NewCompany />} />
<Route path="/companies/:id/contacts" element={<CompanyShow />} />
<Route path="/contacts" element={<Contacts userData={userData}/>} />
<Route path="/contacts/new" element={<NewContact userData={userData}/>} />
<Route path="/job_applications" element={<ApplicationsGrid/>}/>
<Route path="/job_applications/:jobAppId" element={<JobApplication/>}/>
<Route
path="/userInformation"
element={<UserInformation userData={userData} />}
<Routes>
<Route // Public Route
path="/"
element={<ProtectedRoute/>}
/>
<Route path="/contacts/:contactId" element={<ShowContact />}/>
</Route>
<Route path="/UserRegistration" element={<UserRegistration/>}/>
</Routes>

{/* Protected layout using MenuBar */}
<Route element={isLoggedIn ? <MenuBar /> : <Navigate to="/" replace />}>
<Route
path="/home"
element={
<DashBoard/>
}
/>
<Route path="/jobapplications/new" element={<NewJobApplication />} />
<Route path="/companies" element={<Companies />} />
<Route path="/companies/new" element={<NewCompany />} />
<Route path="/companies/:id/contacts" element={<CompanyShow />} />
<Route path="/contacts" element={<Contacts userData={userData}/>} />
<Route path="/contacts/new" element={<NewContact userData={userData}/>} />
<Route path="/job_applications" element={<ApplicationsGrid/>}/>
<Route path="/job_applications/:jobAppId" element={<JobApplication/>}/>
<Route
path="/userInformation"
element={<UserInformation userData={userData} />}
/>
<Route path="/contacts/:contactId" element={<ShowContact />}/>
</Route>
<Route path="/UserRegistration" element={<UserRegistration/>}/>
</Routes>
);
}

function ProtectedRoute() {
const { isLoggedIn } = useUserLoggedContext();
return isLoggedIn ? <Navigate to="/home" replace /> : <LoginForm />;
}

export default App;
9 changes: 8 additions & 1 deletion src/Interfaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,11 @@ export interface DashBoardDattaI{
email: string,
password: string,
passwordConfirmation: string
}
}

export interface CountProps {
section: string;
sectionCount: number;
sectionUrl: string;
sectionDescription: string
}
13 changes: 6 additions & 7 deletions src/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const LoginForm: React.FC = () => {
const [password, setPassword] = useState('');
const [errorMessage, setErrorMessage] = useState('');
const [successMessage, setSuccessMessage] = useState('');
const { userLogged, setUserData } = useUserLoggedContext()
const { userLogged, setUserData } = useUserLoggedContext();
const navigate = useNavigate();

const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
Expand All @@ -24,9 +24,9 @@ const LoginForm: React.FC = () => {
};

loginUser(requestBody)

.then((loggedInUser) => {
console.log("logged data:", loggedInUser)
setUserData({
const userData = {
token: loggedInUser.token,
user: {
data: {
Expand All @@ -39,13 +39,12 @@ const LoginForm: React.FC = () => {
}
}
}
});
// setId(loggedInUser.user.data.id);
// setLogin(true);
}
setUserData(userData)
sessionStorage.setItem("userData", JSON.stringify(userData))
setSuccessMessage('Login successful!');
userLogged(loggedInUser.token, loggedInUser.user.data.type)
navigate("/")
console.log("User updated successfully:", loggedInUser);
})
.catch((error) => {
console.error("Error updating user:", error);
Expand Down
Loading

0 comments on commit c2daf0d

Please sign in to comment.