-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(Dashboard): The seller and admin dashboard
- Loading branch information
1 parent
00af2dd
commit 32f14cd
Showing
82 changed files
with
8,344 additions
and
3,412 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,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'); | ||
}); | ||
}); | ||
}); |
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,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>, | ||
); | ||
}); | ||
}); |
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,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>, | ||
); | ||
}); | ||
}); |
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,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>, | ||
); | ||
}); | ||
}); |
Oops, something went wrong.