Skip to content

Commit

Permalink
feat(onboarding): dont clear suggested in resetPresetProgress
Browse files Browse the repository at this point in the history
  • Loading branch information
vanilla-wave committed Sep 30, 2024
1 parent b18acd6 commit b76b954
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
13 changes: 9 additions & 4 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,10 @@ export class Controller<HintParams, Presets extends string, Steps extends string
}
};

resetPresetProgress = async (presetArg: string | string[]) => {
resetPresetProgress = async (
presetArg: string | string[],
{removeFromSuggested} = {removeFromSuggested: false},
) => {
this.logger.debug('Reset progress for', presetArg);
await this.ensureRunning();
this.assertProgressLoaded();
Expand All @@ -494,9 +497,11 @@ export class Controller<HintParams, Presets extends string, Steps extends string
(preset) => !presets.includes(preset as Presets),
);

this.state.base.suggestedPresets = this.state.base.activePresets.filter(
(preset) => !presets.includes(preset as Presets),
);
if (removeFromSuggested) {
this.state.base.suggestedPresets = this.state.base.activePresets.filter(
(preset) => !presets.includes(preset as Presets),
);
}

await this.updateBaseState();
await this.updateProgress();
Expand Down
4 changes: 3 additions & 1 deletion src/promo-manager/core/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ export class Controller {
this.state.progress = JSON.parse(JSON.stringify(defaultProgressState)) as ProgressState;

if (this.options.onboarding) {
await this.options.onboarding.getInstance().resetPresetProgress([...this.promoPresets]);
await this.options.onboarding
.getInstance()
.resetPresetProgress([...this.promoPresets], {removeFromSuggested: true});
}

this.emitChange();
Expand Down
23 changes: 15 additions & 8 deletions src/tests/commonPresets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,25 @@ describe('preset management', function () {
const controller = new Controller(options);
await controller.resetPresetProgress(['createProject', 'createQueue']);

const newProgressState = options.onSave.progress.mock.calls[0][0];

// remove createQueue from finished
expect(newProgressState.finishedPresets).toEqual([]);
expect(controller.state.progress?.finishedPresets).toEqual([]);

// remove createProject passed steps
expect(newProgressState.presetPassedSteps.createProject).toBeUndefined();
expect(controller.state.progress?.presetPassedSteps.createProject).toBeUndefined();

const newBaseState = options.onSave.state.mock.calls[0][0];
// remove createProject from active and suggested presets
expect(newBaseState.activePresets).toEqual([]);
expect(newBaseState.suggestedPresets).toEqual([]);
// remove createProject from active presets
expect(controller.state.base.activePresets).toEqual([]);
});

it('removeFromSuggested=true, remove from suggested', async function () {
const options = getOptions({}, {finishedPresets: ['createQueue']});

const controller = new Controller(options);
await controller.resetPresetProgress(['createProject', 'createQueue'], {
removeFromSuggested: true,
});

expect(controller.state.base.suggestedPresets).toEqual([]);
});
});
});
Expand Down

0 comments on commit b76b954

Please sign in to comment.