Skip to content

Commit 12c2ce9

Browse files
committed
test(slider): Added defaultValue tests
1 parent a42c952 commit 12c2ce9

File tree

1 file changed

+45
-23
lines changed

1 file changed

+45
-23
lines changed

src/components/slider/slider.spec.ts

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
import { defineComponents } from '../common/definitions/defineComponents.js';
2121
import { asPercent } from '../common/util.js';
2222
import {
23-
FormAssociatedTestBed,
23+
createFormAssociatedTestBed,
2424
simulateKeyboard,
2525
simulateLostPointerCapture,
2626
simulatePointerDown,
@@ -1107,61 +1107,83 @@ describe('Slider component', () => {
11071107
});
11081108

11091109
describe('Form integration', () => {
1110-
const spec = new FormAssociatedTestBed<IgcSliderComponent>(
1110+
const spec = createFormAssociatedTestBed<IgcSliderComponent>(
11111111
html`<igc-slider name="slider" value="3"></igc-slider>`
11121112
);
11131113

11141114
beforeEach(async () => {
11151115
await spec.setup(IgcSliderComponent.tagName);
11161116
});
11171117

1118-
it('is form associated', async () => {
1118+
it('is form associated', () => {
11191119
expect(spec.element.form).to.equal(spec.form);
11201120
});
11211121

1122-
it('is associated on submit', async () => {
1123-
expect(spec.submit()?.get(spec.element.name)).to.equal('3');
1122+
it('is associated on submit', () => {
1123+
spec.assertSubmitHasValue(spec.element.value.toString());
1124+
spec.setProperties({ value: 66 });
11241125

1125-
spec.element.value = 66;
1126-
await elementUpdated(spec.element);
1127-
1128-
expect(spec.submit()?.get(spec.element.name)).to.equal('66');
1126+
spec.assertSubmitHasValue('66');
11291127
});
11301128

1131-
it('is correctly reset on form reset', async () => {
1132-
spec.element.value = 4;
1133-
await elementUpdated(spec.element);
1134-
1129+
it('is correctly reset on form reset', () => {
1130+
spec.setProperties({ value: 4 });
11351131
spec.reset();
1132+
11361133
expect(spec.element.value).to.equal(3);
11371134
});
11381135

11391136
it('should reset to the new default value after setAttribute() call', () => {
1140-
spec.element.setAttribute('value', '17');
1141-
spec.element.value = 50;
1142-
1137+
spec.setAttributes({ value: 17 });
1138+
spec.setProperties({ value: 50 });
11431139
spec.reset();
11441140

11451141
expect(spec.element.value).to.equal(17);
1146-
expect(spec.submit()?.get(spec.element.name)).to.equal(
1147-
spec.element.value.toString()
1148-
);
1142+
spec.assertSubmitHasValue(spec.element.value.toString());
11491143
});
11501144

1151-
it('reflects disabled ancestor state', async () => {
1145+
it('reflects disabled ancestor state', () => {
11521146
spec.setAncestorDisabledState(true);
11531147
expect(spec.element.disabled).to.be.true;
11541148

11551149
spec.setAncestorDisabledState(false);
11561150
expect(spec.element.disabled).to.be.false;
11571151
});
11581152

1159-
it('fulfils custom constraints', async () => {
1153+
it('fulfils custom constraints', () => {
11601154
spec.element.setCustomValidity('invalid');
1161-
spec.submitFails();
1155+
spec.assertSubmitFails();
11621156

11631157
spec.element.setCustomValidity('');
1164-
spec.submitValidates();
1158+
spec.assertSubmitPasses();
1159+
});
1160+
});
1161+
1162+
describe('defaultValue', () => {
1163+
describe('Form integration', () => {
1164+
const spec = createFormAssociatedTestBed<IgcSliderComponent>(
1165+
html`<igc-slider name="slider" .defaultValue=${3}></igc-slider>`
1166+
);
1167+
1168+
beforeEach(async () => {
1169+
await spec.setup(IgcSliderComponent.tagName);
1170+
});
1171+
1172+
it('correct initial state', () => {
1173+
spec.assertIsPristine();
1174+
expect(spec.element.value).to.equal(3);
1175+
});
1176+
1177+
it('is correctly submitted', () => {
1178+
spec.assertSubmitHasValue(spec.element.value.toString());
1179+
});
1180+
1181+
it('is correctly reset', () => {
1182+
spec.setProperties({ value: 55 });
1183+
spec.reset();
1184+
1185+
expect(spec.element.value).to.equal(3);
1186+
});
11651187
});
11661188
});
11671189
});

0 commit comments

Comments
 (0)