diff --git a/src/controller.ts b/src/controller.ts index b66e6ef..0aa1ce0 100644 --- a/src/controller.ts +++ b/src/controller.ts @@ -436,6 +436,31 @@ export class Controller { const preset = this.options.config.presets[presetSlug]; @@ -606,31 +631,6 @@ export class Controller { - this.state = {...this.state}; + this.state = JSON.parse(JSON.stringify(this.state)); for (const listener of this.stateListeners) { listener(); diff --git a/src/tests/controller.test.ts b/src/tests/controller.test.ts index 155c5a0..09382c1 100644 --- a/src/tests/controller.test.ts +++ b/src/tests/controller.test.ts @@ -165,6 +165,24 @@ describe('store api', function () { expect(Object.is(snapshot1, snapshot2)).toBe(false); }); + it('change state -> deep field updates', async function () { + const options = getOptions(); + + const controller = new Controller(options); + + const snapshot1 = controller.getSnapshot(); + await controller.addPreset('createQueue'); + const snapshot2 = controller.getSnapshot(); + + expect(Object.is(snapshot1.base.activePresets, snapshot2.base.activePresets)).toBe(false); + expect(Object.is(snapshot1.base.availablePresets, snapshot2.base.availablePresets)).toBe( + false, + ); + expect(Object.is(snapshot1.base.suggestedPresets, snapshot2.base.suggestedPresets)).toBe( + false, + ); + }); + it('change progress -> trigger callback', async function () { const options = getOptions(); @@ -190,6 +208,23 @@ describe('store api', function () { expect(Object.is(snapshot1, snapshot2)).toBe(false); }); + it('change progress -> deep field updates', async function () { + const options = getOptions(); + + const controller = new Controller(options); + + const snapshot1 = controller.getSnapshot(); + await controller.passStep('createSprint'); + const snapshot2 = controller.getSnapshot(); + + expect( + Object.is(snapshot1.progress?.presetPassedSteps, snapshot2.progress?.presetPassedSteps), + ).toBe(false); + expect( + Object.is(snapshot1.progress?.finishedPresets, snapshot2.progress?.finishedPresets), + ).toBe(false); + }); + it('unsubscribe -> no cb', async function () { const options = getOptions();