Skip to content

Commit

Permalink
Test for keyboard events on slider
Browse files Browse the repository at this point in the history
  • Loading branch information
robGardiner01 committed May 29, 2024
1 parent 46ef090 commit 32ea7d8
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/app/components/slider/slider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { By } from '@angular/platform-browser';
import { Slider } from './slider';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';

describe('Slider', () => {
fdescribe('Slider', () => {
let slider: Slider;
let fixture: ComponentFixture<Slider>;

Expand Down Expand Up @@ -234,6 +234,31 @@ describe('Slider', () => {
expect(unbindDragListenersSpy).toHaveBeenCalled();
});

it('should change values with keyboard events', () => {
slider.updateValue(0);
fixture.detectChanges();

const incrementValueSpy = spyOn(slider, 'incrementValue').and.callThrough();
const spanEl = fixture.debugElement.query(By.css('.p-slider-handle'));
spanEl.nativeElement.dispatchEvent(new KeyboardEvent('keydown', { code: 'ArrowRight' }));
spanEl.nativeElement.dispatchEvent(new KeyboardEvent('keydown', { code: 'ArrowRight' }));
fixture.detectChanges();
expect(incrementValueSpy).toHaveBeenCalled();

const decrementValueSpy = spyOn(slider, 'decrementValue').and.callThrough();
spanEl.nativeElement.dispatchEvent(new KeyboardEvent('keydown', { code: 'ArrowLeft' }));
fixture.detectChanges();
expect(decrementValueSpy).toHaveBeenCalled();

const onDragEndSpy = spyOn(slider, 'onDragEnd').and.callThrough();
const onSlideEndEmitterSpy = spyOn(slider.onSlideEnd, 'emit').and.callThrough();
spanEl.nativeElement.dispatchEvent(new KeyboardEvent('keydown', { code: 'Tab' }));
fixture.detectChanges();
expect(onDragEndSpy).toHaveBeenCalled();
expect(onSlideEndEmitterSpy).toHaveBeenCalled();
expect(slider.value).toEqual(1);
});

it('should increment value with step', () => {
slider.value = 0;
slider.step = 2;
Expand Down

0 comments on commit 32ea7d8

Please sign in to comment.