From 569991a5f65d6f58c2a290479c053622a2ba84ab Mon Sep 17 00:00:00 2001 From: Jason Mitchell Date: Fri, 15 Mar 2019 00:42:36 -0700 Subject: [PATCH] fix: avoid resetting the step manager on any attribute changes --- addon/components/step-manager.ts | 23 ++++++++++++++++------- tests/integration/step-manager-test.js | 25 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/addon/components/step-manager.ts b/addon/components/step-manager.ts index 88256199..a134c23a 100644 --- a/addon/components/step-manager.ts +++ b/addon/components/step-manager.ts @@ -70,6 +70,12 @@ export default class StepManagerComponent extends Component { */ linear!: boolean; + /** + * @property {boolean} boolean + * @private + */ + _watchCurrentStep!: boolean; + /** * @property {BaseStateMachine} transitions state machine for transitions * @private @@ -85,6 +91,7 @@ export default class StepManagerComponent extends Component { 'currentStep' ); + this._watchCurrentStep = isPresent(currentStep); const startingStep = isNone(initialStep) ? currentStep : initialStep; if (!isPresent(this.linear)) { @@ -113,13 +120,15 @@ export default class StepManagerComponent extends Component { } didUpdateAttrs() { - const newStep = this.currentStep; - - if (typeof newStep === 'undefined') { - const firstStep = get(this.transitions, 'firstStep'); - this.transitionTo(firstStep); - } else { - this.transitionTo(newStep); + if (this._watchCurrentStep) { + const newStep = this.currentStep; + + if (typeof newStep === 'undefined') { + const firstStep = get(this.transitions, 'firstStep'); + this.transitionTo(firstStep); + } else { + this.transitionTo(newStep); + } } } diff --git a/tests/integration/step-manager-test.js b/tests/integration/step-manager-test.js index 654447e8..08b04fdd 100644 --- a/tests/integration/step-manager-test.js +++ b/tests/integration/step-manager-test.js @@ -109,6 +109,31 @@ module('step-manager', function(hooks) { assert.equal(this.get('step'), 'first'); }); + + test('does not reset back to first step on any attribute change', async function(assert) { + this.set('initialStep', 'second'); + this.set('randomAttribute', 'initial value'); + + await render(hbs` + {{#step-manager randomAttribute=randomAttribute initialStep=initialStep as |w|}} + {{#w.step name='first'}} +
+ {{/w.step}} + {{#w.step name='second'}} +
+ {{/w.step}} + {{/step-manager}} + `); + + assert.dom('[data-test-second]').exists(); + assert.dom('[data-test-first]').doesNotExist(); + + this.set('initialStep', 'second'); + this.set('randomAttribute', 'a new value'); + + assert.dom('[data-test-second]').exists(); + assert.dom('[data-test-first]').doesNotExist(); + }); }); });