Skip to content

Commit 809a545

Browse files
committed
add testing for market place
1 parent 62ca57f commit 809a545

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

__tests__/marketplace.test.tsx

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import '@testing-library/jest-dom/extend-expect';
2+
3+
import { fireEvent, render, screen } from '@testing-library/react';
4+
5+
import MarketplaceCard from '../app/src/components/marketplace/MarketplaceCard';
6+
import { Provider } from 'react-redux';
7+
import React from 'react';
8+
import axios from 'axios';
9+
import store from '../app/src/redux/store';
10+
11+
// Mocking the axios module to avoid actual network calls
12+
jest.mock('axios');
13+
14+
describe('MarketplaceCard', () => {
15+
const mockProject = {
16+
_id: 123,
17+
name: 'Sample Project',
18+
username: 'user123'
19+
// ... other properties as needed
20+
};
21+
22+
it('displays project name and username', () => {
23+
render(
24+
<Provider store={store}>
25+
<MarketplaceCard proj={mockProject} />
26+
</Provider>
27+
);
28+
29+
expect(screen.getByText('Sample Project')).toBeInTheDocument();
30+
expect(screen.getByText('user123')).toBeInTheDocument();
31+
});
32+
33+
// You can also test handleClone and handleCloneOpen functionalities
34+
// e.g. using mock implementations for axios.get, dispatch, history.push, etc.
35+
});
36+
37+
describe('MarketplaceContainer', () => {
38+
const mockProjects = [
39+
{
40+
_id: 1,
41+
name: 'Project 1',
42+
username: 'user1'
43+
// ... other properties
44+
},
45+
{
46+
_id: 2,
47+
name: 'Project 2',
48+
username: 'user2'
49+
// ... other properties
50+
}
51+
];
52+
53+
beforeEach(() => {
54+
// Set up mock axios call for every test
55+
axios.get.mockResolvedValue({ data: mockProjects });
56+
});
57+
58+
it('fetches and displays projects', async () => {
59+
render(<MarketplaceCard proj={undefined} />);
60+
61+
// Wait for the async axios call to complete and state to update
62+
const project1 = await screen.findByText('Project 1');
63+
const project2 = await screen.findByText('Project 2');
64+
65+
expect(project1).toBeInTheDocument();
66+
expect(project2).toBeInTheDocument();
67+
});
68+
69+
// Additional tests can include: testing search bar functionality,
70+
// loading states, and no results found message.
71+
});

0 commit comments

Comments
 (0)