Skip to content

Commit

Permalink
feat: add step pass hook
Browse files Browse the repository at this point in the history
  • Loading branch information
vanilla-wave committed Aug 3, 2023
1 parent 0233ff3 commit beae3e0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,20 @@ describe('pass step', function () {
expect(newProgressState.finishedPresets).toEqual(['createProject']);
expect(options.onSave.progress).toHaveBeenCalledTimes(1);
});

describe('step hooks', function () {
it('pass step -> call onPass hook', async function () {
const options = getOptions();
const mock = jest.fn();

options.config.presets.createProject.steps[1].hooks = {onStepPass: mock};

const controller = new Controller(options);
await controller.passStep('createSprint');

expect(mock).toHaveBeenCalled();
});
});
});

describe('hints', function () {
Expand Down
1 change: 1 addition & 0 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export class Controller<HintParams, Presets extends string, Steps extends string
}

this.options.hooks?.onStepPass?.({preset, step: stepSlug});
step?.hooks?.onStepPass?.();

await this.savePassedStepData(preset, stepSlug, () => {
if (step?.passMode !== 'onShowHint') {
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export type PresetStep<Steps extends string, HintParams> = {
hintParams?: HintParams;
closeOnElementUnmount?: boolean;
passRestriction?: 'afterPrevious';
hooks?: {
onStepPass?: () => void;
};
};

export type Preset<HintParams, Steps extends string> = {
Expand Down

0 comments on commit beae3e0

Please sign in to comment.