Skip to content

Commit 297c0a7

Browse files
committed
test(aria/spinbutton): add tests for edge cases
1 parent 0df5562 commit 297c0a7

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

src/aria/spinbutton/spinbutton.spec.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,50 @@ describe('SpinButton', () => {
515515
});
516516
});
517517

518+
describe('edge cases', () => {
519+
it('should do nothing on Home when min is undefined', () => {
520+
setupSpinButton({value: 50, max: 100});
521+
home();
522+
expect(spinButtonInstance.value()).toBe(50);
523+
});
524+
525+
it('should do nothing on End when max is undefined', () => {
526+
setupSpinButton({value: 50, min: 0});
527+
end();
528+
expect(spinButtonInstance.value()).toBe(50);
529+
});
530+
531+
it('should wrap correctly with step > 1', () => {
532+
setupSpinButton({value: 10, min: 0, max: 10, step: 3, wrap: true});
533+
up();
534+
expect(spinButtonInstance.value()).toBe(2); // 10 + 3 = 13, wraps to 2
535+
});
536+
537+
it('should clamp PageUp when it would exceed max', () => {
538+
setupSpinButton({value: 95, min: 0, max: 100, pageStep: 10});
539+
pageUp();
540+
expect(spinButtonInstance.value()).toBe(100);
541+
});
542+
543+
it('should clamp PageDown when it would go below min', () => {
544+
setupSpinButton({value: 5, min: 0, max: 100, pageStep: 10});
545+
pageDown();
546+
expect(spinButtonInstance.value()).toBe(0);
547+
});
548+
549+
it('should wrap PageUp when wrap is enabled', () => {
550+
setupSpinButton({value: 95, min: 0, max: 100, pageStep: 10, wrap: true});
551+
pageUp();
552+
expect(spinButtonInstance.value()).toBe(4); // 95 + 10 = 105, wraps to 4
553+
});
554+
555+
it('should wrap PageDown when wrap is enabled', () => {
556+
setupSpinButton({value: 5, min: 0, max: 100, pageStep: 10, wrap: true});
557+
pageDown();
558+
expect(spinButtonInstance.value()).toBe(96); // 5 - 10 = -5, wraps to 96
559+
});
560+
});
561+
518562
describe('RTL support', () => {
519563
beforeEach(() => {
520564
TestBed.configureTestingModule({

0 commit comments

Comments
 (0)