import { UniDriver } from '@wix/wix-ui-test-utils/unidriver'; import { ToolbarCollectionErrorStateUniDriver } from '../ErrorState/ToolbarCollectionErrorState.uni.driver'; import { CollectionEmptyStateUniDriver } from '../EmptyState/CollectionEmptyState.uni.driver'; import { CollectionToolbarUniDriver } from '../CollectionToolbar/CollectionToolbar.uni.driver'; import { AppliedFiltersTagListUniDriver } from '../AppliedFiltersTagList/AppliedFiltersTagList.uni.driver'; import TableUniDriver from '../Table/Table.uni.driver'; import { SummaryBarUniDriver } from '../SummaryBar/SummaryBar.uni.driver'; import { CollectionPremiumEmptyStateUniDriver } from '../EmptyState/CollectionPremiumEmptyState.uni.driver'; import { CollectionNoResultsStateUniDriver } from '../EmptyState/CollectionNoResultsState.uni.driver'; export function TableFoldersUniDriver(base: UniDriver, body: UniDriver) { const toolbarBase = () => base.$('[data-hook="collection-toolbar"]'); const toolbar = () => CollectionToolbarUniDriver(toolbarBase(), body); const table = TableUniDriver(base, body); const loadingStateExists = () => base.$('[data-hook="placeholder-states-loading-state"]').exists(); const getSummaryBar = () => SummaryBarUniDriver(base, body); const getEmptyStateByDataHook = (dataHook = 'collection-empty-state') => CollectionEmptyStateUniDriver(base.$(`[data-hook="${dataHook}"]`), body); const getPremiumEmptyStateByDataHook = (dataHook: string) => CollectionPremiumEmptyStateUniDriver( base.$(`[data-hook="${dataHook}"]`), body, ); const getNoResultsStateByDataHook = (dataHook = 'collection-empty-state') => CollectionNoResultsStateUniDriver( base.$(`[data-hook="${dataHook}"]`), body, ); return { ...table, toolbar: () => toolbar(), getErrorStateByDataHook: (dataHook = 'placeholder-states-error-state') => ToolbarCollectionErrorStateUniDriver( base.$(`[data-hook="${dataHook}"]`), body, ), /** Get collection empty state within the table that by a specific data hook */ getEmptyStateByDataHook, /** Get premium empty state within the table that by a specific data hook */ getPremiumEmptyStateByDataHook, /** Get collection no results state within the table that by a specific data hook */ getNoResultsStateByDataHook, loadingStateExists, folderIconExistsAt: async (row: number, col = 0) => (await table.getRowByIndex(row).$$('td').get(col)) .$('[data-hook="folder-icon"]') .exists(), avatarExistsAt: async (row: number, col: number) => (await table.getRowByIndex(row).$$('td').get(col)) .$('[data-hook="item-avatar"]') .exists(), subToolbar: () => AppliedFiltersTagListUniDriver( base.$('[data-hook="collection-table-sub-toolbar"]'), body, ), /** * Gets collection summary bar */ getSummaryBar, }; } export default TableFoldersUniDriver;