Skip to content
Draft
Show file tree
Hide file tree
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
feat: added the ability to close the hint using the keyboard
  • Loading branch information
vladislavkeblysh authored and filippovskii09 committed Oct 23, 2025
commit bcd44b1239f0d017c5a5447274a8249c9f786378
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React, { useState } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this React import?

Copy link
Author

Choose a reason for hiding this comment

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

no, removed

import PropTypes from 'prop-types';
import { useIntl } from '@edx/frontend-platform/i18n';
import {
Expand All @@ -6,6 +7,7 @@ import {
OverlayTrigger,
Stack,
Tooltip,
IconButton,
} from '@openedx/paragon';
import { InfoOutline, Locked } from '@openedx/paragon/icons';
import { useContextId } from '../../../../data/hooks';
Expand All @@ -20,6 +22,13 @@ const GradeSummaryHeader = ({ allOfSomeAssignmentTypeIsLocked }) => {
verifiedMode,
gradesFeatureIsFullyLocked,
} = useModel('progress', courseId);
const [showTooltip, setShowTooltip] = useState(false);

const handleKeyDown = (event) => {
if (event.key === 'Escape') {
setShowTooltip(false);
}
};

return (
<Stack gap={2} className="mb-3">
Expand All @@ -34,9 +43,13 @@ const GradeSummaryHeader = ({ allOfSomeAssignmentTypeIsLocked }) => {
</Tooltip>
)}
>
<Icon
<IconButton
onClick={() => { setShowTooltip(!showTooltip); }}
onBlur={() => { setShowTooltip(false); }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
onClick={() => { setShowTooltip(!showTooltip); }}
onBlur={() => { setShowTooltip(false); }}
onClick={() => setShowTooltip(!showTooltip)}
onBlur={() => setShowTooltip(false)}

Copy link
Author

Choose a reason for hiding this comment

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

fixed

onKeyDown={handleKeyDown}
alt={intl.formatMessage(messages.gradeSummaryTooltipAlt)}
src={InfoOutline}
className="mb-3"
size="sm"
/>
</OverlayTrigger>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this import?

Copy link
Author

Choose a reason for hiding this comment

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

no, removed

import {
render, screen, waitFor,
} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { useSelector } from 'react-redux';
import { IntlProvider } from 'react-intl';

import GradeSummaryHeader from './GradeSummaryHeader';
import { useModel } from '../../../../generic/model-store';
import messages from '../messages';

jest.mock('react-redux', () => ({
useSelector: jest.fn(),
}));

jest.mock('../../../../generic/model-store', () => ({
useModel: jest.fn(),
}));

describe('GradeSummaryHeader', () => {
beforeEach(() => {
useSelector.mockImplementation((selector) => selector({
courseHome: { courseId: 'test-course-id' },
}));
useModel.mockReturnValue({ gradesFeatureIsFullyLocked: false });
});

const renderComponent = (props = {}) => {
render(
<IntlProvider locale="en" messages={messages}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this extra IntlProvider?

Copy link
Author

Choose a reason for hiding this comment

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

no, removed

<GradeSummaryHeader
intl={{ formatMessage: jest.fn((msg) => msg.defaultMessage) }}
allOfSomeAssignmentTypeIsLocked={false}
{...props}
/>
</IntlProvider>,
);
};

it('visible the tooltip when Escape is pressed', async () => {
renderComponent();

const iconButton = screen.getByRole('button', {
name: messages.gradeSummaryTooltipAlt.defaultMessage,
});

userEvent.click(iconButton);

await waitFor(() => {
expect(screen.getByText(messages.gradeSummaryTooltipBody.defaultMessage)).toBeVisible();
});
});
});