Skip to content

Commit

Permalink
fix: cheats and saves not persisting properly automatically
Browse files Browse the repository at this point in the history
- fixes issues with bulk upload of cheats/saves not persisting properly

- due to the fact that we weren't using the callback on these helpers, as they don't return a promise (yet)

- probably a cleaner way to express this, will do in the future after some core updates to these helper funcs
  • Loading branch information
thenick775 committed Nov 19, 2024
1 parent fffd7c3 commit 23508d9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
15 changes: 12 additions & 3 deletions gbajs3/src/components/modals/upload-cheats.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ describe('<UploadCheatsModal />', () => {
await userEvent.click(screen.getByRole('button', { name: 'Upload' }));

expect(uploadCheatsSpy).toHaveBeenCalledOnce();
expect(uploadCheatsSpy).toHaveBeenCalledWith(testCheatFile);
expect(uploadCheatsSpy).toHaveBeenCalledWith(
testCheatFile,
expect.anything()
);
expect(syncActionIfEnabledSpy).toHaveBeenCalledOnce();

expect(screen.getByText('Upload complete!')).toBeVisible();
Expand Down Expand Up @@ -105,8 +108,14 @@ describe('<UploadCheatsModal />', () => {
await userEvent.click(screen.getByRole('button', { name: 'Upload' }));

expect(uploadCheatsSpy).toHaveBeenCalledTimes(2);
expect(uploadCheatsSpy).toHaveBeenCalledWith(testCheatFiles[0]);
expect(uploadCheatsSpy).toHaveBeenCalledWith(testCheatFiles[1]);
expect(uploadCheatsSpy).toHaveBeenCalledWith(
testCheatFiles[0],
expect.anything()
);
expect(uploadCheatsSpy).toHaveBeenCalledWith(
testCheatFiles[1],
expect.anything()
);
expect(syncActionIfEnabledSpy).toHaveBeenCalledOnce();

expect(screen.getByText('Upload complete!')).toBeVisible();
Expand Down
12 changes: 10 additions & 2 deletions gbajs3/src/components/modals/upload-cheats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,16 @@ export const UploadCheatsModal = () => {
[reset, setValue]
);

const onSubmit: SubmitHandler<InputProps> = ({ cheatFiles }) => {
cheatFiles.forEach((cheatFiles) => emulator?.uploadCheats(cheatFiles));
const onSubmit: SubmitHandler<InputProps> = async ({ cheatFiles }) => {
await Promise.all(
cheatFiles.map(
(cheatFile) =>
new Promise<void>((resolve) => {
emulator?.uploadCheats(cheatFile, resolve);
})
)
);

reset();
syncActionIfEnabled();
};
Expand Down
15 changes: 12 additions & 3 deletions gbajs3/src/components/modals/upload-saves.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ describe('<UploadSavesModal />', () => {
await userEvent.click(screen.getByRole('button', { name: 'Upload' }));

expect(uploadSaveOrSaveStateSpy).toHaveBeenCalledOnce();
expect(uploadSaveOrSaveStateSpy).toHaveBeenCalledWith(testSaveFile);
expect(uploadSaveOrSaveStateSpy).toHaveBeenCalledWith(
testSaveFile,
expect.anything()
);
expect(syncActionIfEnabledSpy).toHaveBeenCalledOnce();

expect(screen.getByText('Upload complete!')).toBeVisible();
Expand Down Expand Up @@ -104,8 +107,14 @@ describe('<UploadSavesModal />', () => {
await userEvent.click(screen.getByRole('button', { name: 'Upload' }));

expect(uploadSaveSpy).toHaveBeenCalledTimes(2);
expect(uploadSaveSpy).toHaveBeenCalledWith(testSaveFiles[0]);
expect(uploadSaveSpy).toHaveBeenCalledWith(testSaveFiles[1]);
expect(uploadSaveSpy).toHaveBeenCalledWith(
testSaveFiles[0],
expect.anything()
);
expect(uploadSaveSpy).toHaveBeenCalledWith(
testSaveFiles[1],
expect.anything()
);
expect(syncActionIfEnabledSpy).toHaveBeenCalledOnce();

expect(screen.getByText('Upload complete!')).toBeVisible();
Expand Down
12 changes: 10 additions & 2 deletions gbajs3/src/components/modals/upload-saves.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,16 @@ export const UploadSavesModal = () => {
[reset, setValue]
);

const onSubmit: SubmitHandler<InputProps> = ({ saveFiles }) => {
saveFiles.forEach((saveFile) => emulator?.uploadSaveOrSaveState(saveFile));
const onSubmit: SubmitHandler<InputProps> = async ({ saveFiles }) => {
await Promise.all(
saveFiles.map(
(saveFile) =>
new Promise<void>((resolve) => {
emulator?.uploadSaveOrSaveState(saveFile, resolve);
})
)
);

reset();
syncActionIfEnabled();
};
Expand Down

0 comments on commit 23508d9

Please sign in to comment.