Skip to content

Commit

Permalink
updates tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckheit committed Nov 11, 2019
1 parent 897ede0 commit 2b8e67b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
3 changes: 0 additions & 3 deletions packages/mdc-linear-progress/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ export const cssClasses = {
};

export const strings = {
ARIA_LABEL: 'aria-label',
ARIA_VALUEMAX: 'aria-valuemax',
ARIA_VALUEMIN: 'aria-valuemin',
ARIA_VALUENOW: 'aria-valuenow',
BUFFER_SELECTOR: '.mdc-linear-progress__buffer',
PRIMARY_BAR_SELECTOR: '.mdc-linear-progress__primary-bar',
Expand Down
6 changes: 3 additions & 3 deletions packages/mdc-linear-progress/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class MDCLinearProgressFoundation extends MDCFoundation<MDCLinearProgress

if (this.isDeterminate_) {
this.adapter_.removeClass(cssClasses.INDETERMINATE_CLASS);
this.adapter_.setAttribute('aria-valuenow', this.progress_.toString());
this.adapter_.setAttribute(strings.ARIA_VALUENOW, this.progress_.toString());
this.setScale_(this.adapter_.getPrimaryBar(), this.progress_);
this.setScale_(this.adapter_.getBuffer(), this.buffer_);
} else {
Expand All @@ -85,7 +85,7 @@ export class MDCLinearProgressFoundation extends MDCFoundation<MDCLinearProgress
this.adapter_.addClass(cssClasses.REVERSED_CLASS);
}
this.adapter_.addClass(cssClasses.INDETERMINATE_CLASS);
this.adapter_.removeAttribute('aria-valuenow');
this.adapter_.removeAttribute(strings.ARIA_VALUENOW);
this.setScale_(this.adapter_.getPrimaryBar(), 1);
this.setScale_(this.adapter_.getBuffer(), 1);
}
Expand All @@ -95,7 +95,7 @@ export class MDCLinearProgressFoundation extends MDCFoundation<MDCLinearProgress
this.progress_ = value;
if (this.isDeterminate_) {
this.setScale_(this.adapter_.getPrimaryBar(), value);
this.adapter_.setAttribute('aria-valuenow', value.toString());
this.adapter_.setAttribute(strings.ARIA_VALUENOW, value.toString());
}
}

Expand Down
12 changes: 6 additions & 6 deletions test/unit/mdc-linear-progress/foundation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {setupFoundationTest} from '../helpers/setup';
import {verifyDefaultAdapter} from '../helpers/foundation';
import {MDCLinearProgressFoundation} from '../../../packages/mdc-linear-progress/foundation';

const {cssClasses} = MDCLinearProgressFoundation;
const {cssClasses, strings} = MDCLinearProgressFoundation;

suite('MDCLinearProgressFoundation');

Expand All @@ -48,7 +48,7 @@ test('defaultAdapter returns a complete adapter implementation', () => {

const setupTest = () => setupFoundationTest(MDCLinearProgressFoundation);

test('#setDeterminate adds class, resets transforms, and removes aria-valuenow', () => {
test('#setDeterminate false adds class, resets transforms, and removes aria-valuenow', () => {
const {foundation, mockAdapter} = setupTest();
td.when(mockAdapter.hasClass(cssClasses.INDETERMINATE_CLASS)).thenReturn(false);
const primaryBar = {};
Expand All @@ -60,7 +60,7 @@ test('#setDeterminate adds class, resets transforms, and removes aria-valuenow',
td.verify(mockAdapter.addClass(cssClasses.INDETERMINATE_CLASS));
td.verify(mockAdapter.setStyle(primaryBar, 'transform', 'scaleX(1)'));
td.verify(mockAdapter.setStyle(buffer, 'transform', 'scaleX(1)'));
td.verify(mockAdapter.removeAttribute('aria-valuenow'));
td.verify(mockAdapter.removeAttribute(strings.ARIA_VALUENOW));
});

test('#setDeterminate removes class', () => {
Expand Down Expand Up @@ -88,7 +88,7 @@ test('#setDeterminate restores previous progress value after toggled from false
foundation.setDeterminate(false);
foundation.setDeterminate(true);
td.verify(mockAdapter.setStyle(primaryBar, 'transform', 'scaleX(0.123)'), {times: 2});
td.verify(mockAdapter.setAttribute('aria-valuenow', '0.123'), {times: 2});
td.verify(mockAdapter.setAttribute(strings.ARIA_VALUENOW, '0.123'), {times: 2});
});

test('#setDeterminate restores previous buffer value after toggled from false to true', () => {
Expand All @@ -111,7 +111,7 @@ test('#setDeterminate updates progress value set while determinate is false afte
foundation.setProgress(0.123);
foundation.setDeterminate(true);
td.verify(mockAdapter.setStyle(primaryBar, 'transform', 'scaleX(0.123)'));
td.verify(mockAdapter.setAttribute('aria-valuenow', '0.123'));
td.verify(mockAdapter.setAttribute(strings.ARIA_VALUENOW, '0.123'));
});

test('#setProgress sets transform and aria-valuenow', () => {
Expand All @@ -122,7 +122,7 @@ test('#setProgress sets transform and aria-valuenow', () => {
foundation.init();
foundation.setProgress(0.5);
td.verify(mockAdapter.setStyle(primaryBar, 'transform', 'scaleX(0.5)'));
td.verify(mockAdapter.setAttribute('aria-valuenow', '0.5'));
td.verify(mockAdapter.setAttribute(strings.ARIA_VALUENOW, '0.5'));
});

test('#setProgress on indeterminate does nothing', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/mdc-linear-progress/mdc-linear-progress.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test('set indeterminate', () => {

component.determinate = false;
assert.isOk(root.classList.contains('mdc-linear-progress--indeterminate'));
assert.equal(undefined, root.getAttribute('aria-valuenow'));
assert.equal(undefined, root.getAttribute(MDCLinearProgressFoundation.strings.ARIA_VALUENOW));
});

test('set progress', () => {
Expand All @@ -68,7 +68,7 @@ test('set progress', () => {
component.progress = 0.5;
const primaryBar = root.querySelector(MDCLinearProgressFoundation.strings.PRIMARY_BAR_SELECTOR);
assert.equal('scaleX(0.5)', primaryBar.style.transform);
assert.equal('0.5', root.getAttribute('aria-valuenow'));
assert.equal('0.5', root.getAttribute(MDCLinearProgressFoundation.strings.ARIA_VALUENOW));
});

test('set buffer', () => {
Expand Down

0 comments on commit 2b8e67b

Please sign in to comment.