-
Notifications
You must be signed in to change notification settings - Fork 149
fix: keep displayed orders in progress state and dedupe favicon completions #6510
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
Open
fairlighteth
wants to merge
5
commits into
develop
Choose a base branch
from
fix/progress-solvers
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9099761
fix: add atom for surplus order IDs and integrate into OrderProgressS…
fairlighteth 6299cc0
fix: enhance order completion handling with caching and cleanup logic
fairlighteth b5b8e4f
docs: clarify handling of surplus and confirmation modals in OrderPro…
fairlighteth 9d9220e
Merge branch 'develop' into fix/progress-solvers
fairlighteth f1c5b22
refactor: streamline order progress state management and enhance test…
fairlighteth 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
106 changes: 106 additions & 0 deletions
106
apps/cowswap-frontend/src/modules/application/utils/faviconAnimation/controller.test.ts
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,106 @@ | ||
| jest.mock('common/favicon', () => { | ||
| const mockPlay = jest.fn() | ||
|
|
||
| class MockFaviconAnimator { | ||
| play(_frames: string[], options?: { onComplete?: () => void }): void { | ||
| mockPlay(_frames) | ||
| options?.onComplete?.() | ||
| } | ||
| stop(): void {} | ||
| resetToDefault(): void {} | ||
| setDefaultFrame(): void {} | ||
| isAnimationRunning(): boolean { | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| FaviconAnimator: MockFaviconAnimator, | ||
| frameDurations: { | ||
| solving: 100, | ||
| completed: 100, | ||
| completedHold: 100, | ||
| backToDefault: 100, | ||
| }, | ||
| __mockPlay__: mockPlay, | ||
| } | ||
| }) | ||
|
|
||
| import { OrderProgressBarStepName } from 'modules/orderProgressBar' | ||
| import { OrderProgressBarState } from 'modules/orderProgressBar/types' | ||
|
|
||
| import { FaviconAnimationController } from './controller' | ||
|
|
||
| const { __mockPlay__: mockPlay } = jest.requireMock('common/favicon') as { __mockPlay__: jest.Mock } | ||
|
|
||
| describe('FaviconAnimationController', () => { | ||
| const frameSet = { | ||
| defaultFrame: 'default.ico', | ||
| completedFrames: ['completed-1', 'completed-2'], | ||
| completedHoldFrame: 'completed-hold', | ||
| backToDefaultFrames: ['back-1'], | ||
| solvingFrames: ['solving-1'], | ||
| } | ||
|
|
||
| const NOW = 10_000 | ||
|
|
||
| function successState(): OrderProgressBarState { | ||
| return { | ||
| progressBarStepName: OrderProgressBarStepName.FINISHED, | ||
| lastTimeChangedSteps: NOW, | ||
| } | ||
| } | ||
|
|
||
| function solvingState(): OrderProgressBarState { | ||
| return { | ||
| progressBarStepName: OrderProgressBarStepName.SOLVING, | ||
| lastTimeChangedSteps: NOW, | ||
| countdown: 5, | ||
| } | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| jest.spyOn(Date, 'now').mockReturnValue(NOW) | ||
| mockPlay.mockClear() | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| jest.restoreAllMocks() | ||
| }) | ||
|
|
||
| function countCompletionPlays(): number { | ||
| return mockPlay.mock.calls.filter(([frames]) => frames === frameSet.completedFrames).length | ||
| } | ||
|
|
||
| it('only queues a completion animation once for the same finished state', () => { | ||
| const controller = new FaviconAnimationController(frameSet) | ||
|
|
||
| controller.update({ orderA: successState() }) | ||
| controller.update({}) // state pruned temporarily | ||
| controller.update({ orderA: successState() }) // re-added while still success | ||
|
|
||
| expect(countCompletionPlays()).toBe(1) | ||
| }) | ||
|
|
||
| it('queues another completion when an order returns to solving and finishes again', () => { | ||
| const controller = new FaviconAnimationController(frameSet) | ||
|
|
||
| controller.update({ orderA: successState() }) | ||
| controller.update({ orderA: solvingState() }) | ||
| controller.update({ orderA: successState() }) | ||
|
|
||
| expect(countCompletionPlays()).toBe(2) | ||
| }) | ||
|
|
||
| it('ignores completion animations triggered while another order is still in progress', () => { | ||
| const controller = new FaviconAnimationController(frameSet) | ||
|
|
||
| controller.update({ orderA: successState(), orderB: solvingState() }) | ||
| // Completing while another order is still solving should not enqueue anything. | ||
| expect(countCompletionPlays()).toBe(0) | ||
|
|
||
| controller.update({ orderB: successState() }) | ||
|
|
||
| expect(countCompletionPlays()).toBe(1) | ||
| }) | ||
| }) |
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
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.