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 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions src/tutorial/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@

}
}

.tutorialsText {
padding: 0.5rem 0.5rem;
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
padding: 0.5rem 0.5rem;
padding: layout.$spacing-03;

}

.tutorialsText:hover {
background: #e8e8e8;
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
background: #e8e8e8;
background: colors.$white-hover;

Carbon color token mappings

}
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(),
}))
Comment on lines +7 to +9
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))
})
})
3 changes: 2 additions & 1 deletion src/tutorial/tutorial.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import { showModal } from '@openmrs/esm-framework';
import styles from './styles.scss'

const Tutorial = () => {
const { t } = useTranslation();
Expand All @@ -13,7 +14,7 @@ const Tutorial = () => {

return (
<>
<div onClick={handleOpenModal}>{t('tutorials', 'Tutorials')}</div>
<div onClick={handleOpenModal} className={styles.tutorialsText}>{t('tutorials', 'Tutorials')}</div>
</>
);
};
Expand Down
Loading