Skip to content

Commit

Permalink
Improve Code Coverage in src/screens/OrgSettings/OrgSetting.tsx (#3091)
Browse files Browse the repository at this point in the history
* Improved code coverage OrgSetting.tsx
  • Loading branch information
vivekbisen04 authored Jan 2, 2025
1 parent 96a343e commit 78be925
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
44 changes: 38 additions & 6 deletions src/screens/OrgSettings/OrgSettings.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,50 @@ describe('Organisation Settings Page', () => {
});
});

it('should render dropdown for settings tabs', async () => {
it('should handle dropdown item selection correctly', async () => {
renderOrganisationSettings();

await waitFor(() => {
expect(screen.getByTestId('settingsDropdownToggle')).toBeInTheDocument();
expect(
screen.getByTestId('settingsDropdownContainer'),
).toBeInTheDocument();
});

userEvent.click(screen.getByTestId('settingsDropdownToggle'));
const dropdownToggle = screen.getByTestId('settingsDropdownToggle');
userEvent.click(dropdownToggle);

const dropdownItems = screen.getAllByRole('button', {
name: /general|actionItemCategories|agendaItemCategories/i,
});
// Find all dropdown items
const dropdownItems = screen.getAllByRole('menuitem');
expect(dropdownItems).toHaveLength(3);

for (const item of dropdownItems) {
userEvent.click(item);

if (item.textContent?.includes('general')) {
await waitFor(() => {
expect(screen.getByTestId('generalTab')).toBeInTheDocument();
});
} else if (item.textContent?.includes('actionItemCategories')) {
await waitFor(() => {
expect(
screen.getByTestId('actionItemCategoriesTab'),
).toBeInTheDocument();
});
} else if (item.textContent?.includes('agendaItemCategories')) {
await waitFor(() => {
expect(
screen.getByTestId('agendaItemCategoriesTab'),
).toBeInTheDocument();
});
}

if (item !== dropdownItems[dropdownItems.length - 1]) {
userEvent.click(dropdownToggle);
}
}

expect(dropdownToggle).toHaveTextContent(
screen.getByTestId('agendaItemCategoriesSettings').textContent || '',
);
});
});
6 changes: 2 additions & 4 deletions src/screens/OrgSettings/OrgSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@ function OrgSettings(): JSX.Element {
{settingtabs.map((setting, index) => (
<Dropdown.Item
key={index}
onClick={
/* istanbul ignore next */
() => setTab(setting)
}
role="menuitem"
onClick={() => setTab(setting)}
className={tab === setting ? 'text-secondary' : ''}
>
{t(setting)}
Expand Down

0 comments on commit 78be925

Please sign in to comment.