import { UniDriver } from '@wix/wix-ui-test-utils/unidriver'; import { baseUniDriverFactory } from '../../unidriver'; import { ButtonUniDriver, TextButtonUniDriver, } from '@wix/design-system/dist/testkit/unidriver'; export default (base: UniDriver, body: UniDriver) => { const tryAgainButton = () => TextButtonUniDriver( base.$(`[data-hook="error-card-state-action-button"]`), body, ); const stepCta = (id: string) => ButtonUniDriver(base.$(`[data-hook="setup-step-cta-${id}"]`), body); return { /** Widget title text. */ getTitle: () => base.$(`[data-hook="setup-widget-title"]`).text(), /** "X/Y completed" progress label text. */ getProgressLabel: () => base.$(`[data-hook="setup-widget-progress"]`).text(), /** Titles of all rendered steps, in order. */ getStepTitles: () => base.$$(`[data-hook^="setup-step-title-"]`).map((el) => el.text()), /** Whether a given step row/card is rendered. */ stepExists: (id: string) => base.$(`[data-hook="setup-step-${id}"]`).exists(), /** Click a step's row/card (triggers inline toggle or navigate). */ clickStep: (id: string) => base.$(`[data-hook="setup-step-${id}"]`).click(), /** Click a step's CTA button. */ clickStepCta: (id: string) => stepCta(id).click(), /** Whether a step's CTA is rendered. */ stepCtaExists: (id: string) => base.$(`[data-hook="setup-step-cta-${id}"]`).exists(), /** Whether a disabled step's permission tooltip wraps its CTA. */ disabledTooltipExists: (id: string) => base.$(`[data-hook="setup-step-disabled-tooltip-${id}"]`).exists(), /** Whether a step's inline-expansion content is shown. */ isStepExpanded: (id: string) => base.$(`[data-hook="setup-step-content-${id}"]`).exists(), /** Whether a step row/card is the single focused ("next") step. */ isStepFocused: (id: string) => base .$(`[data-hook="setup-step-${id}"]`) .attr('data-focused') .then((value) => value === 'true'), /** Whether an aggregated group's children are shown. */ isGroupExpanded: (id: string) => base.$(`[data-hook="setup-step-children-${id}"]`).exists(), /** Click an arbitrary element by data-hook within the widget. */ clickByDataHook: (dataHook: string) => base.$(`[data-hook="${dataHook}"]`).click(), /** Whether the all-complete success surface is shown. */ isAllComplete: () => base.$(`[data-hook="setup-all-complete"]`).exists(), /** Whether the loading skeleton is shown. */ isLoading: () => base.$(`[data-hook="setup-widget-skeleton"]`).exists(), /** Whether the error state is shown. */ isError: () => base.$(`[data-hook="error-card-state"]`).exists(), /** Click the error state's "try again" button (refetches). */ clickTryAgain: () => tryAgainButton().click(), ...baseUniDriverFactory(base), }; };