{"version":3,"file":"index.cjs","names":["ComponentDriver","listHelper","HTMLElementDriver","textList: string[]","cellLocator: PartLocator","locatorUtil","locatorUtil","locatorUtil","HTMLElementDriver","ComponentDriver","locatorUtil","listHelper"],"sources":["../src/components/datagrid/DataGridRowDriverBase.ts","../src/components/datagrid/DataGridDataRowDriver.ts","../src/components/datagrid/DataGridHeaderRowDriver.ts","../src/components/datagrid/DataGridProDriver.ts"],"sourcesContent":["import { HTMLElementDriver } from '@atomic-testing/component-driver-html';\nimport { byAttribute, ComponentDriver, ComponentDriverCtor, listHelper, locatorUtil, PartLocator } from '@atomic-testing/core';\n\n// In MUI7, there is an extra div preceding the actual data cells. We need to skip it.\nconst columnStartingIndex = 1;\n\n/**\n * Base class for data grid row\n */\nexport abstract class DataGridRowDriverBase extends ComponentDriver {\n  protected async getCellCount(): Promise<number> {\n    let count = 0;\n    for await (const _ of listHelper.getListItemIterator(\n      this,\n      this.getCellLocator(),\n      HTMLElementDriver,\n      columnStartingIndex\n    )) {\n      count++;\n    }\n    return count;\n  }\n\n  /**\n   * Get the text of each visible cell in the row.\n   * Caveat: Because of virtualization, the text of the cell may not be available until the cell is visible.\n   * @returns A promise array of text of each visible cell in the row\n   */\n  async getRowText(): Promise<string[]> {\n    const textList: string[] = [];\n    for await (const cell of listHelper.getListItemIterator(\n      this,\n      this.getCellLocator(),\n      HTMLElementDriver,\n      columnStartingIndex\n    )) {\n      const text = await cell.getText();\n      textList.push(text!.trim());\n    }\n    return textList;\n  }\n\n  /**\n   * Get the cell driver at the specified index or data field.\n   * Caveat: Because of virtualization, the cell may not be available until the cell is visible.\n   * @param cellIndexOrField number: column index, string: column field\n   * @param driverClass The driver class of the cell. Default is HTMLElementDriver\n   * @returns A promise of the cell driver, or null if the cell is not found\n   */\n  async getCell<DriverT extends ComponentDriver>(\n    cellIndexOrField: number | string, // number: column index, string: column field\n    driverClass: ComponentDriverCtor<DriverT> = HTMLElementDriver as ComponentDriverCtor<DriverT>\n  ): Promise<DriverT | null> {\n    let cellLocator: PartLocator;\n    if (typeof cellIndexOrField === 'number') {\n      cellLocator = byAttribute('data-colindex', cellIndexOrField.toString());\n    } else {\n      cellLocator = byAttribute('data-field', cellIndexOrField);\n    }\n    const locator = locatorUtil.append(this.locator, cellLocator);\n    const cellExists = await this.interactor.exists(locator);\n    if (cellExists) {\n      return new driverClass(locator, this.interactor, this.commutableOption);\n    }\n\n    return null;\n  }\n\n  protected abstract getCellLocator(): PartLocator;\n}\n","import { byRole, IComponentDriverOption, Interactor, locatorUtil, PartLocator } from '@atomic-testing/core';\n\nimport { DataGridRowDriverBase } from './DataGridRowDriverBase';\n\nexport class DataGridDataRowDriver extends DataGridRowDriverBase {\n  private readonly _dataCellLocator: PartLocator;\n  constructor(locator: PartLocator, interactor: Interactor, option?: Partial<IComponentDriverOption>) {\n    super(locator, interactor, {\n      ...option,\n      parts: {},\n    });\n\n    this._dataCellLocator = locatorUtil.append(locator, byRole('cell'));\n  }\n\n  protected override getCellLocator(): PartLocator {\n    return this._dataCellLocator;\n  }\n\n  override get driverName(): string {\n    return 'MuiV6DataGridDataRowDriver';\n  }\n}\n","import { byRole, IComponentDriverOption, Interactor, locatorUtil, PartLocator } from '@atomic-testing/core';\n\nimport { DataGridRowDriverBase } from './DataGridRowDriverBase';\n\nexport class DataGridHeaderRowDriver extends DataGridRowDriverBase {\n  private readonly _headerCellLocator: PartLocator;\n  constructor(locator: PartLocator, interactor: Interactor, option?: Partial<IComponentDriverOption>) {\n    super(locator, interactor, {\n      ...option,\n      parts: {},\n    });\n\n    this._headerCellLocator = locatorUtil.append(locator, byRole('columnheader'));\n  }\n\n  getColumnCount(): Promise<number> {\n    return this.getCellCount();\n  }\n\n  protected override getCellLocator(): PartLocator {\n    return this._headerCellLocator;\n  }\n\n  override get driverName(): string {\n    return 'MuiV6DataGridHeaderRowDriver';\n  }\n}\n","import { HTMLElementDriver } from '@atomic-testing/component-driver-html';\nimport {\n  byCssClass,\n  byCssSelector,\n  byRole,\n  ComponentDriver,\n  ComponentDriverCtor,\n  IComponentDriverOption,\n  Interactor,\n  listHelper,\n  locatorUtil,\n  PartLocator,\n  ScenePart,\n} from '@atomic-testing/core';\n\nimport { DataGridCellQuery } from './DataGridCellQuery';\nimport { DataGridHeaderRowDriver } from './DataGridHeaderRowDriver';\n\nconst parts = {\n  headerRow: {\n    locator: byCssClass('MuiDataGrid-columnHeaders').chain(byCssSelector('[role=row]:first-of-type')),\n    driver: DataGridHeaderRowDriver,\n  },\n  loading: {\n    locator: byRole('progressbar'),\n    driver: HTMLElementDriver,\n  },\n} satisfies ScenePart;\n\nconst dataRowLocator = byCssSelector('[role=row][data-rowindex]');\n\n/**\n * Driver for Material UI v6 DataGridPro component.\n * @see https://mui.com/x/react-data-grid/\n */\nexport class DataGridProDriver extends ComponentDriver<typeof parts> {\n  constructor(locator: PartLocator, interactor: Interactor, option?: Partial<IComponentDriverOption>) {\n    super(locator, interactor, {\n      ...option,\n      parts,\n    });\n  }\n\n  /**\n   * Checks if the data grid is currently loading.\n   * @returns A promise that resolves to a boolean indicating if the data grid is loading.\n   */\n  async isLoading(): Promise<boolean> {\n    const result = await Promise.all([this.parts.loading.isVisible()]);\n    return result.some(v => v);\n  }\n\n  /**\n   * Waits for the data grid to exit the loading state.\n   * @param timeoutMs The maximum time to wait for the load to complete, in milliseconds.\n   */\n  async waitForLoad(timeoutMs: number = 10000): Promise<void> {\n    await this.parts.headerRow.waitUntilComponentState();\n    await this.waitUntil({ probeFn: () => this.isLoading(), terminateCondition: false, timeoutMs });\n  }\n\n  /**\n   * The number of columns currently displayed in the data grid, note that data grid pro\n   * uses virtualize rendering, therefore the column count heavily depends on the viewport size\n   * @returns The number of columns currently displayed in the data grid\n   */\n  async getColumnCount(): Promise<number> {\n    return this.parts.headerRow.getColumnCount();\n  }\n\n  /**\n   * The array text of the header row, note that columns not shown in the viewport may not be included because of virtualize rendering\n   * @returns The array of text of the header row\n   */\n  async getHeaderText(): Promise<string[]> {\n    return this.parts.headerRow.getRowText();\n  }\n\n  /**\n   * The number of rows currently displayed in the data grid, note that data grid pro\n   * uses virtualize rendering, therefore the row count heavily depends on the viewport size\n   * @returns The number of columns currently displayed in the data grid\n   */\n  async getRowCount(): Promise<number> {\n    const gridRowLocator = locatorUtil.append(this.locator, dataRowLocator);\n    let count = 0;\n    for await (const _ of listHelper.getListItemIterator(this, gridRowLocator, HTMLElementDriver)) {\n      count++;\n    }\n    return count;\n  }\n\n  /**\n   * Return the row driver for the row at the specified index, if the row does not exist, return null\n   * @param rowIndex\n   * @returns\n   */\n  async getRow(rowIndex: number): Promise<DataGridHeaderRowDriver | null> {\n    const rowLocator = locatorUtil.append(this.locator, byCssSelector(`[role=row][data-rowindex=\"${rowIndex}\"]`));\n    const rowExists = await this.interactor.exists(rowLocator);\n    if (rowExists) {\n      return new DataGridHeaderRowDriver(rowLocator, this.interactor, this.commutableOption);\n    }\n\n    return null;\n  }\n\n  /**\n   * The array text of the specified row, note that columns not shown in the viewport may not be included because of virtualize rendering\n   * @param rowIndex The index of the row\n   * @returns The array of text of the specified row\n   */\n  async getRowText(rowIndex: number): Promise<string[]> {\n    const row = await this.getRow(rowIndex);\n    if (row != null) {\n      return row.getRowText();\n    }\n    throw new Error(`Row ${rowIndex} does not exist`);\n  }\n\n  /**\n   * Get the cell driver for the cell, if the cell does not exist, return null\n   * The cell driver is default to HTMLElementDriver, you can specify a different driver class\n   * @param query The query to locate the cell\n   * @param driverClass Optional, the driver class to use for the cell, default to HTMLElementDriver\n   * @returns\n   */\n  async getCell<DriverT extends ComponentDriver>(\n    query: DataGridCellQuery,\n    driverClass: ComponentDriverCtor<DriverT> = HTMLElementDriver as ComponentDriverCtor<DriverT>\n  ): Promise<DriverT | null> {\n    await this.waitForLoad();\n    const rowDriver = await this.getRow(query.rowIndex);\n\n    if (rowDriver === null) {\n      return null;\n    }\n\n    if ('columnIndex' in query) {\n      return rowDriver.getCell(query.columnIndex, driverClass);\n    }\n\n    return rowDriver.getCell(query.columnField, driverClass);\n  }\n\n  /**\n   * Get the text content of the cell, if the cell does not exist, throw an error\n   * @param query The query to locate the cell\n   * @returns\n   */\n  async getCellText(query: DataGridCellQuery): Promise<string> {\n    const cell = await this.getCell(query);\n    if (cell != null) {\n      const text = await cell.getText();\n      return text!;\n    }\n\n    const columnIdentifier = 'columnIndex' in query ? query.columnIndex : query.columnField;\n    throw new Error(`Cell at row:${query.rowIndex} column:${columnIdentifier} does not exist`);\n  }\n\n  override get driverName(): string {\n    return 'MuiV6DataGridDriver';\n  }\n}\n"],"mappings":";;;;AAIA,MAAM,sBAAsB;;;;AAK5B,IAAsB,wBAAtB,cAAoDA,qCAAgB;CAClE,MAAgB,eAAgC;EAC9C,IAAI,QAAQ;AACZ,aAAW,MAAM,KAAKC,gCAAW,oBAC/B,MACA,KAAK,gBAAgB,EACrBC,yDACA,oBACD,CACC;AAEF,SAAO;;;;;;;CAQT,MAAM,aAAgC;EACpC,MAAMC,WAAqB,EAAE;AAC7B,aAAW,MAAM,QAAQF,gCAAW,oBAClC,MACA,KAAK,gBAAgB,EACrBC,yDACA,oBACD,EAAE;GACD,MAAM,OAAO,MAAM,KAAK,SAAS;AACjC,YAAS,KAAK,KAAM,MAAM,CAAC;;AAE7B,SAAO;;;;;;;;;CAUT,MAAM,QACJ,kBACA,cAA4CA,yDACnB;EACzB,IAAIE;AACJ,MAAI,OAAO,qBAAqB,SAC9B,qDAA0B,iBAAiB,iBAAiB,UAAU,CAAC;MAEvE,qDAA0B,cAAc,iBAAiB;EAE3D,MAAM,UAAUC,iCAAY,OAAO,KAAK,SAAS,YAAY;AAE7D,MADmB,MAAM,KAAK,WAAW,OAAO,QAAQ,CAEtD,QAAO,IAAI,YAAY,SAAS,KAAK,YAAY,KAAK,iBAAiB;AAGzE,SAAO;;;;;;AC7DX,IAAa,wBAAb,cAA2C,sBAAsB;CAE/D,YAAY,SAAsB,YAAwB,QAA0C;AAClG,QAAM,SAAS,YAAY;GACzB,GAAG;GACH,OAAO,EAAE;GACV,CAAC;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