Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 38c40f7

Browse files
authored
fix(slider): Add two test cases to cover give default value to step for discrete slider (#1262)
1 parent 2336128 commit 38c40f7

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

test/unit/mdc-slider/foundation.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ test('#init checks if slider is discrete and if display track markers', () => {
117117
raf.restore();
118118
});
119119

120+
test('#init sets step to one if slider is discrete but step is zero', () => {
121+
const {foundation, mockAdapter} = setupTest();
122+
const raf = createMockRaf();
123+
124+
td.when(mockAdapter.computeBoundingRect()).thenReturn({width: 100, left: 200});
125+
td.when(mockAdapter.hasClass(cssClasses.IS_DISCRETE)).thenReturn(true);
126+
foundation.init();
127+
128+
raf.flush();
129+
130+
assert.equal(foundation.getStep(), 1);
131+
132+
raf.restore();
133+
});
134+
120135
test('#init performs an initial layout of the component', () => {
121136
const {foundation, mockAdapter} = setupTest();
122137
const raf = createMockRaf();

test/unit/mdc-slider/mdc-slider.test.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import td from 'testdouble';
2222
import {createMockRaf} from '../helpers/raf';
2323
import {TRANSFORM_PROP} from './helpers';
2424

25-
import {strings} from '../../../packages/mdc-slider/constants';
25+
import {cssClasses, strings} from '../../../packages/mdc-slider/constants';
2626
import {MDCSlider} from '../../../packages/mdc-slider';
2727

2828
suite('MDCSlider');
@@ -149,14 +149,23 @@ test('#initialSyncWithDOM adds an aria-valuemax attribute if not present', () =>
149149
assert.equal(root.getAttribute('aria-valuemax'), String(component.max));
150150
});
151151

152-
test('#initialSyncWithDOM syncs the value property with aria-valuenow', () => {
152+
test('#initialSyncWithDOM syncs the value property with aria-valuenow for continuous slider', () => {
153153
const root = getFixture();
154154
root.setAttribute('aria-valuenow', '30');
155155

156156
const component = new MDCSlider(root);
157157
assert.equal(component.value, 30);
158158
});
159159

160+
test('#initialSyncWithDOM syncs the value property with aria-valuenow for discrete slider', () => {
161+
const root = getFixture();
162+
root.classList.add(cssClasses.DISCRETE);
163+
root.setAttribute('aria-valuenow', '30');
164+
165+
const component = new MDCSlider(root);
166+
assert.equal(component.value, 30);
167+
});
168+
160169
test('#initialSyncWithDOM adds an aria-valuenow attribute if not present', () => {
161170
const root = getFixture();
162171
root.removeAttribute('aria-valuenow');

0 commit comments

Comments
 (0)