-
Notifications
You must be signed in to change notification settings - Fork 303
fix(profile): stop work experience skills failing to save in silence #6645
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
rebelchris
merged 2 commits into
main
from
fix/work-experience-skills-silent-save-failure
Sep 11, 2026
Merged
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
100 changes: 100 additions & 0 deletions
100
packages/shared/src/components/modals/DirtyFormModal.spec.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,100 @@ | ||
| import React from 'react'; | ||
| import { act, render, screen, waitFor } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import DirtyFormModal from './DirtyFormModal'; | ||
|
|
||
| const mockCloseModal = jest.fn(); | ||
|
|
||
| jest.mock('../../hooks/useLazyModal', () => ({ | ||
| useLazyModal: () => ({ closeModal: mockCloseModal }), | ||
| })); | ||
|
|
||
| const renderModal = (onSave: () => void | Promise<void>) => | ||
| render( | ||
| <DirtyFormModal | ||
| isOpen | ||
| onRequestClose={jest.fn()} | ||
| onDiscard={jest.fn()} | ||
| onSave={onSave} | ||
| />, | ||
| ); | ||
|
|
||
| describe('DirtyFormModal', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('closes immediately for a synchronous save', async () => { | ||
| renderModal(jest.fn()); | ||
|
|
||
| await userEvent.click(screen.getByRole('button', { name: 'Save changes' })); | ||
|
|
||
| expect(mockCloseModal).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('stays open until an async save settles', async () => { | ||
| let resolveSave: () => void; | ||
| const onSave = jest.fn( | ||
| () => | ||
| new Promise<void>((resolve) => { | ||
| resolveSave = resolve; | ||
| }), | ||
| ); | ||
|
|
||
| renderModal(onSave); | ||
|
|
||
| await userEvent.click(screen.getByRole('button', { name: 'Save changes' })); | ||
|
|
||
| expect(onSave).toHaveBeenCalled(); | ||
| expect(mockCloseModal).not.toHaveBeenCalled(); | ||
| expect(screen.getByRole('button', { name: 'Discard' })).toBeDisabled(); | ||
|
|
||
| await act(async () => { | ||
| resolveSave(); | ||
| }); | ||
|
|
||
| await waitFor(() => expect(mockCloseModal).toHaveBeenCalledTimes(1)); | ||
| }); | ||
|
|
||
| it('cannot be dismissed while an async save is in flight', async () => { | ||
| let resolveSave: () => void; | ||
| const onRequestClose = jest.fn(); | ||
| const onSave = jest.fn( | ||
| () => | ||
| new Promise<void>((resolve) => { | ||
| resolveSave = resolve; | ||
| }), | ||
| ); | ||
|
|
||
| render( | ||
| <DirtyFormModal | ||
| isOpen | ||
| onRequestClose={onRequestClose} | ||
| onDiscard={jest.fn()} | ||
| onSave={onSave} | ||
| />, | ||
| ); | ||
|
|
||
| await userEvent.click(screen.getByRole('button', { name: 'Save changes' })); | ||
|
|
||
| await userEvent.keyboard('{Escape}'); | ||
| expect(onRequestClose).not.toHaveBeenCalled(); | ||
| expect(mockCloseModal).not.toHaveBeenCalled(); | ||
|
|
||
| await act(async () => { | ||
| resolveSave(); | ||
| }); | ||
|
|
||
| await waitFor(() => expect(mockCloseModal).toHaveBeenCalledTimes(1)); | ||
| }); | ||
|
|
||
| it('closes after a rejected save so the form and its error stay visible', async () => { | ||
| const onSave = jest.fn(() => Promise.reject(new Error('nope'))); | ||
|
|
||
| renderModal(onSave); | ||
|
|
||
| await userEvent.click(screen.getByRole('button', { name: 'Save changes' })); | ||
|
|
||
| await waitFor(() => expect(mockCloseModal).toHaveBeenCalledTimes(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.
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.
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.
Non-blocking question: while
isSavingis true only the two buttons are disabled; the modal itself can still be dismissed via Escape/overlay through the defaultonRequestClose. If that happens mid-save, thisfinallylater callscloseModal()on whatever lazy modal is current at that point (possibly a different one the user opened in the meantime), andsetIsSavingfires on an unmounted component. Consider either blockingonRequestClosewhile saving or tracking mount state before callingcloseModal()infinally. Low likelihood given the short window, so a judgment call.Reviewed by AI.