Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) O3-3890 Help menu (and menu items) should use a standard Carbon… #21

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
(fix) O3-3890 Help menu (and menu items) should use a standard Carbon…
… menu
  • Loading branch information
Samstar10 committed Sep 26, 2024
commit 994dbdbf18ffd210f685f7715673a7207b24ab55
7 changes: 7 additions & 0 deletions src/tutorial/styles.scss
Original file line number Diff line number Diff line change
@@ -28,3 +28,10 @@

}
}

.tutorialMenuItem {
color: black !important;
&:focus {
outline: none;
}
}
26 changes: 26 additions & 0 deletions src/tutorial/tutorial.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react";
import { render, screen, fireEvent } from "@testing-library/react";
import '@testing-library/jest-dom';
import { showModal } from "@openmrs/esm-framework";
import Tutorial from "./tutorial";

jest.mock('@openmrs/esm-framework', () => ({
showModal: jest.fn(),
}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
jest.mock('@openmrs/esm-framework', () => ({
showModal: jest.fn(),
}))
const mockShowModal = jest.mocked('showModal');

And then replace showModal in assertions with mockShowModal. See https://o3-docs.openmrs.org/docs/frontend-modules/unit-and-integration-testing#you-should-not-need-to-use-partial-mocks for more context about why you shouldn't need to use partial mocks.


describe('Tutorial Component', () => {
it('renders the menu item with the correct label', () => {
render(<Tutorial />);

expect(screen.getByText(/Tutorials/i)).toBeInTheDocument();
})

it('calls showModal when the menu item is clicked', () => {
render(<Tutorial />);

const menuItem = screen.getByText(/Tutorials/i);
fireEvent.click(menuItem);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer userEvent instead.


expect(showModal).toHaveBeenCalledWith('tutorial-modal', expect.any(Object))
})
})
8 changes: 7 additions & 1 deletion src/tutorial/tutorial.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { showModal } from '@openmrs/esm-framework';
import { MenuItem } from '@carbon/react';
import styles from './styles.scss';

const Tutorial = () => {
const { t } = useTranslation();
@@ -13,7 +15,11 @@ const Tutorial = () => {

return (
<>
<div onClick={handleOpenModal}>{t('tutorials', 'Tutorials')}</div>
<MenuItem
onClick={handleOpenModal}
label={t('tutorials', 'Tutorials')}
className={styles.tutorialMenuItem}
/>
</>
);
};