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 submenu mouseenter work', () => {
fixture.detectChanges();
const mouseenterCallback = jasmine.createSpy('mouseenter callback');
const subs = testComponent.subs.toArray();
const title = submenu.nativeElement.querySelector('.ant-menu-submenu-title');
subs[0].nzSubmenuService.mouseEnterLeave$.subscribe(mouseenterCallback);
dispatchFakeEvent(title, 'mouseenter');
fixture.detectChanges();
expect(mouseenterCallback).toHaveBeenCalledWith(true);
expect(mouseenterCallback).toHaveBeenCalledTimes(1);
});
it('should submenu mouseleave work', () => {
it('should key up and down work with shift key', () => {
testComponent.max = 100;
testComponent.min = -100;
const upArrowEvent = new KeyboardEvent('keydown', {
code: 'ArrowUp',
shiftKey: true
});
const downArrowEvent = new KeyboardEvent('keydown', {
code: 'ArrowDown',
shiftKey: true
});
fixture.detectChanges();
expect(testComponent.value).toBe(undefined);
dispatchEvent(inputElement, upArrowEvent);
dispatchFakeEvent(inputElement, 'keyup');
fixture.detectChanges();
expect(testComponent.value).toBe(10);
dispatchEvent(inputElement, downArrowEvent);
fixture.detectChanges();
expect(testComponent.value).toBe(0);
dispatchEvent(inputElement, downArrowEvent);
fixture.detectChanges();
expect(testComponent.value).toBe(-10);
});
it('should update value immediately after formatter changed', () => {
it('should edit focus', fakeAsync(() => {
const editButton = componentElement.querySelector('.ant-typography-edit');
editButton!.click();
fixture.detectChanges();
flush();
fixture.detectChanges();
const textarea = componentElement.querySelector('textarea')! as HTMLTextAreaElement;
expect(document.activeElement === textarea).toBe(true);
dispatchFakeEvent(textarea, 'blur');
fixture.detectChanges();
}));
it('should focus className correct', fakeAsync(() => {
fixture.detectChanges();
expect(inputNumber.nativeElement.classList).toContain('ng-untouched');
dispatchFakeEvent(inputElement, 'focus');
fixture.detectChanges();
tick();
fixture.detectChanges();
expect(inputNumber.nativeElement.classList).toContain('ng-untouched');
expect(inputNumber.nativeElement.classList).toContain('ant-input-number-focused');
dispatchFakeEvent(inputElement, 'blur');
fixture.detectChanges();
tick();
fixture.detectChanges();
expect(inputNumber.nativeElement.classList).not.toContain('ant-input-number-focused');
expect(inputNumber.nativeElement.classList).toContain('ng-touched');
}));
it('should nzSize work', () => {
it('should submenu mouseleave work', () => {
fixture.detectChanges();
const mouseleaveCallback = jasmine.createSpy('mouseleave callback');
const subs = testComponent.subs.toArray();
const title = submenu.nativeElement.querySelector('.ant-menu-submenu-title');
subs[0].nzSubmenuService.mouseEnterLeave$.subscribe(mouseleaveCallback);
dispatchFakeEvent(title, 'mouseleave');
fixture.detectChanges();
expect(mouseleaveCallback).toHaveBeenCalledWith(false);
expect(mouseleaveCallback).toHaveBeenCalledTimes(1);
});
it('should nested submenu work', () => {
it('should parse correct', fakeAsync(() => {
inputElement.nativeElement.value = '01:01:01';
dispatchFakeEvent(inputElement.nativeElement, 'keyup');
dispatchFakeEvent(inputElement.nativeElement, 'blur');
fixture.detectChanges();
flush();
fixture.detectChanges();
flush();
expect(testComponent.value).toEqual(new Date(1970, 0, 1, 1, 1, 1));
}));
it('should host click trigger', () => {
fixture.detectChanges();
const clickSpy = spyOn(nzSelectService, 'clickOption');
fixture.detectChanges();
expect(clickSpy).toHaveBeenCalledTimes(0);
dispatchFakeEvent(li.nativeElement, 'click');
expect(clickSpy).toHaveBeenCalledTimes(1);
});
});
it('should support switch trigger', fakeAsync(() => {
fixture.componentInstance.inputTrigger = true;
fixture.detectChanges();
const input = fixture.debugElement.query(By.css('input')).nativeElement;
const mention = fixture.componentInstance.mention;
expect(fixture.debugElement.query(By.css('textarea'))).toBeFalsy();
expect(input).toBeTruthy();
input.value = '@a';
fixture.detectChanges();
dispatchFakeEvent(input, 'click');
fixture.detectChanges();
flush();
expect(mention.isOpen).toBe(true);
const option = overlayContainerElement.querySelector('.ant-mention-dropdown-item') as HTMLElement;
option.click();
fixture.detectChanges();
tick(500);
expect(mention.isOpen).toBe(false);
expect(overlayContainerElement.textContent).toEqual('');
}));
});
it('should not complete number work with up arrow', () => {
testComponent.nzInputNumberComponent.onModelChange('1.');
fixture.detectChanges();
dispatchFakeEvent(upHandler, 'mousedown');
fixture.detectChanges();
expect(testComponent.value).toBe(1);
});
it('should not complete number work with down arrow', () => {
it('should not close if mouse down in dialog', fakeAsync(() => {
fixture.componentInstance.isVisible = true;
fixture.detectChanges();
tick(1000);
fixture.detectChanges();
const bodyNativeElement = fixture.debugElement.query(By.css('.ant-modal-body')).nativeElement;
dispatchFakeEvent(bodyNativeElement, 'mousedown');
fixture.detectChanges();
const warpNativeElement = fixture.debugElement.query(By.css('.ant-modal-wrap')).nativeElement;
dispatchFakeEvent(warpNativeElement, 'mouseup');
dispatchFakeEvent(warpNativeElement, 'click');
fixture.detectChanges();
tick(1000);
fixture.detectChanges();
expectModalHidden(fixture.debugElement.query(By.css('nz-modal')).nativeElement, false);
}));
});