-
-
Notifications
You must be signed in to change notification settings - Fork 624
fix(person-images): prevent flash of previous page's images (#1315) #1321
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
tanmaysachann
wants to merge
2
commits into
AOSSIE-Org:main
Choose a base branch
from
tanmaysachann:fix/1315-ai-tagging-page-flash
base: main
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.
+119
−3
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import { render, screen, waitFor } from '@/test-utils'; | ||
| import { Routes, Route } from 'react-router'; | ||
| import { PersonImages } from '@/pages/PersonImages/PersonImages'; | ||
| import type { Image } from '@/types/Media'; | ||
| import * as apiFunctions from '@/api/api-functions'; | ||
|
|
||
| // ImageCard resolves thumbnails through Tauri's convertFileSrc; return the path | ||
| // unchanged so we can assert which person's images are in the DOM by their src. | ||
| jest.mock('@tauri-apps/api/core', () => ({ | ||
| invoke: jest.fn().mockResolvedValue(null), | ||
| convertFileSrc: (path: string) => path, | ||
| })); | ||
|
|
||
| jest.mock('@/api/api-functions', () => ({ | ||
| fetchClusterImages: jest.fn(), | ||
| renameCluster: jest.fn(), | ||
| })); | ||
|
|
||
| const fetchClusterImages = apiFunctions.fetchClusterImages as jest.Mock; | ||
|
|
||
| const makeImage = (id: string, path: string): Image => ({ | ||
| id, | ||
| path, | ||
| thumbnailPath: path, | ||
| folder_id: 'folder', | ||
| isTagged: true, | ||
| isFavourite: false, | ||
| tags: [], | ||
| }); | ||
|
|
||
| // "Person A" stands in for whatever the previous page (e.g. the Home gallery) | ||
| // left in the shared `images` slice; "Person B" is the cluster we navigate to. | ||
| const personAImages = [ | ||
| makeImage('a1', '/personA/1.jpg'), | ||
| makeImage('a2', '/personA/2.jpg'), | ||
| ]; | ||
| const personBImages = [ | ||
| makeImage('b1', '/personB/1.jpg'), | ||
| makeImage('b2', '/personB/2.jpg'), | ||
| ]; | ||
|
|
||
| const renderPerson = (clusterId: string) => | ||
| render( | ||
| <Routes> | ||
| <Route path="/person/:clusterId" element={<PersonImages />} /> | ||
| </Routes>, | ||
| { | ||
| // Pre-seed the shared slice with the previous page's images. This is the | ||
| // exact condition that produced the flash described in issue #1315. | ||
| preloadedState: { | ||
| images: { images: personAImages, currentViewIndex: -1 }, | ||
| }, | ||
| initialRoutes: [`/person/${clusterId}`], | ||
| }, | ||
| ); | ||
|
|
||
| const imageSrcs = (container: HTMLElement) => | ||
| Array.from(container.querySelectorAll('img')).map((img) => | ||
| img.getAttribute('src'), | ||
| ); | ||
|
|
||
| const hasPersonA = (container: HTMLElement) => | ||
| imageSrcs(container).some((src) => src?.startsWith('/personA/')); | ||
| const hasPersonB = (container: HTMLElement) => | ||
| imageSrcs(container).some((src) => src?.startsWith('/personB/')); | ||
|
|
||
| beforeEach(() => { | ||
| fetchClusterImages.mockReset(); | ||
| fetchClusterImages.mockImplementation(async ({ clusterId }) => ({ | ||
| success: true, | ||
| data: { | ||
| images: clusterId === 'B' ? personBImages : personAImages, | ||
| cluster_name: clusterId === 'B' ? 'Bob' : 'Alice', | ||
| }, | ||
| })); | ||
| }); | ||
|
|
||
| describe('PersonImages (issue #1315: no flash of the previous page)', () => { | ||
| test('never paints the stale slice images, on the first frame or after', async () => { | ||
| const { container } = renderPerson('B'); | ||
|
|
||
| // First frame: before the cluster query resolves, the shared slice still | ||
| // holds Person A's images. The grid must not paint them, otherwise the user | ||
| // sees the flash. (This assertion fails against the pre-fix code.) | ||
| expect(hasPersonA(container)).toBe(false); | ||
|
|
||
| // Let the query resolve, then confirm Person A never appears at any point. | ||
| await waitFor(() => { | ||
| expect(hasPersonB(container)).toBe(true); | ||
| }); | ||
| expect(hasPersonA(container)).toBe(false); | ||
| }); | ||
|
|
||
| test("renders the navigated cluster's images and name once loaded", async () => { | ||
| const { container } = renderPerson('B'); | ||
|
|
||
| expect(await screen.findByText('Bob')).toBeInTheDocument(); | ||
| await waitFor(() => { | ||
| expect(hasPersonB(container)).toBe(true); | ||
| }); | ||
| }); | ||
| }); |
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.