Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should detect focus via touch', fakeAsync(() => {
// Simulate focus via touch.
dispatchFakeEvent(buttonElement, 'touchstart');
buttonElement.focus();
fixture.detectChanges();
tick(TOUCH_BUFFER_MS);
expect(buttonElement.classList.length)
.toBe(2, 'button should have exactly 2 focus classes');
expect(buttonElement.classList.contains('cdk-focused'))
.toBe(true, 'button should have cdk-focused class');
expect(buttonElement.classList.contains('cdk-touch-focused'))
.toBe(true, 'button should have cdk-touch-focused class');
expect(changeHandler).toHaveBeenCalledWith('touch');
}));
it('should clear the timeouts on click', fakeAsync(() => {
dispatchFakeEvent(nextButton, 'mousedown');
fixture.detectChanges();
dispatchFakeEvent(nextButton, 'click');
fixture.detectChanges();
// No need to assert. If fakeAsync doesn't throw, it means that the timers were cleared.
}));
it('should trigger output event on primary value bar animation end', () => {
fixture.detectChanges();
spyOn(progressComponent.animationEnd, 'next');
progressComponent.value = 40;
expect(progressComponent.animationEnd.next).not.toHaveBeenCalled();
// On animation end, output should be emitted.
dispatchFakeEvent(primaryValueBar.nativeElement, 'transitionend');
expect(progressComponent.animationEnd.next).toHaveBeenCalledWith({ value: 40 });
});
});
it('should prevent the default `selectstart` action when an item is being dragged', () => {
registry.startDragging(testComponent.dragItems.first, createMouseEvent('mousedown'));
expect(dispatchFakeEvent(document, 'selectstart').defaultPrevented).toBe(true);
});
it('should show ripples for pagination buttons', () => {
appComponent.addTabsForScrolling();
fixture.detectChanges();
expect(appComponent.tabHeader._showPaginationControls).toBe(true);
const buttonAfter = fixture.debugElement.query(By.css('.mat-tab-header-pagination-after'))!;
expect(fixture.nativeElement.querySelectorAll('.mat-ripple-element').length)
.toBe(0, 'Expected no ripple to show up initially.');
dispatchFakeEvent(buttonAfter.nativeElement, 'mousedown');
dispatchFakeEvent(buttonAfter.nativeElement, 'mouseup');
expect(fixture.nativeElement.querySelectorAll('.mat-ripple-element').length)
.toBe(1, 'Expected one ripple to show up after mousedown');
});
it('should re-align the ink bar when the window is resized', fakeAsync(() => {
fixture = TestBed.createComponent(SimpleTabHeaderApp);
fixture.detectChanges();
const inkBar = fixture.componentInstance.tabHeader._inkBar;
spyOn(inkBar, 'alignToElement');
dispatchFakeEvent(window, 'resize');
tick(150);
fixture.detectChanges();
expect(inkBar.alignToElement).toHaveBeenCalled();
discardPeriodicTasks();
}));
it('should not throw when clicking outside', fakeAsync(() => {
dispatchFakeEvent(fixture.debugElement.query(By.css('input'))!.nativeElement, 'focus');
fixture.detectChanges();
flush();
expect(() => dispatchFakeEvent(document, 'click')).not.toThrow();
}));
});
it('should set aria-invalid if the form field is invalid', fakeAsync(() => {
fixture.componentInstance.control = new FormControl(undefined, [Validators.required]);
fixture.detectChanges();
const input: HTMLInputElement = fixture.nativeElement.querySelector('input');
expect(input.getAttribute('aria-invalid')).toBe('true');
typeInElement(input, '123');
fixture.detectChanges();
dispatchKeyboardEvent(input, 'keydown', ENTER);
fixture.detectChanges();
tick();
dispatchFakeEvent(input, 'blur');
tick();
fixture.detectChanges();
expect(input.getAttribute('aria-invalid')).toBe('false');
}));
});
tick(300);
expect(header.scrollDistance).toBe(0, 'Expected not to scroll after short amount of time.');
tick(1000);
expect(header.scrollDistance).toBeGreaterThan(0, 'Expected to scroll after some time.');
let previousDistance = header.scrollDistance;
tick(100);
expect(header.scrollDistance)
.toBeGreaterThan(previousDistance, 'Expected to scroll again after some more time.');
dispatchFakeEvent(nextButton, endEventName);
}
function assertNextButtonScrolling(startEventName: string, endEventName: string) {
expect(header.scrollDistance).toBe(0, 'Expected to start off not scrolled.');
dispatchFakeEvent(nextButton, startEventName);
fixture.detectChanges();
tick(300);
expect(header.scrollDistance).toBe(0, 'Expected not to scroll after short amount of time.');
tick(1000);
expect(header.scrollDistance).toBeGreaterThan(0, 'Expected to scroll after some time.');
let previousDistance = header.scrollDistance;
tick(100);
expect(header.scrollDistance)
.toBeGreaterThan(previousDistance, 'Expected to scroll again after some more time.');