{"version":3,"file":"ng-zorro-antd-core-testing.mjs","names":[],"sources":["../../components/core/testing/directionality.ts","../../components/core/testing/event-objects.ts","../../components/core/testing/dispatch-events.ts","../../components/core/testing/mock-ng-zone.ts","../../components/core/testing/type-in-element.ts","../../components/core/testing/zoneless-helpers.ts"],"sourcesContent":["/**\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE\n */\n\nimport { Directionality } from '@angular/cdk/bidi';\nimport {\n  type Type,\n  DebugElement,\n  EnvironmentProviders,\n  makeEnvironmentProviders,\n  Provider,\n  signal\n} from '@angular/core';\nimport { ComponentFixture, TestBed } from '@angular/core/testing';\nimport { Subject } from 'rxjs';\n\nclass MockDirectionality {\n  value = 'ltr';\n  change = new Subject();\n  valueSignal = signal('ltr');\n}\n\nexport function provideMockDirectionality(): EnvironmentProviders {\n  return makeEnvironmentProviders([{ provide: Directionality, useClass: MockDirectionality }]);\n}\n\ntype Predicate<T> = (value: T) => boolean;\n\n/**\n * Creates a `describe('RTL', ...)` block that verifies the component correctly toggles\n * an RTL CSS class when `Directionality.valueSignal` changes between 'ltr' and 'rtl'.\n *\n * Must be called at the top level of a spec file (outside any `describe` that has its own\n * `beforeEach` configuring TestBed), because it configures its own TestBed internally.\n *\n * @param componentFn Thunk returning the component class. Using a thunk avoids class hoisting\n *   issues — class declarations defined below the call site would be `undefined` at registration time.\n * @param predicate A `By.directive(...)` or `By.css(...)` predicate to locate the element\n *   that carries the RTL class. Use `By.css` when the RTL class is on a child element rather\n *   than the component host.\n * @param classnamePrefix The class prefix (e.g. `'ant-alert'`). The test asserts the presence\n *   of `${classnamePrefix}-rtl`.\n * @param options.detectChangesFn Custom change detection callback for components that need\n *   imperative updates beyond `fixture.detectChanges()` (e.g. calling a private method).\n * @param options.providers Additional providers needed by the component (e.g. `provideNzIconsTesting()`).\n */\nexport function testDirectionality<T>(\n  componentFn: () => Type<T>,\n  predicate: Predicate<DebugElement>,\n  classnamePrefix: string,\n  options?: {\n    detectChangesFn?: (fixture: ComponentFixture<T>) => void;\n    providers?: Array<Provider | EnvironmentProviders>;\n  }\n): void {\n  const rtlClass = `${classnamePrefix}-rtl`;\n  describe('RTL', () => {\n    let fixture: ComponentFixture<T>;\n    let dir: Directionality;\n\n    function detectChanges(): void {\n      if (options?.detectChangesFn) {\n        options.detectChangesFn(fixture);\n      } else {\n        fixture.detectChanges();\n      }\n    }\n\n    beforeEach(() => {\n      TestBed.configureTestingModule({\n        providers: [provideMockDirectionality(), ...(options?.providers || [])]\n      });\n      dir = TestBed.inject(Directionality);\n      fixture = TestBed.createComponent(componentFn());\n    });\n\n    it('should className correct on dir change', async () => {\n      detectChanges();\n      fixture.autoDetectChanges();\n      await fixture.whenStable();\n      const debugElement = fixture.debugElement.query(predicate);\n      expect(debugElement).toBeTruthy();\n      expect(debugElement.nativeElement.classList.contains(rtlClass)).toBe(false);\n\n      dir.valueSignal.set('rtl');\n      detectChanges();\n      await fixture.whenStable();\n      expect(debugElement.nativeElement.classList.contains(rtlClass)).toBe(true);\n\n      dir.valueSignal.set('ltr');\n      detectChanges();\n      await fixture.whenStable();\n      expect(debugElement.nativeElement.classList.contains(rtlClass)).toBe(false);\n    });\n  });\n}\n","/**\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE\n */\n\nimport { NzSafeAny } from 'ng-zorro-antd/core/types';\n\n/** Creates a browser MouseEvent with the specified options. */\nexport function createMouseEvent(type: string, x: number = 0, y: number = 0, button: number = 0): MouseEvent {\n  const event = document.createEvent('MouseEvent');\n\n  event.initMouseEvent(\n    type,\n    true /* canBubble */,\n    false /* cancelable */,\n    window /* view */,\n    0 /* detail */,\n    x /* screenX */,\n    y /* screenY */,\n    x /* clientX */,\n    y /* clientY */,\n    false /* ctrlKey */,\n    false /* altKey */,\n    false /* shiftKey */,\n    false /* metaKey */,\n    button /* button */,\n    null /* relatedTarget */\n  );\n\n  // `initMouseEvent` doesn't allow us to pass the `buttons` and\n  // defaults it to 0 which looks like a fake event.\n  Object.defineProperty(event, 'buttons', { get: () => 1 });\n\n  return event;\n}\n\n/** Creates a browser TouchEvent with the specified pointer coordinates. */\nexport function createTouchEvent(type: string, pageX: number = 0, pageY: number = 0): UIEvent {\n  // In favor of creating events that work for most of the browsers, the event is created\n  // as a basic UI Event. The necessary details for the event will be set manually.\n  const event = new UIEvent(type, { detail: 0, view: window });\n  const touchDetails = { pageX, pageY, clientX: pageX, clientY: pageY };\n\n  // Most of the browsers don't have a \"initTouchEvent\" method that can be used to define\n  // the touch details.\n  Object.defineProperties(event, {\n    touches: { value: [touchDetails] },\n    targetTouches: { value: [touchDetails] },\n    changedTouches: { value: [touchDetails] }\n  });\n\n  return event;\n}\n\n/** Dispatches a keydown event from an element. */\nexport function createKeyboardEvent(\n  type: string,\n  keyCode: number,\n  target?: Element,\n  key?: string,\n  ctrlKey?: boolean,\n  metaKey?: boolean,\n  shiftKey?: boolean\n): KeyboardEvent {\n  const event = document.createEvent('KeyboardEvent') as NzSafeAny;\n\n  // Firefox does not support `initKeyboardEvent`, but supports `initKeyEvent`.\n  if (event.initKeyEvent) {\n    event.initKeyEvent(type, true, true, window, 0, 0, 0, 0, 0, keyCode);\n  } else {\n    event.initKeyboardEvent(type, true, true, window, 0, key, 0, '', false);\n  }\n\n  // Webkit Browsers don't set the keyCode when calling the init function.\n  // See related bug https://bugs.webkit.org/show_bug.cgi?id=16735\n  Object.defineProperties(event, {\n    keyCode: { get: () => keyCode },\n    key: { get: () => key },\n    target: { get: () => target },\n    ctrlKey: { get: () => ctrlKey },\n    metaKey: { get: () => metaKey },\n    shiftKey: { get: () => shiftKey }\n  });\n\n  return event;\n}\n\n/** Creates a fake event object with any desired event type. */\nexport function createFakeEvent(type: string, canBubble: boolean = true, cancelable: boolean = true): Event {\n  const event = document.createEvent('Event');\n  event.initEvent(type, canBubble, cancelable);\n  return event;\n}\n","/**\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE\n */\n\nimport { createFakeEvent, createKeyboardEvent, createMouseEvent, createTouchEvent } from './event-objects';\n\n/** Utility to dispatch any event on a Node. */\nexport function dispatchEvent(node: Node | Window, event: Event): Event {\n  node.dispatchEvent(event);\n  return event;\n}\n\n/** Shorthand to dispatch a fake event on a specified node. */\nexport function dispatchFakeEvent(node: Node | Window, type: string, canBubble?: boolean): Event {\n  return dispatchEvent(node, createFakeEvent(type, canBubble));\n}\n\n/** Shorthand to dispatch a keyboard event with a specified key code. */\nexport function dispatchKeyboardEvent(node: Node, type: string, keyCode: number, target?: Element): KeyboardEvent {\n  return dispatchEvent(node, createKeyboardEvent(type, keyCode, target)) as KeyboardEvent;\n}\n\n/** Shorthand to dispatch a mouse event on the specified coordinates. */\nexport function dispatchMouseEvent(\n  node: Node,\n  type: string,\n  x: number = 0,\n  y: number = 0,\n  event: MouseEvent = createMouseEvent(type, x, y)\n): MouseEvent {\n  return dispatchEvent(node, event) as MouseEvent;\n}\n\n/** Shorthand to dispatch a touch event on the specified coordinates. */\nexport function dispatchTouchEvent(node: Node, type: string, x: number = 0, y: number = 0): TouchEvent {\n  return dispatchEvent(node, createTouchEvent(type, x, y)) as TouchEvent;\n}\n","/**\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE\n */\n\nimport { EventEmitter, Injectable, NgZone } from '@angular/core';\n\nimport { NzSafeAny } from 'ng-zorro-antd/core/types';\n\n/**\n * Mock synchronous NgZone implementation that can be used\n * to flush out `onStable` subscriptions in tests.\n *\n * via: https://github.com/angular/angular/blob/master/packages/core/testing/src/ng_zone_mock.ts\n *\n * @docs-private\n */\n@Injectable()\nexport class MockNgZone extends NgZone {\n  override onStable = new EventEmitter<NzSafeAny>(false);\n\n  constructor() {\n    super({ enableLongStackTrace: false });\n  }\n\n  override run(fn: () => NzSafeAny): NzSafeAny {\n    return fn();\n  }\n\n  override runOutsideAngular(fn: () => NzSafeAny): NzSafeAny {\n    return fn();\n  }\n\n  simulateZoneExit(): void {\n    this.onStable.emit(null);\n  }\n}\n","/**\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE\n */\n\nimport { dispatchFakeEvent } from './dispatch-events';\n\n/**\n * Focuses an input, sets its value and dispatches\n * the `input` event, simulating the user typing.\n *\n * @param value Value to be set on the input.\n * @param element Element onto which to set the value.\n */\nexport function typeInElement(value: string, element: HTMLInputElement | HTMLTextAreaElement): void {\n  element.focus();\n  element.value = value;\n  dispatchFakeEvent(element, 'input');\n}\n","/**\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE\n */\n\nimport type { ComponentFixture } from '@angular/core/testing';\n\nexport function sleep(ms: number): Promise<void> {\n  return new Promise(resolve => setTimeout(resolve, ms));\n}\n\nexport function nextAnimationFrame(): Promise<void> {\n  return sleep(16);\n}\n\nexport async function updateNonSignalsInput<T>(fixture: ComponentFixture<T>, ms?: number): Promise<void> {\n  fixture.changeDetectorRef.markForCheck();\n  if (typeof ms === 'number') {\n    await sleep(ms);\n  }\n  await fixture.whenStable();\n}\n"],"mappings":";;;;;AAiBA,IAAM,qBAAN,MAAwB;CACtB,QAAQ;CACR,SAAS,IAAI,QAAO;CACpB,cAAc,OAAO,OAAM,GAAA,YAAA,CAAA,EAAA,WAAA,cAAA,CAAA,+BAAA,CAAA,CAAA;AAC5B;AAED,SAAgB,4BAAyB;CACvC,OAAO,yBAAyB,CAAC;EAAE,SAAS;EAAgB,UAAU;CAAkB,CAAE,CAAC;AAC7F;AAsBA,SAAgB,mBACd,aACA,WACA,iBACA,SAGC;CAED,MAAM,WAAW,GAAG,gBAAe;CACnC,SAAS,aAAY;EACnB,IAAI;EACJ,IAAI;EAEJ,S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