How to use the ng-zorro-antd/core.dispatchFakeEvent function in ng-zorro-antd

To help you get started, we’ve selected a few ng-zorro-antd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NG-ZORRO / ng-zorro-antd / components / menu / nz-menu.spec.ts View on Github external
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', () => {
github NG-ZORRO / ng-zorro-antd / components / input-number / nz-input-number.spec.ts View on Github external
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', () => {
github NG-ZORRO / ng-zorro-antd / components / typography / nz-typography.spec.ts View on Github external
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();
    }));
github NG-ZORRO / ng-zorro-antd / components / input-number / nz-input-number.spec.ts View on Github external
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', () => {
github NG-ZORRO / ng-zorro-antd / components / menu / nz-menu.spec.ts View on Github external
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', () => {
github NG-ZORRO / ng-zorro-antd / components / time-picker / nz-time-value-accessor.directive.spec.ts View on Github external
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));
    }));
github NG-ZORRO / ng-zorro-antd / components / select / nz-option-li.spec.ts View on Github external
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);
    });
  });
github NG-ZORRO / ng-zorro-antd / components / mention / nz-mention.spec.ts View on Github external
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('');
    }));
  });
github NG-ZORRO / ng-zorro-antd / components / input-number / nz-input-number.spec.ts View on Github external
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', () => {
github NG-ZORRO / ng-zorro-antd / components / modal / nz-modal.spec.ts View on Github external
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);
    }));
  });