Skip to content

Commit

Permalink
fix(linear-progress): restores progress when determinate set to true (#…
Browse files Browse the repository at this point in the history
…1698)

Fixes a bug where the progress was set to 1 after determinate was toggled from false to true, regardless of what progress was set to before.

The progress value is stored in the Foundation instance, defaulting to 0 to follow #1694.

Fixes #1531
  • Loading branch information
patrickrodee authored Dec 12, 2017
1 parent c989b43 commit 1d9cd68
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/mdc-linear-progress/foundation.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ export default class MDCLinearProgressFoundation extends MDCFoundation {
init() {
this.determinate_ = !this.adapter_.hasClass(cssClasses.INDETERMINATE_CLASS);
this.reverse_ = this.adapter_.hasClass(cssClasses.REVERSED_CLASS);
this.progress_ = 0;
}

setDeterminate(isDeterminate) {
this.determinate_ = isDeterminate;
if (this.determinate_) {
this.adapter_.removeClass(cssClasses.INDETERMINATE_CLASS);
this.setScale_(this.adapter_.getPrimaryBar(), this.progress_);
} else {
this.adapter_.addClass(cssClasses.INDETERMINATE_CLASS);
this.setScale_(this.adapter_.getPrimaryBar(), 1);
Expand All @@ -60,6 +62,7 @@ export default class MDCLinearProgressFoundation extends MDCFoundation {
}

setProgress(value) {
this.progress_ = value;
if (this.determinate_) {
this.setScale_(this.adapter_.getPrimaryBar(), value);
}
Expand Down
22 changes: 22 additions & 0 deletions test/unit/mdc-linear-progress/foundation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ test('#setDeterminate removes class', () => {
td.verify(mockAdapter.removeClass(cssClasses.INDETERMINATE_CLASS));
});

test('#setDeterminate restores previous progress value after toggled from false to true', () => {
const {foundation, mockAdapter} = setupTest();
const primaryBar = {};
td.when(mockAdapter.getPrimaryBar()).thenReturn(primaryBar);
foundation.init();
foundation.setProgress(0.123);
foundation.setDeterminate(false);
foundation.setDeterminate(true);
td.verify(mockAdapter.setStyle(primaryBar, 'transform', 'scaleX(0.123)'), {times: 2});
});

test('#setDeterminate updates progress value set while determinate is false after determinate is true', () => {
const {foundation, mockAdapter} = setupTest();
const primaryBar = {};
td.when(mockAdapter.getPrimaryBar()).thenReturn(primaryBar);
foundation.init();
foundation.setDeterminate(false);
foundation.setProgress(0.123);
foundation.setDeterminate(true);
td.verify(mockAdapter.setStyle(primaryBar, 'transform', 'scaleX(0.123)'));
});

test('#setProgress sets transform', () => {
const {foundation, mockAdapter} = setupTest();
td.when(mockAdapter.hasClass(cssClasses.INDETERMINATE_CLASS)).thenReturn(false);
Expand Down

0 comments on commit 1d9cd68

Please sign in to comment.