diff --git a/frontend/src/components/session/ChangesWalkthroughSheet.test.tsx b/frontend/src/components/session/ChangesWalkthroughSheet.test.tsx index ebf7c931..9b58ef33 100644 --- a/frontend/src/components/session/ChangesWalkthroughSheet.test.tsx +++ b/frontend/src/components/session/ChangesWalkthroughSheet.test.tsx @@ -73,6 +73,7 @@ describe('ChangesWalkthroughSheet', () => { Element.prototype.setPointerCapture ??= () => {} Element.prototype.releasePointerCapture ??= () => {} Element.prototype.scrollIntoView ??= () => {} + Element.prototype.scrollTo ??= () => {} }) beforeEach(() => { @@ -198,6 +199,27 @@ describe('ChangesWalkthroughSheet', () => { }) }) + it('scrolls back to the top of the overview when a walkthrough is regenerated', async () => { + const user = userEvent.setup() + const scrollTo = vi.spyOn(Element.prototype, 'scrollTo') + let createdAt = 1 + mocks.getChangeWalkthrough.mockImplementation(async () => state({ walkthrough: { ...walkthrough, createdAt } })) + mocks.generateChangeWalkthrough.mockImplementation(async () => { + createdAt = 2 + return state({ walkthrough: { ...walkthrough, createdAt } }) + }) + renderSheet() + + await user.click(await screen.findByRole('button', { name: '1. Add the greeting' })) + expect(await screen.findByText('1 of 2')).toBeInTheDocument() + + scrollTo.mockClear() + await user.click(screen.getByRole('button', { name: 'Regenerate walkthrough' })) + + await waitFor(() => expect(scrollTo).toHaveBeenCalledWith({ top: 0 })) + expect(await screen.findByText('Overview')).toBeInTheDocument() + }) + it('shows progress while the server is generating instead of the generate button', async () => { mocks.getChangeWalkthrough.mockResolvedValue(state({ walkthrough: null, generating: true })) renderSheet() diff --git a/frontend/src/components/session/ChangesWalkthroughSheet.tsx b/frontend/src/components/session/ChangesWalkthroughSheet.tsx index 00af3202..ab1abf1a 100644 --- a/frontend/src/components/session/ChangesWalkthroughSheet.tsx +++ b/frontend/src/components/session/ChangesWalkthroughSheet.tsx @@ -129,6 +129,7 @@ export function ChangesWalkthroughProvider({ sessionId, active, children }: Chan useEffect(() => { setStopIndex(null) + scrollRef.current?.scrollTo?.({ top: 0 }) }, [active, sessionId, walkthrough?.createdAt]) const hunksById = new Map(walkthrough?.hunks.map((hunk) => [hunk.id, hunk]) ?? [])