Skip to content

Commit d1e2e82

Browse files
committed
Feat(Dashboard): The seller and admin dashboard
1 parent 058eb0c commit d1e2e82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2099
-32508
lines changed

package-lock.json

Lines changed: 0 additions & 32004 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"dev": "next dev",
6+
"dev": "next dev ",
77
"build": "next build",
88
"start": "next start",
99
"lint": "next lint",
@@ -29,15 +29,16 @@
2929
"npx": "^10.2.2",
3030
"react": "^18",
3131
"react-dom": "^18",
32+
"react-google-charts": "^4.0.1",
3233
"react-hook-form": "^7.51.5",
3334
"react-icons": "^5.2.1",
3435
"react-query": "^3.39.3",
3536
"react-rating": "^2.0.5",
3637
"react-rating-stars-component": "^2.2.0",
3738
"react-redux": "^9.1.2",
3839
"react-router-dom": "^6.23.1",
39-
"react-toastify": "^10.0.5",
4040
"react-slick": "^0.30.2",
41+
"react-toastify": "^10.0.5",
4142
"redux-mock-store": "^1.5.4",
4243
"redux-thunk": "^3.1.0",
4344
"slick-carousel": "^1.8.1",
@@ -97,8 +98,8 @@
9798
"jest-dom": "^4.0.0",
9899
"jest-environment-jsdom": "^29.7.0",
99100
"lint-staged": "^15.2.4",
100-
"msw": "^2.3.1",
101101
"match-media-mock": "^0.1.1",
102+
"msw": "^2.3.1",
102103
"postcss": "^8",
103104
"prettier": "^3.2.5",
104105
"react-test-renderer": "^18.3.1",
@@ -109,4 +110,4 @@
109110
"ts-node": "^10.9.2",
110111
"typescript": "^5.4.5"
111112
}
112-
}
113+
}

public/dash1.png

1002 Bytes
Loading

public/dash2.png

1008 Bytes
Loading

public/orderdash.png

975 Bytes
Loading

public/orderdash1.png

2.16 KB
Loading

public/wishdash.png

251 Bytes
Loading

src/__tests__/2FA_Authentication.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { act } from 'react';
22
import { render, screen } from '@testing-library/react';
33
import MockAdapter from 'axios-mock-adapter';
4-
import { Provider } from 'react-redux';
4+
55
//import configureStore from 'redux-mock-store'; // Assuming you are using Redux
66
import OtpVerify from '../components/2faVerification';
77
import userEvent from '@testing-library/user-event';
@@ -13,6 +13,7 @@ import {
1313
import { configureStore } from '@reduxjs/toolkit';
1414
import twoFactorAuthSlice from '../redux/slices/2faAuthenticationSlice';
1515
import axios from 'axios';
16+
import { Provider } from 'react-redux';
1617
jest.mock('axios');
1718
const URL = process.env.URL;
1819
console.log("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",URL)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import React from 'react';
2+
import { render, screen, waitFor } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
4+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
5+
import Page from '@/app/dashboard/productcreate/page';
6+
import request from '@/utils/axios';
7+
import { useRouter } from 'next/navigation';
8+
9+
jest.mock('@/utils/axios', () => ({
10+
get: jest.fn(),
11+
}));
12+
13+
jest.mock('next/navigation', () => ({
14+
useRouter: jest.fn(),
15+
}));
16+
17+
// Mock components
18+
jest.mock('@/components/DashNavbar', () => () => (
19+
<div data-testid="mock-dashnavbar">Mock DashNavbar</div>
20+
));
21+
jest.mock('@/components/headerDash', () => () => (
22+
<div data-testid="mock-headerdash">Mock HeaderDash</div>
23+
));
24+
jest.mock('@/components/Product/AddProducts', () => () => (
25+
<div data-testid="mock-addproducts">Mock AddProducts</div>
26+
));
27+
28+
const queryClient = new QueryClient();
29+
30+
describe('Page Component', () => {
31+
beforeEach(() => {
32+
(request.get as jest.Mock).mockImplementation((url) => {
33+
if (url.includes('/categories')) {
34+
return Promise.resolve({
35+
data: [
36+
{ id: 1, name: 'Category 1' },
37+
{ id: 2, name: 'Category 2' },
38+
],
39+
});
40+
}
41+
return Promise.resolve({ data: [] });
42+
});
43+
44+
Storage.prototype.getItem = jest.fn(() =>
45+
JSON.stringify({
46+
User: {
47+
Role: {
48+
name: 'admin',
49+
},
50+
name: 'Test User',
51+
},
52+
}),
53+
);
54+
55+
(useRouter as jest.Mock).mockReturnValue({
56+
push: jest.fn(),
57+
});
58+
});
59+
60+
test('renders data after loading', async () => {
61+
render(
62+
<QueryClientProvider client={queryClient}>
63+
<Page />
64+
</QueryClientProvider>,
65+
);
66+
67+
await waitFor(() => {
68+
expect(screen.getByTestId('mock-dashnavbar')).toBeInTheDocument();
69+
});
70+
71+
expect(screen.getByTestId('mock-headerdash')).toBeInTheDocument();
72+
expect(screen.getByTestId('mock-addproducts')).toBeInTheDocument();
73+
});
74+
75+
test('redirects to /dashboard/home if user is not a seller', async () => {
76+
Storage.prototype.getItem = jest.fn(() =>
77+
JSON.stringify({
78+
User: {
79+
Role: {
80+
name: 'admin',
81+
},
82+
name: 'Test User',
83+
},
84+
}),
85+
);
86+
87+
render(
88+
<QueryClientProvider client={queryClient}>
89+
<Page />
90+
</QueryClientProvider>,
91+
);
92+
93+
await waitFor(() => {
94+
expect(useRouter().push).toHaveBeenCalledWith('/dashboard/home');
95+
});
96+
});
97+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react';
2+
import { render, screen, waitFor } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
4+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
5+
import Page from '@/app/dashboard/profile/page';
6+
import request from '@/utils/axios';
7+
import { useRouter } from 'next/navigation';
8+
9+
jest.mock('@/utils/axios', () => ({
10+
get: jest.fn(),
11+
}));
12+
13+
const queryClient = new QueryClient();
14+
jest.mock('@/components/DashNavbar', () => () => (
15+
<div data-testid="mock-dashnavbar">Mock DashNavbar</div>
16+
));
17+
describe('Page Component', () => {
18+
beforeEach(() => {
19+
Storage.prototype.getItem = jest.fn(() =>
20+
JSON.stringify({
21+
User: {
22+
Role: {
23+
name: 'admin',
24+
},
25+
name: 'Test User',
26+
},
27+
}),
28+
);
29+
});
30+
31+
test('renders loading state initially', () => {
32+
render(
33+
<QueryClientProvider client={queryClient}>
34+
<Page />
35+
</QueryClientProvider>,
36+
);
37+
});
38+
});

0 commit comments

Comments
 (0)