Skip to content

Commit 0b9f94c

Browse files
Disarm setConfirmOverwrite in loadProjects
1 parent ad59825 commit 0b9f94c

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/__tests__/components/modals/SaveAsProjectModal.test.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,26 @@ describe('SaveAsProjectModal', () => {
148148
expect(screen.queryByText('Overwrite this project with the draft?')).not.toBeInTheDocument();
149149
});
150150

151+
it('clears an armed overwrite confirm when the source changes so a stale target cannot be used', async () => {
152+
mockSendCommand
153+
.mockResolvedValueOnce(JSON.stringify([STUB_PROJECT]))
154+
.mockResolvedValueOnce(JSON.stringify([STUB_PROJECT_2]));
155+
const { rerender } = render(<SaveAsProjectModal {...defaultProps} />);
156+
157+
// Arm the overwrite confirm against the first source's project.
158+
await waitFor(() => expect(screen.getByText('Unnamed')).toBeInTheDocument());
159+
const row = screen.getByText('Unnamed').closest('li');
160+
if (!row) throw new Error('expected the project row to be present');
161+
await userEvent.click(within(row).getByRole('button', { name: 'Overwrite' }));
162+
expect(screen.getByText('Overwrite this project with the draft?')).toBeInTheDocument();
163+
164+
// Switching sources must drop the stale confirm rather than carry it into the new list.
165+
rerender(<SaveAsProjectModal {...defaultProps} sourceProjectId="src-proj-2" />);
166+
167+
await waitFor(() => expect(screen.getByText('French glosses')).toBeInTheDocument());
168+
expect(screen.queryByText('Overwrite this project with the draft?')).not.toBeInTheDocument();
169+
});
170+
151171
it('logs and notifies when loading the project list rejects', async () => {
152172
const loadError = new Error('network error');
153173
mockSendCommand.mockRejectedValue(loadError);

src/components/modals/SaveAsProjectModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export function SaveAsProjectModal({
9393
const gen = loadGenRef.current;
9494
setIsLoading(true);
9595
setProjects([]);
96+
setConfirmOverwrite(undefined);
9697
try {
9798
const json = await papi.commands.sendCommand(
9899
'interlinearizer.getProjectsForSource',

0 commit comments

Comments
 (0)