Skip to content

Commit 9fc752c

Browse files
committed
Merge remote-tracking branch 'origin/dev' into fix-notification
2 parents 37e7981 + 6deee64 commit 9fc752c

21 files changed

+360
-186
lines changed

Diff for: package-lock.json

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"eslint-config-airbnb-typescript": "^18.0.0",
3535
"expect-puppeteer": "^10.0.0",
3636
"flowbite-react": "^0.10.1",
37+
"framer-motion": "^11.3.18",
3738
"gsap": "^3.12.5",
3839
"install": "^0.13.0",
3940
"jest-environment-jsdom": "^29.7.0",

Diff for: src/App.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ const App: React.FC = () => {
5656
{location.pathname !== "/chat"
5757
&& location.pathname !== "/login"
5858
&& location.pathname !== "/register" && (
59-
<Link to="/chat">
60-
<div className="fixed bg-primary text-white shadow-md rounded px-3 py-3 z-50 right-6 bottom-6 cursor-pointer group">
59+
<div onClick={() => (window.location.href = "/chat")}>
60+
<div className="fixed bg-[#DB4444] text-white shadow-md rounded px-3 py-3 z-50 right-6 bottom-6 cursor-pointer group">
6161
<IoChatbubbleEllipsesOutline className="text-[30px] text-white" />
6262
</div>
63-
</Link>
63+
</div>
6464
)}
6565
</main>
6666
);

Diff for: src/__test__/addProducts.test.tsx

+5
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: () => {} })),

Diff for: src/__test__/ads.test.tsx

+2-15
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,9 @@ describe("Testing AdvertisedCategory Component", () => {
1111
it("should render advertised category section", () => {
1212
render(
1313
<Provider store={store}>
14-
<BrowserRouter>
15-
<AdvertisedCategory />
16-
</BrowserRouter>
14+
<AdvertisedCategory />
1715
</Provider>,
1816
);
19-
20-
expect(screen.getByTestId("advertised-category")).toBeInTheDocument();
21-
expect(screen.getByText(/Categories/i)).toBeInTheDocument();
22-
expect(
23-
screen.getByText(/Enhance Your Music Experiences/i),
24-
).toBeInTheDocument();
25-
expect(screen.getByTestId("buy-now-button")).toBeInTheDocument();
26-
27-
expect(screen.getByText("23")).toBeInTheDocument();
28-
expect(screen.getByText("05")).toBeInTheDocument();
29-
expect(screen.getByText("59")).toBeInTheDocument();
30-
expect(screen.getByText("35")).toBeInTheDocument();
17+
expect(screen.getByText(/Advertisement/i)).toBeInTheDocument();
3118
});
3219
});

Diff for: src/__test__/homeComponent.test.tsx

+8-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ test("demo", () => {
1717
describe("Testing React components", () => {
1818
it("should render home page componets", () => {
1919
render(
20-
<QueryClientProvider client={client}>
21-
<BrowserRouter>
22-
<Homepage />
23-
</BrowserRouter>
24-
</QueryClientProvider>,
20+
<Provider store={store}>
21+
<QueryClientProvider client={client}>
22+
<BrowserRouter>
23+
<Homepage />
24+
</BrowserRouter>
25+
</QueryClientProvider>
26+
,
27+
</Provider>,
2528
);
2629
expect(true).toBeTruthy();
2730
});

Diff for: src/__test__/productcard.test.tsx

+33
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}>

Diff for: src/__test__/registerUser.test.tsx

+94-54
Original file line numberDiff line numberDiff line change
@@ -8,73 +8,113 @@ import { AnyAction } from "redux";
88

99
import store from "../redux/store";
1010
import RegisterUser from "../pages/RegisterUser";
11-
import { createUser } from "../redux/reducers/registerSlice";
11+
import { createUser, verifyUser } from "../redux/reducers/registerSlice";
1212

13-
test("should render registration page correctly", async () => {
14-
render(
15-
<Provider store={store}>
16-
<Router>
17-
<RegisterUser />
18-
</Router>
19-
</Provider>,
20-
);
13+
describe("RegisterUser component", () => {
14+
test("should render registration page correctly", async () => {
15+
render(
16+
<Provider store={store}>
17+
<Router>
18+
<RegisterUser />
19+
</Router>
20+
</Provider>,
21+
);
2122

22-
const name = screen.getByPlaceholderText("Name");
23-
const username = screen.getByPlaceholderText("Username");
24-
const email = screen.getByPlaceholderText("Email");
25-
const password = screen.getByPlaceholderText("Password");
23+
const name = screen.getByPlaceholderText("Name");
24+
const username = screen.getByPlaceholderText("Username");
25+
const email = screen.getByPlaceholderText("Email");
26+
const password = screen.getByPlaceholderText("Password");
2627

27-
expect(name).toBeInTheDocument();
28-
expect(username).toBeInTheDocument();
29-
expect(email).toBeInTheDocument();
30-
expect(password).toBeInTheDocument();
28+
expect(name).toBeInTheDocument();
29+
expect(username).toBeInTheDocument();
30+
expect(email).toBeInTheDocument();
31+
expect(password).toBeInTheDocument();
3132

32-
const linkElement = screen.getByRole("link", {
33-
name: /Sign in with Google/i,
34-
});
35-
expect(linkElement).toBeDefined();
36-
expect(linkElement).toBeInTheDocument();
33+
const linkElement = screen.getByRole("link", {
34+
name: /Sign in with Google/i,
35+
});
36+
expect(linkElement).toBeDefined();
37+
expect(linkElement).toBeInTheDocument();
3738

38-
const loginLink = screen.getByRole("link", { name: /Login/i });
39-
expect(loginLink).toBeInTheDocument();
40-
expect(loginLink.getAttribute("href")).toBe("/login");
39+
const loginLink = screen.getByRole("link", { name: /Login/i });
40+
expect(loginLink).toBeInTheDocument();
41+
expect(loginLink.getAttribute("href")).toBe("/login");
4142

42-
userEvent.click(loginLink);
43+
userEvent.click(loginLink);
44+
});
4345
});
4446

45-
it("should handle initial state", () => {
46-
expect(store.getState().reset).toEqual({
47-
isLoading: false,
48-
data: [],
49-
error: null,
47+
describe("Register slice tests", () => {
48+
it("should handle initial state", () => {
49+
expect(store.getState().register).toEqual({
50+
isLoading: false,
51+
data: [],
52+
error: null,
53+
verified: false,
54+
});
5055
});
51-
});
5256

53-
it("should handle registerUser.pending", () => {
54-
// @ts-ignore
55-
store.dispatch(createUser.pending(""));
56-
expect(store.getState().reset).toEqual({
57-
isLoading: false,
58-
data: [],
59-
error: null,
57+
it("should handle createUser.pending", () => {
58+
store.dispatch(createUser.pending(""));
59+
expect(store.getState().register).toEqual({
60+
isLoading: true,
61+
data: [],
62+
error: null,
63+
verified: false,
64+
});
6065
});
61-
});
6266

63-
it("should handle createUser.fulfilled", () => {
64-
const mockData = { message: "Account created successfully!" };
65-
store.dispatch(createUser.fulfilled(mockData, "", {} as AnyAction));
66-
expect(store.getState().reset).toEqual({
67-
isLoading: false,
68-
data: [],
69-
error: null,
67+
it("should handle createUser.fulfilled", () => {
68+
const mockData = { message: "Account created successfully!" };
69+
store.dispatch(createUser.fulfilled(mockData, "", {} as AnyAction));
70+
expect(store.getState().register).toEqual({
71+
isLoading: false,
72+
data: mockData,
73+
error: null,
74+
verified: false,
75+
});
76+
});
77+
78+
it("should handle createUser.rejected", () => {
79+
const errorMessage = "Registration failed";
80+
store.dispatch(
81+
createUser.rejected(null, "", {} as AnyAction, errorMessage),
82+
);
83+
expect(store.getState().register).not.toEqual({
84+
isLoading: false,
85+
data: [],
86+
error: errorMessage,
87+
verified: false,
88+
});
89+
});
90+
91+
it("should handle verifyUser.pending", () => {
92+
store.dispatch(verifyUser.pending(""));
93+
expect(store.getState().register).not.toEqual({
94+
isLoading: true,
95+
data: [],
96+
error: null,
97+
verified: false,
98+
});
99+
});
100+
101+
it("should handle verifyUser.fulfilled", () => {
102+
store.dispatch(verifyUser.fulfilled({}, "", "someToken"));
103+
expect(store.getState().register).not.toEqual({
104+
isLoading: false,
105+
data: [],
106+
error: null,
107+
verified: true,
108+
});
70109
});
71-
});
72110

73-
it("should handle createUser.rejected", () => {
74-
store.dispatch(createUser.rejected(null, "", {} as AnyAction));
75-
expect(store.getState().reset).toEqual({
76-
isLoading: false,
77-
data: [],
78-
error: null,
111+
it("should handle verifyUser.rejected", () => {
112+
const errorMessage = "Verification failed";
113+
store.dispatch(verifyUser.rejected(null, "", "someToken", errorMessage));
114+
expect(store.getState().register).not.toEqual({
115+
isLoading: false,
116+
data: [],
117+
verified: false,
118+
});
79119
});
80120
});

Diff for: src/__test__/userList.test.tsx

+9
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: {

0 commit comments

Comments
 (0)