Skip to content

Commit

Permalink
fix(linear-progress): Restore buffer after determinate is toggl… (#5156)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericfromgoogle authored and abhiomkar committed Oct 7, 2019
1 parent 37d6458 commit 09b1598
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/mdc-linear-progress/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class MDCLinearProgressFoundation extends MDCFoundation<MDCLinearProgress
private isDeterminate_!: boolean;
private isReversed_!: boolean;
private progress_!: number;
private buffer_!: number;

constructor(adapter?: Partial<MDCLinearProgressAdapter>) {
super({...MDCLinearProgressFoundation.defaultAdapter, ...adapter});
Expand All @@ -58,13 +59,15 @@ export class MDCLinearProgressFoundation extends MDCFoundation<MDCLinearProgress
this.isDeterminate_ = !this.adapter_.hasClass(cssClasses.INDETERMINATE_CLASS);
this.isReversed_ = this.adapter_.hasClass(cssClasses.REVERSED_CLASS);
this.progress_ = 0;
this.buffer_ = 1;
}

setDeterminate(isDeterminate: boolean) {
this.isDeterminate_ = isDeterminate;
if (this.isDeterminate_) {
this.adapter_.removeClass(cssClasses.INDETERMINATE_CLASS);
this.setScale_(this.adapter_.getPrimaryBar(), this.progress_);
this.setScale_(this.adapter_.getBuffer(), this.buffer_);
} else {
this.adapter_.addClass(cssClasses.INDETERMINATE_CLASS);
this.setScale_(this.adapter_.getPrimaryBar(), 1);
Expand All @@ -80,6 +83,7 @@ export class MDCLinearProgressFoundation extends MDCFoundation<MDCLinearProgress
}

setBuffer(value: number) {
this.buffer_ = value;
if (this.isDeterminate_) {
this.setScale_(this.adapter_.getBuffer(), value);
}
Expand Down
11 changes: 11 additions & 0 deletions test/unit/mdc-linear-progress/foundation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ test('#setDeterminate restores previous progress value after toggled from false
td.verify(mockAdapter.setStyle(primaryBar, 'transform', 'scaleX(0.123)'), {times: 2});
});

test('#setDeterminate restores previous buffer value after toggled from false to true', () => {
const {foundation, mockAdapter} = setupTest();
const buffer = {};
td.when(mockAdapter.getBuffer()).thenReturn(buffer);
foundation.init();
foundation.setBuffer(0.123);
foundation.setDeterminate(false);
foundation.setDeterminate(true);
td.verify(mockAdapter.setStyle(buffer, '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 = {};
Expand Down

0 comments on commit 09b1598

Please sign in to comment.