Skip to content

Commit

Permalink
removed code coverage disable statement
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhiren-Mhatre committed Jan 17, 2025
1 parent b12be01 commit 7e8383f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 25 deletions.
32 changes: 21 additions & 11 deletions src/screens/UserPortal/People/People.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ describe('People Component Additional Coverage Tests', () => {
data: {
organizations: [
{
__typename: 'Organization', // Add typename to match actual response
__typename: 'Organization',
_id: 'org-1',
admins: [
{
Expand Down Expand Up @@ -1311,26 +1311,36 @@ describe('People Component Additional Coverage Tests', () => {
</MockedProvider>,
);

// Wait for initial members data to load
// Wait for initial data to load and verify member is shown
await waitFor(() => {
expect(screen.getByText('Test Member')).toBeInTheDocument();
});

// Switch to admin mode before admin data is available
userEvent.click(screen.getByTestId('modeChangeBtn'));
await waitFor(() => {
userEvent.click(screen.getByTestId('modeBtn1'));
// Use act to wrap state changes
await act(async () => {
// Open dropdown
fireEvent.click(screen.getByTestId('modeChangeBtn'));
// Wait for dropdown to open
await waitFor(() => {
expect(screen.getByTestId('modeBtn1')).toBeInTheDocument();
});
// Click admin mode button
fireEvent.click(screen.getByTestId('modeBtn1'));
});

// Initially there should be no members shown as we're waiting for admin data
expect(screen.queryByText('Test Member')).not.toBeInTheDocument();
// Wait for admin data to finish loading
await waitFor(
() => {
// Verify the member is no longer shown
expect(screen.queryByText('Test Member')).not.toBeInTheDocument();
},
{ timeout: 2000 },
);

// Wait for admin data to load and verify it appears
// Wait for admin data to load and verify admin appears
await waitFor(
() => {
// Check for the admin's name (firstName + lastName)
expect(screen.getByText('Admin Test')).toBeInTheDocument();
// Also verify that the admin role is displayed
expect(screen.getByText('Admin')).toBeInTheDocument();
},
{ timeout: 2000 },
Expand Down
34 changes: 20 additions & 14 deletions src/screens/UserPortal/People/People.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,27 @@ export default function people(): JSX.Element {
}
}
useEffect(() => {
if (mode === 0 && data) {
setMembers(allMembers);
} else if (mode === 1) {
// Clear members immediately when switching to admin mode
if (mode === 1) {
// Admin mode
// Immediately clear current members when switching to admin mode
setMembers([]);

Check warning on line 155 in src/screens/UserPortal/People/People.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/UserPortal/People/People.tsx#L155

Added line #L155 was not covered by tests
// Then update with admin data when it's available
if (data2) {
setMembers(admins);
// Only set admin members if we have the data
if (data2 && data2.organizations[0]?.admins) {
const adminMembers = data2.organizations[0].admins.map(
(admin: InterfaceMember) => ({

Check warning on line 159 in src/screens/UserPortal/People/People.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/UserPortal/People/People.tsx#L158-L159

Added lines #L158 - L159 were not covered by tests
...admin,
userType: 'Admin',
}),
);
setMembers(adminMembers);

Check warning on line 164 in src/screens/UserPortal/People/People.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/UserPortal/People/People.tsx#L164

Added line #L164 was not covered by tests
}
} else if (mode === 0) {
// All members mode
if (data && data.organizationsMemberConnection) {
setMembers(allMembers);

Check warning on line 169 in src/screens/UserPortal/People/People.tsx

View check run for this annotation

Codecov / codecov/patch

src/screens/UserPortal/People/People.tsx#L169

Added line #L169 was not covered by tests
}
}
}, [mode, data, data2, allMembers, admins]);
}, [mode, data, data2, allMembers]);

return (
<>
Expand Down Expand Up @@ -238,8 +248,7 @@ export default function people(): JSX.Element {
page * rowsPerPage,
page * rowsPerPage + rowsPerPage,
)
: /* istanbul ignore next */
members
: members
).map((member: InterfaceMember, index) => {
const name = `${member.firstName} ${member.lastName}`;

Expand All @@ -263,10 +272,7 @@ export default function people(): JSX.Element {
<tbody>
<tr>
<PaginationList
count={
/* istanbul ignore next */
members ? members.length : 0
}
count={members ? members.length : 0}
rowsPerPage={rowsPerPage}
page={page}
onPageChange={handleChangePage}
Expand Down

0 comments on commit 7e8383f

Please sign in to comment.