-
Notifications
You must be signed in to change notification settings - Fork 0
fix(clock): stop tick-driven re-renders in registration widget #145
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b1b1295
fix(clock): stop tick-driven re-renders in registration widget
gcutrini 70c621d
chore(deps): add spark-md5 to satisfy openstack-uicore-foundation peer
gcutrini 21a84a0
fix(clock): use Math.floor for unix seconds in ClockProvider seed
gcutrini 80a143b
test(registration-form): exercise isTicketCurrentlyAvailable via render
gcutrini c05158b
test(purchase-complete): cover both useClockSelector branches
gcutrini 94178c5
test(withWidgetProviders): cover the re-render path with a fresh time…
gcutrini 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
78 changes: 78 additions & 0 deletions
78
src/components/purchase-complete/__tests__/purchase-complete.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,78 @@ | ||
| import React from 'react'; | ||
| import { cleanup, render, act } from '@testing-library/react'; | ||
| import '@testing-library/jest-dom'; | ||
|
|
||
| // Settable clock seed (the `mock` prefix is the only identifier jest.mock | ||
| // allows the factory to capture via closure). | ||
| let mockClockNow = 0; | ||
| jest.mock('openstack-uicore-foundation/lib/components/clock-context', () => ({ | ||
| useClockSelector: (selector) => selector(mockClockNow), | ||
| })); | ||
|
|
||
| // epochToMomentTimeZone returns an object with .format(). Keep it cheap and | ||
| // deterministic so the test doesn't depend on moment / timezone data. | ||
| jest.mock('openstack-uicore-foundation/lib/utils/methods', () => ({ | ||
| epochToMomentTimeZone: jest.fn(() => ({ format: (fmt) => fmt === 'MMMM D' ? 'January 1' : '09:00 AM' })), | ||
| })); | ||
|
|
||
| jest.mock('openstack-uicore-foundation/lib/components/raw-html', () => (props) => <div>{props.children}</div>); | ||
|
|
||
| import PurchaseComplete from '..'; | ||
|
|
||
| const SUMMIT = { | ||
| start_date: 1_700_000_000, // ~Nov 2023 | ||
| end_date: 1_700_086_400, | ||
| time_zone_id: 'UTC', | ||
| time_zone_label: 'UTC', | ||
| }; | ||
|
|
||
| const defaultProps = { | ||
| checkout: { tickets: [{ owner: { email: 'john@example.com' }, badge: {} }] }, | ||
| user: { email: 'john@example.com' }, | ||
| onPurchaseComplete: jest.fn(), | ||
| goToExtraQuestions: jest.fn(), | ||
| goToEvent: jest.fn(), | ||
| goToMyOrders: jest.fn(), | ||
| // The component waits on this promise before rendering the branch we want | ||
| // to assert, so resolve it synchronously to a deterministic value. | ||
| completedExtraQuestions: jest.fn(() => Promise.resolve(false)), | ||
| summit: SUMMIT, | ||
| clearWidgetState: jest.fn(), | ||
| closeWidget: jest.fn(), | ||
| supportEmail: 'help@example.com', | ||
| hasVirtualAccessLevel: false, | ||
| }; | ||
|
|
||
| afterEach(() => { | ||
| cleanup(); | ||
| jest.clearAllMocks(); | ||
| mockClockNow = 0; | ||
| }); | ||
|
|
||
| const renderAndFlush = async (props = {}) => { | ||
| let utils; | ||
| await act(async () => { | ||
| utils = render(<PurchaseComplete {...defaultProps} {...props} />); | ||
| }); | ||
| return utils; | ||
| }; | ||
|
|
||
| it('renders the active CTA path when the clock seed falls inside the summit window', async () => { | ||
| mockClockNow = SUMMIT.start_date + 1000; | ||
| const { queryByText } = await renderAndFlush(); | ||
|
|
||
| // The "event will start on…" copy belongs to the inactive branch. | ||
| expect(queryByText(/event will start on/i)).not.toBeInTheDocument(); | ||
| // The CTA in the active path with no required extra questions falls through | ||
| // to the My Orders/Tickets button. | ||
| expect(queryByText('View My Orders/Tickets')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders the "event will start" copy when the clock seed is outside the summit window', async () => { | ||
| mockClockNow = SUMMIT.end_date + 1; // one second past end | ||
| const { queryByText } = await renderAndFlush(); | ||
|
|
||
| expect(queryByText(/The event will start on January 1 at 09:00 AM UTC/)).toBeInTheDocument(); | ||
| // CTA still renders in the inactive branch (different layout). | ||
| expect(queryByText('View My Orders/Tickets')).toBeInTheDocument(); | ||
| }); |
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
Oops, something went wrong.
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.
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
__tests__/directory exists forPurchaseComplete. TheisActivevalue is now derived fromuseClockSelector, but neither branch is exercised: the active-summit CTA path (isActive === true) and the "event will start on…" path (isActive === false) are both untested.Missing: mount
PurchaseCompletewith a mockeduseClockSelectorthat returns a timestamp insidesummit.start_date / summit.end_dateand assert the active CTA renders; then one where the timestamp is outside the window and assert the "event will start" copy renders.