-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Code-Hammers/profile-page
Added profiles state, initial profiles load on profiles page
- Loading branch information
Showing
9 changed files
with
137 additions
and
34 deletions.
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# Review and refactor error handling. | ||
# Review and refactor error handling. Needs to be more consistent. Need a guidelines section. | ||
|
||
# Review types (Do we need separate types? Will this cause issues later on?) | ||
|
||
# Add much more thorough edge case tetsing on test files. | ||
|
||
# Testing CI testing integrations | ||
# Create a shared types environment for front and back. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit"; | ||
import axios from "axios"; | ||
import { IProfile } from "../../../types/profile"; | ||
|
||
interface ProfilesState { | ||
profiles: IProfile[]; //TODO ADD PROPER TYPING ONCE OBJECT IS FINALIZED | ||
status: "idle" | "loading" | "failed"; | ||
error: string | null; | ||
} | ||
|
||
const initialState: ProfilesState = { | ||
profiles: [], | ||
status: "idle", | ||
error: null, | ||
}; | ||
|
||
export const fetchProfiles = createAsyncThunk( | ||
"profiles/fetchProfiles", | ||
async (_, thunkAPI) => { | ||
try { | ||
const response = await axios.get("/api/profiles"); | ||
return response.data; | ||
} catch (error) { | ||
if (axios.isAxiosError(error)) { | ||
return thunkAPI.rejectWithValue( | ||
error.response?.data || "Error fetching profiles" | ||
); | ||
} | ||
return thunkAPI.rejectWithValue("An unexpected error occurred"); | ||
} | ||
} | ||
); | ||
|
||
const profilesSlice = createSlice({ | ||
name: "profiles", | ||
initialState, | ||
reducers: { | ||
resetProfilesState(state) { | ||
state.profiles = []; | ||
state.status = "idle"; | ||
state.error = null; | ||
}, | ||
}, | ||
extraReducers: (builder) => { | ||
builder | ||
.addCase(fetchProfiles.pending, (state) => { | ||
state.status = "loading"; | ||
}) | ||
.addCase(fetchProfiles.fulfilled, (state, action) => { | ||
state.profiles = action.payload; | ||
state.status = "idle"; | ||
}) | ||
.addCase(fetchProfiles.rejected, (state, action) => { | ||
state.status = "failed"; | ||
//state.error = action.payload as string; WHAT WOULD PAYLOAD LOOK LIKE HERE? | ||
//TODO BUILD AN ERROR STATE TRACKER FOR CURRENT ERROR INFO | ||
}); | ||
}, | ||
}); | ||
|
||
export default profilesSlice.reducer; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,35 @@ | ||
import React from "react"; | ||
import { render } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
import { create } from "react-test-renderer"; | ||
import { Provider } from "react-redux"; | ||
import configureStore from "redux-mock-store"; | ||
|
||
import Profiles from "./Profiles"; | ||
|
||
describe("Profiles Page", () => { | ||
it("renders the test H1 correctly", () => { | ||
const { getByText } = render(<Profiles />); | ||
const title = getByText("PROFILES"); | ||
expect(title).toBeInTheDocument(); | ||
}); | ||
interface State { | ||
profiles: { | ||
profiles: { user: string }[]; | ||
status: "idle" | "loading" | "failed"; | ||
error: string | null; | ||
}; | ||
} | ||
|
||
const mockStore = configureStore<State>([]); | ||
const initialState: State = { | ||
profiles: { | ||
profiles: [{ user: "User1" }, { user: "User2" }], | ||
status: "idle", | ||
error: null, | ||
}, | ||
}; | ||
|
||
it("matches the snapshot", () => { | ||
const { asFragment } = render(<Profiles />); | ||
expect(asFragment()).toMatchSnapshot(); | ||
describe("MainPage Component", () => { | ||
it("renders correctly", () => { | ||
const store = mockStore(initialState); | ||
const tree = create( | ||
<Provider store={store}> | ||
<Profiles /> | ||
</Provider> | ||
).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
}); |
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
15 changes: 0 additions & 15 deletions
15
client/src/pages/Profiles/__snapshots__/Profiles.test.tsx.snap
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
|
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
interface ISocial { | ||
linkedIn?: string; | ||
github?: string; | ||
twitter?: string; | ||
facebook?: string; | ||
instagram?: string; | ||
} | ||
|
||
interface IJob { | ||
title?: string; | ||
company?: string; | ||
description?: string; | ||
date?: Date; | ||
} | ||
|
||
export interface IProfile { | ||
user: string; | ||
bio?: string; | ||
job?: IJob; | ||
socials?: ISocial; | ||
} |