Skip to content

Commit

Permalink
Fix: created testing for admin league page
Browse files Browse the repository at this point in the history
  • Loading branch information
alexappleget committed Oct 17, 2024
1 parent d2f88e4 commit a894326
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions app/(admin)/admin/leagues/page.test.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
import { render, screen, waitFor } from '@testing-library/react';
import AdminLeagues from './page';
import { getUserLeagues } from '@/utils/utils';
import { getAllLeagueEntries } from '@/api/apiFunctions';

jest.mock('@/store/dataStore', () => ({
useDataStore: jest.fn().mockReturnValue({
user: { leagues: ['league1', 'league2'] },
}),
useDataStore: jest.fn(() => ({
user: {
documentId: '123',
id: '1234',
email: '[email protected]',
leagues: ['league1', 'league2'],
},
})),
}));

jest.mock('@/utils/utils', () => ({
getUserLeagues: jest.fn(() => Promise.resolve([])),
cn: jest.fn(),
}));

jest.mock('@/api/apiFunctions', () => ({
getAllLeagueEntries: jest.fn(),
}));

describe('AdminLeagues', () => {
render(<AdminLeagues />);

const mockGetUserLeagues = getUserLeagues as jest.Mock;
const mockGetAllLeagueEntries = getAllLeagueEntries as jest.Mock;

beforeEach(() => {
render(<AdminLeagues />);
})
jest.clearAllMocks();
});

it('should render the League data table component', async () => {
mockGetAllLeagueEntries.mockResolvedValue([]);

mockGetUserLeagues.mockResolvedValue([]);

await waitFor(() => {
const leagueTable = screen.getByTestId('data-table');
expect(leagueTable).toBeInTheDocument();
Expand Down

0 comments on commit a894326

Please sign in to comment.