@wix/design-system
Version:
@wix/design-system
83 lines • 3.42 kB
JavaScript
import { baseUniDriverFactory, findByHook, } from '../utils/test-utils/unidriver';
import { inputWithOptionsUniDriverFactory } from '../InputWithOptions/InputWithOptions.uni.driver';
import { loaderUniDriverFactory } from '../Loader/Loader.uni.driver';
import { statusIndicatorDriverFactory } from '../StatusIndicator/StatusIndicator.uni.driver';
import { addressInputItemDriverFactory } from '../AddressInputItem/AddressInputItem.uni.driver';
import { dataHooks } from './AddressInput.constants';
import { dataHooks as inputDataHooks } from '../Input/Input.constants';
export const addressInputDriverFactory = (base, body) => {
const { driver, inputDriver, dropdownLayoutDriver } = inputWithOptionsUniDriverFactory(base, body);
const getItemDriverAt = async (index) => {
const optionDrivers = await dropdownLayoutDriver.options();
const item = await optionDrivers[index].element();
return addressInputItemDriverFactory(item);
};
const loaderTestkit = () => loaderUniDriverFactory(findByHook(base, dataHooks.loader), body);
const statusIndicatorTestkit = () => statusIndicatorDriverFactory(findByHook(base, inputDataHooks.status), body);
const isDropdownLoaderShown = () => loaderTestkit().exists();
const isLoadingIndicatorShown = async () => {
try {
const status = await statusIndicatorTestkit().getStatus();
return status === 'loading';
}
catch {
// Couldn't find StatusIndicator
return false;
}
};
return {
...baseUniDriverFactory(base),
/**
* Returns value of the input
*/
getInputValue: () => inputDriver.getValue(),
/**
* Enters given text to input
*/
enterText: text => inputDriver.enterText(text),
/**
* Clicks on the clear button to clear input text
*/
clickClear: () => inputDriver.clickClear(),
/**
* Checks if input is disabled
*/
isDisabled: () => driver.isDisabled(),
/**
* Clicks an option at given index
*/
clickAtOption: index => dropdownLayoutDriver.clickAtOption(index),
/**
* Clicks an option with a given value
*/
clickAtOptionWithValue: value => dropdownLayoutDriver.clickAtOptionWithValue(value),
/** Whether loader is shown
*/
isLoading: async () => (await isLoadingIndicatorShown()) || (await isDropdownLoaderShown()),
/**
* Clicks on input
*/
clickInput: () => inputDriver.click(),
/**
* Gets amount of dropdown items
*/
getAmountOfItems: () => dropdownLayoutDriver.optionsLength(),
/**
* Gets item main label text at given index
*/
getItemMainLabelAt: async (index) => (await getItemDriverAt(index)).getMainLabelText(),
/**
* Gets item secondary label text at given index
*/
getItemSecondaryLabelAt: async (index) => (await getItemDriverAt(index)).getSecondaryLabelText(),
/**
* Press enter on address input
*/
pressEnter: () => driver.pressKey('Enter'),
/**
* Checks whether the address input is focused
*/
isFocused: () => inputDriver.isFocus(),
};
};
//# sourceMappingURL=AddressInput.uni.driver.js.map