Skip to content

Commit

Permalink
Feat(Dashboard): The seller and admin dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnestTchami committed Jul 9, 2024
1 parent 00af2dd commit 32f14cd
Show file tree
Hide file tree
Showing 82 changed files with 8,344 additions and 3,412 deletions.
5,382 changes: 3,808 additions & 1,574 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "next dev ",
"build": "next build",
"start": "next start",
"lint": "next lint",
Expand All @@ -14,6 +14,7 @@
},
"dependencies": {
"@hookform/resolvers": "^3.6.0",
"@nextui-org/react": "^2.4.2",
"@reduxjs/toolkit": "^2.2.5",
"@tanstack/react-query": "^5.40.1",
"@tanstack/react-table": "^8.17.3",
Expand All @@ -32,6 +33,7 @@
"npx": "^3.0.0",
"react": "^18",
"react-dom": "^18",
"react-google-charts": "^4.0.1",
"react-hook-form": "^7.51.5",
"react-icons": "^5.2.1",
"react-query": "^3.39.3",
Expand Down
Binary file added public/dash1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/dash2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/instagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/orderdash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/orderdash1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/wishdash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/__tests__/2FA_Authentication.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { act } from 'react';
import { render, screen } from '@testing-library/react';
import MockAdapter from 'axios-mock-adapter';
import { Provider } from 'react-redux';

//import configureStore from 'redux-mock-store'; // Assuming you are using Redux
import OtpVerify from '../components/2faVerification';
import userEvent from '@testing-library/user-event';
Expand All @@ -13,6 +13,7 @@ import {
import { configureStore } from '@reduxjs/toolkit';
import twoFactorAuthSlice from '../redux/slices/2faAuthenticationSlice';
import axios from 'axios';
import { Provider } from 'react-redux';
jest.mock('axios');
const URL = process.env.URL;
console.log("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",URL)
Expand Down
97 changes: 97 additions & 0 deletions src/__tests__/CreateProdudash.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import Page from '@/app/dashboard/addproduct/page';
import request from '@/utils/axios';
import { useRouter } from 'next/navigation';

jest.mock('@/utils/axios', () => ({
get: jest.fn(),
}));

jest.mock('next/navigation', () => ({
useRouter: jest.fn(),
}));

// Mock components
jest.mock('@/components/DashNavbar', () => () => (
<div data-testid="mock-dashnavbar">Mock DashNavbar</div>
));
jest.mock('@/components/headerDash', () => () => (
<div data-testid="mock-headerdash">Mock HeaderDash</div>
));
jest.mock('@/components/Product/AddProducts', () => () => (
<div data-testid="mock-addproducts">Mock AddProducts</div>
));

const queryClient = new QueryClient();

describe('Page Component', () => {
beforeEach(() => {
(request.get as jest.Mock).mockImplementation((url) => {
if (url.includes('/categories')) {
return Promise.resolve({
data: [
{ id: 1, name: 'Category 1' },
{ id: 2, name: 'Category 2' },
],
});
}
return Promise.resolve({ data: [] });
});

Storage.prototype.getItem = jest.fn(() =>
JSON.stringify({
User: {
Role: {
name: 'admin',
},
name: 'Test User',
},
}),
);

(useRouter as jest.Mock).mockReturnValue({
push: jest.fn(),
});
});

test('renders data after loading', async () => {
render(
<QueryClientProvider client={queryClient}>
<Page />
</QueryClientProvider>,
);

await waitFor(() => {
expect(screen.getByTestId('mock-dashnavbar')).toBeInTheDocument();
});

expect(screen.getByTestId('mock-headerdash')).toBeInTheDocument();
expect(screen.getByTestId('mock-addproducts')).toBeInTheDocument();
});

test('redirects to /dashboard/home if user is not a seller', async () => {
Storage.prototype.getItem = jest.fn(() =>
JSON.stringify({
User: {
Role: {
name: 'admin',
},
name: 'Test User',
},
}),
);

render(
<QueryClientProvider client={queryClient}>
<Page />
</QueryClientProvider>,
);

await waitFor(() => {
expect(useRouter().push).toHaveBeenCalledWith('/dashboard/home');
});
});
});
52 changes: 52 additions & 0 deletions src/__tests__/Orderdash.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import Page from '@/app/dashboard/orders/page';
import request from '@/utils/axios';
import { useRouter } from 'next/navigation';

jest.mock('@/utils/axios', () => ({
get: jest.fn(),
}));

jest.mock('next/cache', () => ({
unstable_noStore: jest.fn(),
}));

jest.mock('next/navigation', () => ({
useRouter: jest.fn(),
}));

const queryClient = new QueryClient();
jest.mock('@/components/BuyerOrdersList', () => () => (
<div data-testid="mock-dashnavbar">Mock buyer List</div>
));
jest.mock('@/components/headerDash', () => () => (
<div data-testid="mock-headernav">Mock DashNavbar</div>
));
describe('Page Component', () => {
beforeEach(() => {
Storage.prototype.getItem = jest.fn(() =>
JSON.stringify({
User: {
Role: {
name: 'admin',
},
name: 'Test User',
},
}),
);
(useRouter as jest.Mock).mockReturnValue({
push: jest.fn(),
});
});

test('renders loading state initially', () => {
render(
<QueryClientProvider client={queryClient}>
<Page />
</QueryClientProvider>,
);
});
});
67 changes: 67 additions & 0 deletions src/__tests__/ProfileDashboard.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import Page from '@/app/dashboard/profile/page';
import request from '@/utils/axios';
import { useRouter } from 'next/navigation';

jest.mock('@/utils/axios', () => ({
get: jest.fn(),
}));

jest.mock('next/navigation', () => ({
useRouter: jest.fn(),
}));

// Mock components
jest.mock('@/components/DashNavbar', () => () => (
<div data-testid="mock-dashnavbar">Mock DashNavbar</div>
));
jest.mock('@/components/headerDash', () => () => (
<div data-testid="mock-headerdash">Mock HeaderDash</div>
));
jest.mock('@/components/Product/AddProducts', () => () => (
<div data-testid="mock-addproducts">Mock AddProducts</div>
));
const queryClient = new QueryClient();
jest.mock('@/components/DashNavbar', () => () => (
<div data-testid="mock-dashnavbar">Mock DashNavbar</div>
));

describe('Page Component', () => {
beforeEach(() => {
(request.get as jest.Mock).mockImplementation((url) => {
if (url.includes('/categories')) {
return Promise.resolve({
data: [
{ id: 1, name: 'Category 1' },
{ id: 2, name: 'Category 2' },
],
});
}
return Promise.resolve({ data: [] });
});
Storage.prototype.getItem = jest.fn(() =>
JSON.stringify({
User: {
Role: {
name: 'admin',
},
name: 'Test User',
},
}),
);
(useRouter as jest.Mock).mockReturnValue({
push: jest.fn(),
});
});

test('renders loading state initially', () => {
render(
<QueryClientProvider client={queryClient}>
<Page />
</QueryClientProvider>,
);
});
});
67 changes: 67 additions & 0 deletions src/__tests__/ProfileeditDashboard.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import Page from '@/app/dashboard/profile_/[id]/page';
import request from '@/utils/axios';
import { useRouter } from 'next/navigation';

jest.mock('@/utils/axios', () => ({
get: jest.fn(),
}));

jest.mock('next/navigation', () => ({
useRouter: jest.fn(),
}));

// Mock components
jest.mock('@/components/DashNavbar', () => () => (
<div data-testid="mock-dashnavbar">Mock DashNavbar</div>
));
jest.mock('@/components/headerDash', () => () => (
<div data-testid="mock-headerdash">Mock HeaderDash</div>
));
jest.mock('@/components/Product/AddProducts', () => () => (
<div data-testid="mock-addproducts">Mock AddProducts</div>
));
const queryClient = new QueryClient();
jest.mock('@/components/DashNavbar', () => () => (
<div data-testid="mock-dashnavbar">Mock DashNavbar</div>
));

describe('Page Component', () => {
beforeEach(() => {
(request.get as jest.Mock).mockImplementation((url) => {
if (url.includes('/categories')) {
return Promise.resolve({
data: [
{ id: 1, name: 'Category 1' },
{ id: 2, name: 'Category 2' },
],
});
}
return Promise.resolve({ data: [] });
});
Storage.prototype.getItem = jest.fn(() =>
JSON.stringify({
User: {
Role: {
name: 'admin',
},
name: 'Test User',
},
}),
);
(useRouter as jest.Mock).mockReturnValue({
push: jest.fn(),
});
});

test('renders loading state initially', () => {
render(
<QueryClientProvider client={queryClient}>
<Page />
</QueryClientProvider>,
);
});
});
Loading

0 comments on commit 32f14cd

Please sign in to comment.