UNPKG

@wix/design-system

Version:

@wix/design-system

48 lines 2.36 kB
import { baseUniDriverFactory } from '../utils/test-utils/unidriver'; import { textUniDriverFactory } from '../Text/Text.uni.driver'; import { dataHooks } from './constants'; export const thumbnailDriverFactory = (base) => { const byHook = (hook) => base.$(`[data-hook*="${hook}"]`); const getThumbnailWrapper = () => byHook(dataHooks.thumbnailWrapper); const getStyle = async (element, rule) => { const style = await element.attr('style'); const match = style?.match(new RegExp(`${rule}: (.*?);`)); return match ? match[1] : ''; }; const getTitle = async () => { if (await byHook(dataHooks.thumbnailTitle).exists()) { return textUniDriverFactory(byHook(dataHooks.thumbnailTitle)); } if (await byHook(dataHooks.thumbnailBottomTitle).exists()) { return textUniDriverFactory(byHook(dataHooks.thumbnailBottomTitle)); } return null; }; return { ...baseUniDriverFactory(base), /** Gets thumbnail title */ getTitle: async () => { const title = await getTitle(); return title ? title.getText() : ''; }, /** Gets thumbnail description */ getDescription: () => byHook(dataHooks.thumbnailDescription).text(), /** Gets selected icon driver */ getSelectedIcon: () => byHook(dataHooks.thumbnailSelectedIcon), /** Gets background image driver */ getBackgroundImage: () => byHook(dataHooks.thumbnailBackgroundImage), /** Checks whether Thumbnail is selected */ isSelected: async () => (await getThumbnailWrapper().attr('data-selected')) === 'true', /** Checks whether Thumbnail is disabled */ isDisabled: async () => (await getThumbnailWrapper().attr('data-disabled')) === 'true', /** Gets thumbnail image driver */ getImage: () => byHook(dataHooks.thumbnailImage), /** Gets thumbnail width, if it's set through `width` prop */ getWidth: async () => await getStyle(base, 'width'), /** Gets thumbnail height, if it's set through `height` prop */ getHeight: async () => await getStyle(await getThumbnailWrapper(), 'height'), /** Gets aria-label attribute */ getAriaLabel: () => base.attr('aria-label'), }; }; //# sourceMappingURL=Thumbnail.uni.driver.js.map