-
Notifications
You must be signed in to change notification settings - Fork 5.5k
fix(onboarding): fox animation not resizing dynamically on welcome page #41499
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
+177
−6
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d549eb1
fix(onboarding): fox animation not resizing dynamically on welcome page
smgv 5846f92
Merge branch 'main' into fix/fox-animation-resize
smgv 611a20a
fix: updated test case for animation
smgv ec39851
Merge branch 'main' into fix/fox-animation-resize
smgv 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
138 changes: 138 additions & 0 deletions
138
ui/pages/onboarding-flow/welcome/fox-appear-animation.test.tsx
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,138 @@ | ||
| import React from 'react'; | ||
| import { render, screen, act } from '@testing-library/react'; | ||
| import * as riveReactCanvas from '@rive-app/react-canvas'; | ||
| import * as riveWasmContext from '../../../contexts/rive-wasm'; | ||
| import FoxAppearAnimation from './fox-appear-animation'; | ||
|
|
||
| const mockStartFire = jest.fn(); | ||
| const mockWiggleFire = jest.fn(); | ||
| const mockLoaderFire = jest.fn(); | ||
|
|
||
| const mockInputs = [ | ||
| { name: 'Start', fire: mockStartFire }, | ||
| { name: 'Wiggle', fire: mockWiggleFire }, | ||
| { name: 'Loader2', fire: mockLoaderFire }, | ||
| ]; | ||
|
|
||
| jest.mock('@rive-app/react-canvas', () => ({ | ||
| useRive: jest.fn(), | ||
| useRiveFile: jest.fn(), | ||
| Layout: jest.fn(), | ||
| Fit: { Contain: 'contain' }, | ||
| Alignment: { BottomCenter: 'bottomCenter' }, | ||
| })); | ||
|
|
||
| jest.mock('../../../contexts/rive-wasm', () => ({ | ||
| useRiveWasmContext: jest.fn(), | ||
| useRiveWasmFile: jest.fn(), | ||
| })); | ||
|
|
||
| const mockedRive = jest.mocked(riveReactCanvas); | ||
| const mockedWasm = jest.mocked(riveWasmContext); | ||
|
|
||
| function setDefaultMocks(rive: Record<string, jest.Mock> | null = null) { | ||
| mockedWasm.useRiveWasmContext.mockReturnValue({ | ||
| isWasmReady: true, | ||
| loading: false, | ||
| error: undefined, | ||
| urlBufferMap: {}, | ||
| setUrlBufferCache: jest.fn(), | ||
| animationCompleted: {}, | ||
| setIsAnimationCompleted: jest.fn(), | ||
| }); | ||
| mockedWasm.useRiveWasmFile.mockReturnValue({ | ||
| buffer: new ArrayBuffer(8), | ||
| error: undefined, | ||
| loading: false, | ||
| }); | ||
| mockedRive.useRiveFile.mockReturnValue({ | ||
| riveFile: { name: 'mock' } as unknown as riveReactCanvas.RiveFile, | ||
| status: 'success', | ||
| }); | ||
| mockedRive.useRive.mockReturnValue({ | ||
| rive, | ||
| RiveComponent: () => <canvas data-testid="rive-component" />, | ||
| } as unknown as ReturnType<typeof riveReactCanvas.useRive>); | ||
| } | ||
|
|
||
| function createRiveInstance() { | ||
| return { | ||
| play: jest.fn(), | ||
| cleanup: jest.fn(), | ||
| resizeToCanvas: jest.fn(), | ||
| stateMachineInputs: jest.fn(() => mockInputs), | ||
| }; | ||
| } | ||
|
|
||
| describe('FoxAppearAnimation', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| setDefaultMocks(); | ||
| }); | ||
|
|
||
| it('renders the Rive component when all resources are ready', () => { | ||
| render(<FoxAppearAnimation />); | ||
|
|
||
| expect(screen.getByTestId('rive-component')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders a placeholder with spinner when resources are not ready and isLoader is true', () => { | ||
| mockedWasm.useRiveWasmContext.mockReturnValue({ | ||
| isWasmReady: false, | ||
| loading: true, | ||
| error: undefined, | ||
| urlBufferMap: {}, | ||
| setUrlBufferCache: jest.fn(), | ||
| animationCompleted: {}, | ||
| setIsAnimationCompleted: jest.fn(), | ||
| }); | ||
|
|
||
| render(<FoxAppearAnimation isLoader />); | ||
|
|
||
| expect(screen.queryByTestId('rive-component')).not.toBeInTheDocument(); | ||
| expect(screen.getByTestId('loading-indicator')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('fires Start trigger and plays the animation on mount', () => { | ||
| const riveInstance = createRiveInstance(); | ||
| setDefaultMocks(riveInstance); | ||
|
|
||
| render(<FoxAppearAnimation />); | ||
|
|
||
| expect(mockStartFire).toHaveBeenCalled(); | ||
| expect(riveInstance.play).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('fires Wiggle and Loader2 triggers when skipTransition and isLoader are true', () => { | ||
| const riveInstance = createRiveInstance(); | ||
| setDefaultMocks(riveInstance); | ||
|
|
||
| render(<FoxAppearAnimation skipTransition isLoader />); | ||
|
|
||
| expect(mockWiggleFire).toHaveBeenCalled(); | ||
| expect(mockStartFire).not.toHaveBeenCalled(); | ||
| expect(mockLoaderFire).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('syncs canvas size on window resize and cleans up the listener on unmount', () => { | ||
| const riveInstance = createRiveInstance(); | ||
| setDefaultMocks(riveInstance); | ||
| const addSpy = jest.spyOn(window, 'addEventListener'); | ||
| const removeSpy = jest.spyOn(window, 'removeEventListener'); | ||
|
|
||
| const { unmount } = render(<FoxAppearAnimation />); | ||
|
|
||
| expect(addSpy).toHaveBeenCalledWith('resize', expect.any(Function)); | ||
|
|
||
| act(() => { | ||
| window.dispatchEvent(new Event('resize')); | ||
| }); | ||
| expect(riveInstance.resizeToCanvas).toHaveBeenCalled(); | ||
|
|
||
| unmount(); | ||
| expect(removeSpy).toHaveBeenCalledWith('resize', expect.any(Function)); | ||
|
|
||
| addSpy.mockRestore(); | ||
| removeSpy.mockRestore(); | ||
| }); | ||
| }); | ||
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.