-
Notifications
You must be signed in to change notification settings - Fork 294
feat: added the ability to close the hint using the keyboard #1812
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
bcd44b1
0bda1d0
152e9bd
3c3bca8
a9e7617
f00f1eb
4e6bbcd
3180f60
8be39b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
|
||
| import { useSelector } from 'react-redux'; | ||
| import LiveTab from './LiveTab'; | ||
|
|
||
| jest.mock('react-redux', () => ({ | ||
| useSelector: jest.fn(), | ||
| })); | ||
|
|
||
| describe('LiveTab', () => { | ||
|
||
| afterEach(() => { | ||
| jest.clearAllMocks(); | ||
| document.body.innerHTML = ''; | ||
| }); | ||
|
|
||
| it('renders iframe from liveModel using dangerouslySetInnerHTML', () => { | ||
| useSelector.mockImplementation((selector) => selector({ | ||
| courseHome: { courseId: 'course-v1:test+id+2024' }, | ||
| models: { | ||
| live: { | ||
| 'course-v1:test+id+2024': { | ||
| iframe: '<iframe id="lti-tab-embed" src="about:blank"></iframe>', | ||
| }, | ||
| }, | ||
| }, | ||
| })); | ||
|
|
||
| render(<LiveTab />); | ||
|
|
||
| const iframe = document.getElementById('lti-tab-embed'); | ||
| expect(iframe).toBeInTheDocument(); | ||
| expect(iframe.src).toBe('about:blank'); | ||
| }); | ||
|
|
||
| it('adds classes to iframe after mount', () => { | ||
| document.body.innerHTML = ` | ||
| <div id="live_tab"> | ||
| <iframe id="lti-tab-embed" class=""></iframe> | ||
| </div> | ||
| `; | ||
|
|
||
| useSelector.mockImplementation((selector) => selector({ | ||
| courseHome: { courseId: 'course-v1:test+id+2024' }, | ||
| models: { | ||
| live: { | ||
| 'course-v1:test+id+2024': { | ||
| iframe: '<iframe id="lti-tab-embed"></iframe>', | ||
| }, | ||
| }, | ||
| }, | ||
| })); | ||
|
|
||
| render(<LiveTab />); | ||
|
|
||
| const iframe = document.getElementById('lti-tab-embed'); | ||
| expect(iframe.className).toContain('vh-100'); | ||
| expect(iframe.className).toContain('w-100'); | ||
| expect(iframe.className).toContain('border-0'); | ||
| }); | ||
|
|
||
| it('does not throw if iframe is not found in DOM', () => { | ||
| useSelector.mockImplementation((selector) => selector({ | ||
| courseHome: { courseId: 'course-v1:test+id+2024' }, | ||
| models: { | ||
| live: { | ||
| 'course-v1:test+id+2024': { | ||
| iframe: '<div>No iframe here</div>', | ||
| }, | ||
| }, | ||
| }, | ||
| })); | ||
|
|
||
| expect(() => render(<LiveTab />)).not.toThrow(); | ||
| const iframe = document.getElementById('lti-tab-embed'); | ||
| expect(iframe).toBeNull(); | ||
| }); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,4 @@ | ||||||||||
| import React, { useState } from 'react'; | ||||||||||
|
||||||||||
| import PropTypes from 'prop-types'; | ||||||||||
| import { useIntl } from '@edx/frontend-platform/i18n'; | ||||||||||
| import { | ||||||||||
|
|
@@ -6,10 +7,11 @@ import { | |||||||||
| OverlayTrigger, | ||||||||||
| Stack, | ||||||||||
| Tooltip, | ||||||||||
| IconButton, | ||||||||||
| } from '@openedx/paragon'; | ||||||||||
| import { InfoOutline, Locked } from '@openedx/paragon/icons'; | ||||||||||
| import { useContextId } from '../../../../data/hooks'; | ||||||||||
|
|
||||||||||
| import { useContextId } from '../../../../data/hooks'; | ||||||||||
| import messages from '../messages'; | ||||||||||
| import { useModel } from '../../../../generic/model-store'; | ||||||||||
|
|
||||||||||
|
|
@@ -20,24 +22,36 @@ 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"> | ||||||||||
| <Stack direction="horizontal" gap={2}> | ||||||||||
| <h3 className="h4 m-0">{intl.formatMessage(messages.gradeSummary)}</h3> | ||||||||||
| <OverlayTrigger | ||||||||||
| trigger="hover" | ||||||||||
| trigger="click" | ||||||||||
| placement="top" | ||||||||||
| show={showTooltip} | ||||||||||
| overlay={( | ||||||||||
| <Tooltip> | ||||||||||
| {intl.formatMessage(messages.gradeSummaryTooltipBody)} | ||||||||||
| </Tooltip> | ||||||||||
| )} | ||||||||||
| > | ||||||||||
| <Icon | ||||||||||
| <IconButton | ||||||||||
| onClick={() => { setShowTooltip(!showTooltip); }} | ||||||||||
| onBlur={() => { setShowTooltip(false); }} | ||||||||||
|
||||||||||
| onClick={() => { setShowTooltip(!showTooltip); }} | |
| onBlur={() => { setShowTooltip(false); }} | |
| onClick={() => setShowTooltip(!showTooltip)} | |
| onBlur={() => setShowTooltip(false)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,127 @@ | ||||||||||||||||||
| import React from 'react'; | ||||||||||||||||||
|
||||||||||||||||||
| 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 { fireEvent } from '@testing-library/dom'; | ||||||||||||||||||
| import GradeSummaryHeader from './GradeSummaryHeader'; | ||||||||||||||||||
|
||||||||||||||||||
| import { IntlProvider } from 'react-intl'; | |
| import { fireEvent } from '@testing-library/dom'; | |
| import GradeSummaryHeader from './GradeSummaryHeader'; | |
| import { IntlProvider } from 'react-intl'; | |
| import { fireEvent } from '@testing-library/dom'; | |
| import GradeSummaryHeader from './GradeSummaryHeader'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved
Outdated
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, removed
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please replace with use userEvent here
https://testing-library.com/docs/user-event/intro/#difference-to-fireevent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please replace with use userEvent here
https://testing-library.com/docs/user-event/intro/#difference-to-fireevent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please replace with use userEvent here
https://testing-library.com/docs/user-event/intro/#difference-to-fireevent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed