Skip to content

Commit 9dc789b

Browse files
committed
test(rating): Added defaultValue tests
1 parent cc0164f commit 9dc789b

File tree

1 file changed

+43
-19
lines changed

1 file changed

+43
-19
lines changed

src/components/rating/rating.spec.ts

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from '../common/controllers/key-bindings.js';
1919
import { defineComponents } from '../common/definitions/defineComponents.js';
2020
import {
21-
FormAssociatedTestBed,
21+
createFormAssociatedTestBed,
2222
simulateClick,
2323
simulateKeyboard,
2424
simulatePointerMove,
@@ -471,56 +471,80 @@ describe('Rating component', () => {
471471
});
472472

473473
describe('Form integration', () => {
474-
const spec = new FormAssociatedTestBed<IgcRatingComponent>(
474+
const spec = createFormAssociatedTestBed<IgcRatingComponent>(
475475
html`<igc-rating name="rating" value="3"></igc-rating>`
476476
);
477477

478478
beforeEach(async () => {
479479
await spec.setup(IgcRatingComponent.tagName);
480480
});
481481

482-
it('is form associated', async () => {
482+
it('is form associated', () => {
483483
expect(spec.element.form).to.equal(spec.form);
484484
});
485485

486-
it('is associated on submit', async () => {
487-
expect(spec.submit()?.get(spec.element.name)).to.equal('3');
486+
it('is associated on submit', () => {
487+
spec.assertSubmitHasValue(spec.element.value.toString());
488488
});
489489

490-
it('is correctly reset on form reset', async () => {
491-
spec.element.value = 4;
492-
await elementUpdated(spec.element);
493-
490+
it('is correctly reset on form reset', () => {
491+
spec.setProperties({ value: 4 });
494492
spec.reset();
493+
495494
expect(spec.element.value).to.equal(3);
496495
});
497496

498497
it('should reset to the new default value after setAttribute() call', () => {
499-
spec.element.setAttribute('value', '5');
500-
spec.element.value = 1;
501-
498+
spec.setAttributes({ value: 5 });
499+
spec.setProperties({ value: 1 });
502500
spec.reset();
503501

504502
expect(spec.element.value).to.equal(5);
505-
expect(spec.submit()?.get(spec.element.name)).to.equal(
506-
spec.element.value.toString()
507-
);
503+
spec.assertSubmitHasValue(spec.element.value.toString());
508504
});
509505

510-
it('reflects disabled ancestor state', async () => {
506+
it('reflects disabled ancestor state', () => {
511507
spec.setAncestorDisabledState(true);
512508
expect(spec.element.disabled).to.be.true;
513509

514510
spec.setAncestorDisabledState(false);
515511
expect(spec.element.disabled).to.be.false;
516512
});
517513

518-
it('fulfils custom constraints', async () => {
514+
it('fulfils custom constraints', () => {
519515
spec.element.setCustomValidity('invalid');
520-
spec.submitFails();
516+
spec.assertSubmitFails();
521517

522518
spec.element.setCustomValidity('');
523-
spec.submitValidates();
519+
spec.assertSubmitPasses();
520+
});
521+
});
522+
523+
describe('defaultValue', () => {
524+
describe('Form integration', () => {
525+
const spec = createFormAssociatedTestBed<IgcRatingComponent>(html`
526+
<igc-rating name="rating" .defaultValue=${3}></igc-rating>
527+
`);
528+
529+
beforeEach(async () => {
530+
await spec.setup(IgcRatingComponent.tagName);
531+
});
532+
533+
it('correct initial state', () => {
534+
spec.assertIsPristine();
535+
expect(spec.element.value).to.equal(3);
536+
});
537+
538+
it('is correctly submitted', () => {
539+
spec.assertSubmitHasValue(spec.element.value.toString());
540+
});
541+
542+
it('is correctly reset', () => {
543+
spec.setProperties({ value: 5 });
544+
spec.reset();
545+
546+
expect(spec.element.value).to.equal(3);
547+
});
524548
});
525549
});
526550
});

0 commit comments

Comments
 (0)