Skip to content

Commit

Permalink
improved code coverage of src/screens/OrganizationVenues/Organization… (
Browse files Browse the repository at this point in the history
#3121)

* improved code coverage of src/screens/OrganizationVenues/OrganizationVenues.tsx

* fixed formatting
  • Loading branch information
Dhiren-Mhatre authored Jan 2, 2025
1 parent 78be925 commit b60c476
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 2 deletions.
111 changes: 111 additions & 0 deletions src/screens/OrganizationVenues/OrganizationVenues.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import { VENUE_LIST } from 'GraphQl/Queries/OrganizationQueries';
import type { ApolloLink } from '@apollo/client';
import { DELETE_VENUE_MUTATION } from 'GraphQl/Mutations/VenueMutations';
import { vi } from 'vitest';
import { errorHandler } from 'utils/errorHandler';

const MOCKS = [
{
request: {
Expand Down Expand Up @@ -505,3 +507,112 @@ describe('Organisation Venues', () => {
});
});
});

vi.mock('utils/errorHandler');
describe('Organisation Venues Error Handling', () => {
beforeEach(() => {
vi.resetAllMocks();
});

test('handles venue query error correctly', async () => {
const mockError = new Error('Failed to fetch venues');
const errorLink = new StaticMockLink([
{
request: {
query: VENUE_LIST,
variables: {
orgId: 'orgId',
orderBy: 'capacity_DESC',
where: {
name_starts_with: '',
description_starts_with: undefined,
},
},
},
error: mockError,
},
]);

renderOrganizationVenue(errorLink);

await waitFor(() => {
expect(errorHandler).toHaveBeenCalledWith(
expect.any(Function),
mockError,
);
});
});

test('handles venue deletion error correctly', async () => {
const mockError = new Error('Failed to delete venue');
const errorLink = new StaticMockLink(
[
{
request: {
query: VENUE_LIST,
variables: {
orgId: 'orgId',
orderBy: 'capacity_DESC',
where: {
name_starts_with: '',
description_starts_with: undefined,
},
},
},
result: {
data: {
getVenueByOrgId: [
{
_id: 'venue1',
name: 'Test Venue',
description: 'Test Description',
capacity: 100,
// ... other required fields
},
],
},
},
},
{
request: {
query: DELETE_VENUE_MUTATION,
variables: { id: 'venue1' },
},
error: mockError,
},
],
true,
);

renderOrganizationVenue(errorLink);

await waitFor(() => {
expect(screen.getByTestId('deleteVenueBtn1')).toBeInTheDocument();
});

fireEvent.click(screen.getByTestId('deleteVenueBtn1'));

await waitFor(() => {
expect(errorHandler).toHaveBeenCalledWith(
expect.any(Function),
mockError,
);
});
});

test('renders venue list correctly after loading', async () => {
renderOrganizationVenue(link);

// First verify loading state
expect(screen.getByTestId('spinner-wrapper')).toBeInTheDocument();

// Then verify venues are rendered
await waitFor(() => {
const venueList = screen.getByTestId('orgvenueslist');
expect(venueList).toBeInTheDocument();

const venues = screen.getAllByTestId(/^venue-item/);
expect(venues).toHaveLength(3);
});
});
});
2 changes: 0 additions & 2 deletions src/screens/OrganizationVenues/OrganizationVenues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ function organizationVenues(): JSX.Element {
});
venueRefetch();
} catch (error) {
/* istanbul ignore next */
errorHandler(t, error);
}
};
Expand Down Expand Up @@ -128,7 +127,6 @@ function organizationVenues(): JSX.Element {
};

// Error handling for venue data fetch
/* istanbul ignore next */
if (venueError) {
errorHandler(t, venueError);
}
Expand Down

0 comments on commit b60c476

Please sign in to comment.