Skip to content

Commit 6deee64

Browse files
authored
Merge pull request #36 from atlp-rwanda/fix-chat
Fix users chat
2 parents 077f5d2 + a4e578d commit 6deee64

File tree

11 files changed

+103
-31
lines changed

11 files changed

+103
-31
lines changed

src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ const App: React.FC = () => {
4949
{location.pathname !== "/chat"
5050
&& location.pathname !== "/login"
5151
&& location.pathname !== "/register" && (
52-
<Link to="/chat">
53-
<div className="fixed bg-primary text-white shadow-md rounded px-3 py-3 z-50 right-6 bottom-6 cursor-pointer group">
52+
<div onClick={() => (window.location.href = "/chat")}>
53+
<div className="fixed bg-[#DB4444] text-white shadow-md rounded px-3 py-3 z-50 right-6 bottom-6 cursor-pointer group">
5454
<IoChatbubbleEllipsesOutline className="text-[30px] text-white" />
5555
</div>
56-
</Link>
56+
</div>
5757
)}
5858
</main>
5959
);

src/__test__/addProducts.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ describe("FileUpload component", () => {
5555
new File(["dummy content"], "example.png", { type: "image/png" }),
5656
];
5757

58+
jest.mock("react-router-dom", () => ({
59+
...jest.requireActual("react-router-dom"),
60+
useParams: jest.fn(),
61+
}));
62+
5863
beforeEach(() => {
5964
(useDropzone as jest.Mock).mockImplementation(() => ({
6065
getRootProps: jest.fn(() => ({ onClick: () => {} })),

src/__test__/productcard.test.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,39 @@ describe("ProductCard Component", () => {
7777
// expect(addToCartButton).toBeDefined();
7878
});
7979

80+
test("renders rating and review count correctly", () => {
81+
render(
82+
<Provider store={store}>
83+
<BrowserRouter>
84+
<ProductCard product={product} />
85+
</BrowserRouter>
86+
</Provider>,
87+
);
88+
89+
const rating = screen.getByTestId("rating");
90+
const reviewCount = screen.getByTestId("review");
91+
92+
expect(rating).toBeDefined();
93+
expect(reviewCount).toBeDefined();
94+
});
95+
96+
test("truncates long product names", () => {
97+
const longNameProduct = {
98+
...product,
99+
name: "This is a very long product name that should be truncated",
100+
};
101+
render(
102+
<Provider store={store}>
103+
<BrowserRouter>
104+
<ProductCard product={longNameProduct} />
105+
</BrowserRouter>
106+
</Provider>,
107+
);
108+
109+
const productName = screen.getByTestId("product-name");
110+
expect(productName.textContent).toHaveLength(15);
111+
});
112+
80113
test("renders wishlist and view details buttons", () => {
81114
render(
82115
<Provider store={store}>

src/__test__/userList.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@ import MockAdapter from "axios-mock-adapter";
66
import UserList from "../page-sections/UserList";
77
import chatSlice from "../redux/reducers/chatSlice";
88
import api from "../redux/api/api";
9+
import { socket } from "../config/socket";
910

1011
const mockApi = new MockAdapter(api);
12+
13+
jest.mock("../config/socket", () => ({
14+
socket: {
15+
on: jest.fn(),
16+
off: jest.fn(),
17+
},
18+
}));
19+
1120
const mockStore = (initialState) =>
1221
configureStore({
1322
reducer: {

src/components/dashboard/Header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const Header: React.FC<HeaderProps> = ({ toggleSidebar }) => {
5454

5555
return (
5656
<>
57-
<header className="flex lg:w-[80%] lg:ml-[5%] px-8 fixed z-30 top-0 items-center w-full justify-between py-4 bg-white dark:bg-secondary-black">
57+
<header className="flex lg:w-[80%] lg:ml-[5%] px-8 fixed z-30 top-0 items-center w-full justify-between py-4 bg-white">
5858
<div className="relative flex items-center justify-between w-full lg:hidden">
5959
<FiMenu className="w-6 h-6 mr-3 text-black" onClick={toggleSidebar} />
6060
<div className="flex items-center gap-4" />
@@ -67,7 +67,7 @@ const Header: React.FC<HeaderProps> = ({ toggleSidebar }) => {
6767
<input
6868
type="text"
6969
placeholder="Search..."
70-
className="pl-10 pr-10 py-2 rounded-md dark:border-[0.3px] outline-none bg-[#F7F8FA] focus:outline-none"
70+
className="pl-10 pr-10 py-2 rounded-md border-[0.3px] outline-none bg-[#F7F8FA] focus:outline-none"
7171
/>
7272
</div>
7373
<div className="flex items-center gap-6">

src/components/dashboard/SideBar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ const SideBar: React.FC<SidebarProps> = ({ isOpen }) => {
2626
isOpen ? "translate-x-0" : "-translate-x-full"
2727
} lg:translate-x-0`}
2828
>
29-
<div className="flex flex-col justify-between min-h-screen py-6 dark:bg-secondary-black">
30-
<div className="flex flex-col items-center justify-center">
29+
<div className="flex flex-col justify-between py-6 min-h-screen">
30+
<div className="flex flex-col justify-center items-center">
3131
<Link to="/">
3232
<div className="flex items-center justify-center gap-1 py-2 font-bold text-black">
3333
<span className="font-[550] text-2xl"> eagles</span>

src/components/dashboard/Spinner.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Spinner = () => (
2-
<span className="inline-block dark:text-white">
2+
<span className="inline-block">
33
<svg
44
width="20"
55
height="20"

src/components/dashboard/admin/AdminSideBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const AdminSideBar: React.FC<SidebarProps> = ({ isOpen }) => {
4747
isOpen ? "translate-x-0" : "-translate-x-full"
4848
} lg:translate-x-0`}
4949
>
50-
<div className="flex flex-col justify-between min-h-screen py-6 dark:bg-secondary-black">
50+
<div className="flex flex-col justify-between min-h-screen py-6">
5151
<div className="flex flex-col items-center justify-center">
5252
<div className="flex items-center justify-center gap-1 py-2 font-bold text-black">
5353
<span className="font-[550] text-2xl">eagles</span>

src/components/dashboard/products/ProductsTable.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,7 @@ const ProductsTable: React.FC = () => {
162162
</tr>
163163
) : products.length === 0 ? (
164164
<tr>
165-
<td
166-
colSpan={6}
167-
className="text-center py-10 text-dark-gray dark:text-white"
168-
>
165+
<td colSpan={6} className="text-center py-10 text-dark-gray">
169166
No products found.
170167
</td>
171168
</tr>

src/page-sections/UserList.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { HiMiniUserGroup } from "react-icons/hi2";
88
import { useAppDispatch } from "../redux/hooks";
99
import Spinner from "../components/dashboard/Spinner";
1010
import { fetchChats, fetchUsers } from "../redux/reducers/chatSlice";
11+
import { socket } from "../config/socket";
1112

1213
interface UserListProps {
1314
onUserSelect: (chat: any | null, user: any) => void;
@@ -38,6 +39,17 @@ const UserList: React.FC<UserListProps> = ({
3839
useEffect(() => {
3940
dispatch(fetchChats());
4041
dispatch(fetchUsers());
42+
43+
const handlePrivateMessage = () => {
44+
dispatch(fetchChats());
45+
dispatch(fetchUsers());
46+
};
47+
48+
socket.on("private message recieved", handlePrivateMessage);
49+
50+
return () => {
51+
socket.off("private message recieved", handlePrivateMessage);
52+
};
4153
}, [dispatch]);
4254

4355
useEffect(() => {
@@ -114,7 +126,7 @@ const UserList: React.FC<UserListProps> = ({
114126
<input
115127
type="text"
116128
placeholder="Search..."
117-
className="px-10 py-2 rounded-md dark:border-[1px] text-gray-500 w-full outline-none bg-bg-gray dark:bg-transparent dark:border-dark-gray focus:outline-none"
129+
className="px-10 py-2 rounded-md border-[1px] text-gray-500 w-full outline-none bg-bg-gray bg-transparent border-dark-gray focus:outline-none"
118130
value={searchTerm}
119131
onChange={handleSearchChange}
120132
/>
@@ -193,7 +205,7 @@ const UserList: React.FC<UserListProps> = ({
193205
{chat.messages.length > 0
194206
? chat.messages[
195207
chat.messages.length - 1
196-
].message.substring(0, 20)
208+
].message.substring(0, 15)
197209
: "No messages yet"}
198210
...
199211
</p>

0 commit comments

Comments
 (0)