-
Notifications
You must be signed in to change notification settings - Fork 9
[OSDEV-1132] implement thanks for submitting screen FE #436
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
Merged
VadimKovalenkoSNF
merged 32 commits into
main
from
OSDEV-1132-implement-thanks-for-submitting-screen-FE
Dec 10, 2024
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
cf9da60
Implement thanks for submitting dialog (partial impl)
VadimKovalenkoSNF bfe527a
Add submit production location modal (partial impl)
VadimKovalenkoSNF 4fae202
Refactor styles
VadimKovalenkoSNF b9f216c
Apply tooltip for the claim button
VadimKovalenkoSNF 7325e3d
Abstract tooltip UI to the DialogTooltip
VadimKovalenkoSNF 9417f0e
Apply unit tests
VadimKovalenkoSNF 6723561
Minor fixes, update Release notes
VadimKovalenkoSNF 36cc496
Apply minor changes, update tests
VadimKovalenkoSNF bd9eb59
Refactor popper mock
VadimKovalenkoSNF 49eeac8
Improve tooltip settings and tests
VadimKovalenkoSNF 3c098dc
Apply proptypes
VadimKovalenkoSNF 96934da
Minor proptype fix
VadimKovalenkoSNF 80f0c94
Remove proptypes from ProductionLocationDialog
VadimKovalenkoSNF 71de095
Merge branch 'main' into OSDEV-1132-implement-thanks-for-submitting-s…
VadimKovalenkoSNF b0b02b1
Merge branch 'main' into OSDEV-1132-implement-thanks-for-submitting-s…
VadimKovalenkoSNF 21f6065
Merge branch 'main' into OSDEV-1132-implement-thanks-for-submitting-s…
VadimKovalenkoSNF f08dd6b
Merge branch 'main' into OSDEV-1132-implement-thanks-for-submitting-s…
VadimKovalenkoSNF 167e828
Merge branch 'main' into OSDEV-1132-implement-thanks-for-submitting-s…
VadimKovalenkoSNF 1738737
Merge branch 'main' into OSDEV-1132-implement-thanks-for-submitting-s…
VadimKovalenkoSNF 7dc2758
Merge branch 'main' into OSDEV-1132-implement-thanks-for-submitting-s…
VadimKovalenkoSNF 13352ff
Merge branch 'main' into OSDEV-1132-implement-thanks-for-submitting-s…
VadimKovalenkoSNF af24f30
Merge branch 'main' into OSDEV-1132-implement-thanks-for-submitting-s…
VadimKovalenkoSNF f5ce8c5
Merge branch 'main' into OSDEV-1132-implement-thanks-for-submitting-s…
VadimKovalenkoSNF 3acb03a
Merge branch 'main' into OSDEV-1132-implement-thanks-for-submitting-s…
VadimKovalenkoSNF 25308d7
Merge branch 'main' into OSDEV-1132-implement-thanks-for-submitting-s…
VadimKovalenkoSNF 1967a45
Refactor styles definition, minor fixes
VadimKovalenkoSNF 48e8a72
Remove redundant console.log
VadimKovalenkoSNF 917f981
Minor lint fix
VadimKovalenkoSNF c78c1b0
Fix unit test
VadimKovalenkoSNF e0ff124
Replace DialogTooltip, add minor changes
VadimKovalenkoSNF 8bc989a
Minor fixes for COLOUR import
VadimKovalenkoSNF 986aec6
Add aria labels
VadimKovalenkoSNF File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import React from 'react'; | ||
| import { render, screen, fireEvent, waitFor } from '@testing-library/react'; | ||
| import DialogTooltip from '../../components/Contribute/DialogTooltip'; | ||
|
|
||
| global.cancelAnimationFrame = jest.fn(); | ||
|
|
||
| jest.mock('@popperjs/core', () => ({ | ||
| __esModule: true, | ||
| default: jest.fn(() => ({ | ||
| destroy: jest.fn(), | ||
| update: jest.fn(), | ||
| scheduleUpdate: jest.fn(), | ||
| enableEventListeners: jest.fn(), | ||
| disableEventListeners: jest.fn(), | ||
| setOptions: jest.fn(), | ||
| })), | ||
| })); | ||
|
|
||
| beforeAll(() => { | ||
| global.Node = global.Node || {}; | ||
| }); | ||
|
|
||
| describe('DialogTooltip Component', () => { | ||
| test('renders tooltip on hover', async () => { | ||
| const mockChildComponent = <span>Hover over this element</span>; | ||
| const mockText = "You'll be able to claim the location after the moderation is done"; | ||
|
|
||
| render( | ||
| <DialogTooltip text={mockText} childComponent={mockChildComponent} classes={{}} /> | ||
| ); | ||
|
|
||
| expect(screen.queryByText(mockText)).not.toBeInTheDocument(); | ||
|
|
||
| fireEvent.mouseEnter(screen.getByText('Hover over this element')); | ||
| await waitFor(() => { | ||
| expect(screen.getByText(mockText)).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| test('hides tooltip on mouse leave', async () => { | ||
| const mockChildComponent = <span>Hover over this element</span>; | ||
| const mockText = "Test tooltip"; | ||
|
|
||
| render( | ||
| <DialogTooltip text={mockText} childComponent={mockChildComponent} classes={{}} /> | ||
| ); | ||
|
|
||
| const element = screen.getByText('Hover over this element'); | ||
|
|
||
| fireEvent.mouseEnter(element); | ||
| await waitFor(() => { | ||
| expect(screen.getByText(mockText)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| fireEvent.mouseLeave(element); | ||
| await waitFor(() => { | ||
| expect(screen.queryByText(mockText)).not.toBeInTheDocument(); | ||
| }); | ||
| }); | ||
| }); |
74 changes: 74 additions & 0 deletions
74
src/react/src/__tests__/components/ProductionLocationDialog.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { BrowserRouter as Router, useHistory } from 'react-router-dom'; | ||
| import UserEvent from "user-event"; | ||
| import ProductionLocationDialog from '../../components/Contribute/ProductionLocationDialog'; | ||
|
|
||
| jest.mock('react-router-dom', () => ({ | ||
| ...jest.requireActual('react-router-dom'), | ||
| useHistory: jest.fn(), | ||
| })); | ||
|
|
||
| const mockHistoryPush = jest.fn(); | ||
|
|
||
| beforeEach(() => { | ||
| useHistory.mockReturnValue({ | ||
| push: mockHistoryPush, | ||
| }); | ||
| }); | ||
|
|
||
| test('renders dialog content', () => { | ||
| render( | ||
| <Router> | ||
| <ProductionLocationDialog classes={{}} /> | ||
| </Router> | ||
| ); | ||
|
|
||
| expect(screen.getByText(/Thanks for adding data for this production location!/i)).toBeInTheDocument(); | ||
| expect(screen.getByText(/Facility name/i)).toBeInTheDocument(); | ||
| expect(screen.getByText(/OS ID/i)).toBeInTheDocument(); | ||
| expect(screen.getByText(/Pending/i)).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('should render multiple instances of text element', () => { | ||
| const text = "Unifill Composite Dyeing Mills Ltd."; | ||
|
|
||
| render( | ||
| <Router> | ||
| <ProductionLocationDialog classes={{}} /> | ||
| </Router> | ||
| ); | ||
|
|
||
| const elements = screen.getAllByText(new RegExp(text, 'i')); | ||
|
|
||
| expect(elements).toHaveLength(2); | ||
| }); | ||
|
|
||
| test('navigates when "Search OS Hub" button is clicked', () => { | ||
| render( | ||
| <Router> | ||
| <ProductionLocationDialog classes={{}} /> | ||
| </Router> | ||
| ); | ||
|
|
||
| const button = screen.getByText(/Search OS Hub/i); | ||
| UserEvent.click(button); | ||
|
|
||
| expect(mockHistoryPush).toHaveBeenCalledWith('/'); | ||
| }); | ||
|
|
||
| test('calls console log when "Submit another Location" button is clicked', () => { | ||
| const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(); | ||
|
|
||
| render( | ||
| <Router> | ||
| <ProductionLocationDialog classes={{}} /> | ||
| </Router> | ||
| ); | ||
|
|
||
| const button = screen.getByText(/Submit another Location/i); | ||
| UserEvent.click(button); | ||
|
|
||
| expect(consoleLogSpy).toHaveBeenCalledWith('submit another location'); | ||
| consoleLogSpy.mockRestore(); | ||
| }); | ||
VadimKovalenkoSNF marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import React, { useState } from 'react'; | ||
| import { shape, string, node } from 'prop-types'; | ||
| import { withStyles } from '@material-ui/core/styles'; | ||
| import Tooltip from '@material-ui/core/Tooltip'; | ||
| import { makeDialogTooltipStyles } from '../../util/styles'; | ||
|
|
||
| const DialogTooltip = ({ text, childComponent, classes }) => { | ||
| const [arrowRef, setArrowRef] = useState(null); | ||
| return ( | ||
| <Tooltip | ||
| aria-label={text} | ||
| enterDelay={200} | ||
| leaveDelay={200} | ||
| title={ | ||
| <> | ||
| {text} | ||
| <span className={classes.arrow} ref={setArrowRef} /> | ||
| </> | ||
| } | ||
| classes={{ | ||
| tooltip: classes.tooltipStyles, | ||
| popper: classes.popperStyles, | ||
| tooltipPlacementLeft: classes.placementLeft, | ||
| tooltipPlacementRight: classes.placementRight, | ||
| tooltipPlacementTop: classes.placementTop, | ||
| tooltipPlacementBottom: classes.placementBottom, | ||
| }} | ||
| PopperProps={{ | ||
| popperOptions: { | ||
| modifiers: { | ||
| arrow: { | ||
| enabled: Boolean(arrowRef), | ||
| element: arrowRef, | ||
| }, | ||
| }, | ||
| }, | ||
| }} | ||
| > | ||
| {childComponent} | ||
| </Tooltip> | ||
| ); | ||
| }; | ||
|
|
||
| DialogTooltip.propTypes = { | ||
| text: string.isRequired, | ||
| childComponent: node.isRequired, | ||
| classes: shape({ | ||
| arrow: shape({}).isRequired, | ||
| tooltipStyles: shape({}).isRequired, | ||
| popperStyles: shape({}).isRequired, | ||
| placementLeft: shape({}).isRequired, | ||
| placementRight: shape({}).isRequired, | ||
| placementTop: shape({}).isRequired, | ||
| placementBottom: shape({}).isRequired, | ||
| }).isRequired, | ||
| }; | ||
|
|
||
| export default withStyles(makeDialogTooltipStyles)(DialogTooltip); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.