Repository: adobe/react-spectrum
File: packages/@react-aria/test-utils/src/types.ts (TypeScript)

Code before:
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

export type Orientation = 'horizontal' | 'vertical';
export type Direction = 'ltr' | 'rtl';

// https://github.com/testing-library/dom-testing-library/issues/939#issuecomment-830771708 is an interesting way of allowing users to configure the timers
// curent way is like https://testing-library.com/docs/user-event/options/#advancetimers,
export interface UserOpts {
  /**
   * The interaction type (mouse, touch, keyboard) that the test util user will use when interacting with a component. This can be overridden
   * at the aria pattern tester level if needed.
   * @default mouse
   */
  interactionType?: 'mouse' | 'touch' | 'keyboard',
  // If using fake timers user should provide something like (time) => jest.advanceTimersByTime(time))}
  // A real timer user would pass async () => await new Promise((resolve) => setTimeout(resolve, waitTime))
  // Time is in ms.
  /**
   * A function used by the test utils to advance timers during interactions. Required for certain aria patterns (e.g. table). This can be overridden
   * at the aria pattern tester level if needed.
   */
  advanceTimer?: (time?: number) => void | Promise<unknown> | any
}

export interface BaseTesterOpts extends UserOpts {
  /** @private */
  user?: any,
  /** The base element for the given tester (e.g. the table, menu trigger button, etc). */
  root: HTMLElement
}

export interface ComboBoxTesterOpts extends BaseTesterOpts {
  /**
   * The base element for the combobox. If provided the wrapping element around the target combobox (as is the the case with a ref provided to RSP ComboBox),
   * will automatically search for the combobox element within.
   */
  root: HTMLElement,
  /**
   * The node of the combobox trigger button if any. If not provided, we will try to automatically use any button
   * within the `root` provided or that the `root` serves as the trigger.
   */
  trigger?: HTMLElement
}

export interface GridListTesterOpts extends BaseTesterOpts {}

export interface ListBoxTesterOpts extends BaseTesterOpts {

Review comment (suggestion):
the typing will need to be looked at again for `advanceTimers`, providing `jest.runAllTimers` as is threw some TS issues depending on the configuration. 

Code after:
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

export type Orientation = 'horizontal' | 'vertical';
export type Direction = 'ltr' | 'rtl';

// https://github.com/testing-library/dom-testing-library/issues/939#issuecomment-830771708 is an interesting way of allowing users to configure the timers
// curent way is like https://testing-library.com/docs/user-event/options/#advancetimers,
export interface UserOpts {
  /**
   * The interaction type (mouse, touch, keyboard) that the test util user will use when interacting with a component. This can be overridden
   * at the aria pattern tester level if needed.
   * @default mouse
   */
  interactionType?: 'mouse' | 'touch' | 'keyboard',
  // If using fake timers user should provide something like (time) => jest.advanceTimersByTime(time))}.
  // A real timer user would pass (waitTime) => new Promise((resolve) => setTimeout(resolve, waitTime))
  // Time is in ms.
  /**
   * A function used by the test utils to advance timers during interactions. Required for certain aria patterns (e.g. table). This can be overridden
   * at the aria pattern tester level if needed.
   */
  advanceTimer?: (time: number) => unknown | Promise<unknown>
}

export interface BaseTesterOpts extends UserOpts {
  /** @private */
  user?: any,
  /** The base element for the given tester (e.g. the table, menu trigger button, etc). */
  root: HTMLElement
}

export interface ComboBoxTesterOpts extends BaseTesterOpts {
  /**
   * The base element for the combobox. If provided the wrapping element around the target combobox (as is the the case with a ref provided to RSP ComboBox),
   * will automatically search for the combobox element within.
   */
  root: HTMLElement,
  /**
   * The node of the combobox trigger button if any. If not provided, we will try to automatically use any button
   * within the `root` provided or that the `root` serves as the trigger.
   */
  trigger?: HTMLElement
}

export interface GridListTesterOpts extends BaseTesterOpts {}

export interface ListBoxTesterOpts extends BaseTesterOpts {