-
Notifications
You must be signed in to change notification settings - Fork 40
#398 Warn when loading saves from newer versions #1271
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
+227
−22
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
26638e2
Initial plan
Copilot 25d9073
Add version warning to ConfirmOverwriteDialog
Copilot deacbcf
Add comprehensive tests for version warning feature
Copilot 8bbbcb9
Remove redundant Number() conversion in parseVersionFromSave
Copilot 1158f3c
Make saveVersion non-optional and add version state management
Copilot 1fa55a3
rewrite parseVersionFromSave
thekingofcity 8f06cb3
update translation
thekingofcity c6768d6
update tests
thekingofcity 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
89 changes: 89 additions & 0 deletions
89
src/components/page-header/confirm-overwrite-dialog.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,89 @@ | ||
| import { screen } from '@testing-library/react'; | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
| import { render } from '../../test-utils'; | ||
| import { CURRENT_VERSION } from '../../util/save'; | ||
| import ConfirmOverwriteDialog from './confirm-overwrite-dialog'; | ||
|
|
||
| // Mock the translation hook | ||
| vi.mock('react-i18next', async () => { | ||
| const actual = await vi.importActual('react-i18next'); | ||
| return { | ||
| ...actual, | ||
| useTranslation: () => ({ | ||
| t: (key: string, options?: any) => { | ||
| if (key === 'header.open.confirmOverwrite.title') return 'Confirm overwrite'; | ||
| if (key === 'header.open.confirmOverwrite.body') | ||
| return 'This action will overwrite your current project. Any unsaved changes will be lost. Are you sure you want to continue?'; | ||
| if (key === 'header.open.confirmOverwrite.overwrite') return 'Overwrite'; | ||
| if (key === 'cancel') return 'Cancel'; | ||
| if (key === 'header.open.confirmOverwrite.newerVersion') | ||
| return `Warning: This save file is from a newer version (${options?.saveVersion}) than the current version (${options?.currentVersion}). Loading it may cause errors or undefined behavior.`; | ||
| return key; | ||
| }, | ||
| }), | ||
| }; | ||
| }); | ||
|
|
||
| describe('ConfirmOverwriteDialog', () => { | ||
| it('should not show version warning when saveVersion is 0', () => { | ||
| render(<ConfirmOverwriteDialog isOpen={true} onClose={vi.fn()} onConfirm={vi.fn()} saveVersion={0} />); | ||
|
|
||
| expect(screen.getByText('Confirm overwrite')).toBeInTheDocument(); | ||
| expect( | ||
| screen.getByText( | ||
| 'This action will overwrite your current project. Any unsaved changes will be lost. Are you sure you want to continue?' | ||
| ) | ||
| ).toBeInTheDocument(); | ||
| expect(screen.queryByText(/Warning:/)).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should not show version warning when saveVersion equals CURRENT_VERSION', () => { | ||
| render( | ||
| <ConfirmOverwriteDialog isOpen={true} onClose={vi.fn()} onConfirm={vi.fn()} saveVersion={CURRENT_VERSION} /> | ||
| ); | ||
|
|
||
| expect(screen.getByText('Confirm overwrite')).toBeInTheDocument(); | ||
| expect(screen.queryByText(/Warning:/)).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should not show version warning when saveVersion is less than CURRENT_VERSION', () => { | ||
| render( | ||
| <ConfirmOverwriteDialog | ||
| isOpen={true} | ||
| onClose={vi.fn()} | ||
| onConfirm={vi.fn()} | ||
| saveVersion={CURRENT_VERSION - 10} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.getByText('Confirm overwrite')).toBeInTheDocument(); | ||
| expect(screen.queryByText(/Warning:/)).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should show version warning when saveVersion is greater than CURRENT_VERSION', () => { | ||
| const newerVersion = CURRENT_VERSION + 10; | ||
| render( | ||
| <ConfirmOverwriteDialog isOpen={true} onClose={vi.fn()} onConfirm={vi.fn()} saveVersion={newerVersion} /> | ||
| ); | ||
|
|
||
| expect(screen.getByText('Confirm overwrite')).toBeInTheDocument(); | ||
| expect( | ||
| screen.getByText( | ||
| `Warning: This save file is from a newer version (${newerVersion}) than the current version (${CURRENT_VERSION}). Loading it may cause errors or undefined behavior.` | ||
| ) | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should render buttons correctly', () => { | ||
| render(<ConfirmOverwriteDialog isOpen={true} onClose={vi.fn()} onConfirm={vi.fn()} saveVersion={0} />); | ||
|
|
||
| expect(screen.getByText('Cancel')).toBeInTheDocument(); | ||
| expect(screen.getByText('Overwrite')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should not render when isOpen is false', () => { | ||
| render(<ConfirmOverwriteDialog isOpen={false} onClose={vi.fn()} onConfirm={vi.fn()} saveVersion={100} />); | ||
|
|
||
| expect(screen.queryByText('Confirm overwrite')).not.toBeInTheDocument(); | ||
| }); | ||
| }); |
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
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
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.