UNPKG

wc-e2e-page-objects

Version:

WooCommerce Page Objects to be used on end-to-end tests with Selenium WebDriver

288 lines (232 loc) 10.9 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _seleniumWebdriver = require('selenium-webdriver'); var _wpE2eWebdriver = require('wp-e2e-webdriver'); var _wpAdminWcSettings = require('./wp-admin-wc-settings'); var _wpAdminWcSettings2 = _interopRequireDefault(_wpAdminWcSettings); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** * @module WPAdminWCSettingsTaxRates */ /** * External dependencies */ /** * Internal Dependencies */ var INSERT_ROW_SELECTOR = _seleniumWebdriver.By.css('.button.insert'); var REMOVE_SELECTED_ROWS_SELECTOR = _seleniumWebdriver.By.css('.button.remove_tax_rates'); var defaultArgs = { url: '', visit: true }; /** * A Tax: Standard/other rates settings screen. * * @extends WPAdminWCSettings */ var WPAdminWCSettingsTaxRates = function (_WPAdminWCSettings) { _inherits(WPAdminWCSettingsTaxRates, _WPAdminWCSettings); /** * @param {WebDriver} driver - Instance of WebDriver. * @param {object} args - Configuration arguments. */ function WPAdminWCSettingsTaxRates(driver) { var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; _classCallCheck(this, WPAdminWCSettingsTaxRates); args = Object.assign(defaultArgs, args); return _possibleConstructorReturn(this, (WPAdminWCSettingsTaxRates.__proto__ || Object.getPrototypeOf(WPAdminWCSettingsTaxRates)).call(this, driver, args)); } /** * Set the Country Code field. * * @param {int} row - Row number to set field for. * @param {string} value - Country code. * @return {Promise} Promise that evaluates to `true` if set successfully, `false` otherwise. */ _createClass(WPAdminWCSettingsTaxRates, [{ key: 'setCountryCode', value: function setCountryCode(row, value) { return _wpE2eWebdriver.WebDriverHelper.setWhenSettable(this.driver, this.getSelector(row, '.wc_input_country_iso'), value); } /** * Set the State Code field. * * @param {int} row - Row number to set field for. * @param {string} value - State code. * @return {Promise} Promise that evaluates to `true` if set successfully, `false` otherwise. */ }, { key: 'setStateCode', value: function setStateCode(row, value) { return _wpE2eWebdriver.WebDriverHelper.setWhenSettable(this.driver, this.getSelector(row, '.state input'), value); } /** * Set the Postcode/Zip field. * * @param {int} row - Row number to set field for. * @param {string} value - Zip or postal code. * @return {Promise} Promise that evaluates to `true` if set successfully, `false` otherwise. */ }, { key: 'setZipCode', value: function setZipCode(row, value) { return _wpE2eWebdriver.WebDriverHelper.setWhenSettable(this.driver, this.getSelector(row, '.postcode input'), value); } /** * Set the City field. * * @param {int} row - Row number to set field for. * @param {string} value - City. * @return {Promise} Promise that evaluates to `true` if set successfully, `false` otherwise. */ }, { key: 'setCity', value: function setCity(row, value) { return _wpE2eWebdriver.WebDriverHelper.setWhenSettable(this.driver, this.getSelector(row, '.city input'), value); } /** * Set the Rate % field. * * @param {int} row - Row number to set field for. * @param {string} value - Rate %. * @return {Promise} Promise that evaluates to `true` if set successfully, `false` otherwise. */ }, { key: 'setRate', value: function setRate(row, value) { return _wpE2eWebdriver.WebDriverHelper.setWhenSettable(this.driver, this.getSelector(row, '.rate input'), value); } /** * Set the Tax Name field. * * @param {int} row - Row number to set field for. * @param {string} value - Tax name. * @return {Promise} Promise that evaluates to `true` if set successfully, `false` otherwise. */ }, { key: 'setTaxName', value: function setTaxName(row, value) { return _wpE2eWebdriver.WebDriverHelper.setWhenSettable(this.driver, this.getSelector(row, '.name input'), value); } /** * Set the Priority field. * * @param {int} row - Row number to set field for. * @param {string} value - Priority. * @return {Promise} Promise that evaluates to `true` if set successfully, `false` otherwise. */ }, { key: 'setPriority', value: function setPriority(row, value) { return _wpE2eWebdriver.WebDriverHelper.setWhenSettable(this.driver, this.getSelector(row, '.priority input'), value); } /** * Check the "Compound" checkbox. * * @param {int} row - Row number of checkbox. * @return {Promise} Promise that evaluates to `true` if box is/gets checked successfully, `false` otherwise. */ }, { key: 'checkCompound', value: function checkCompound(row) { var selector = this.getSelector(row, '.compound input'); _wpE2eWebdriver.WebDriverHelper.unsetCheckbox(this.driver, selector); return _wpE2eWebdriver.WebDriverHelper.setCheckbox(this.driver, selector); } /** * Uncheck the "Compound" checkbox. * * @param {int} row - Row number of checkbox. * @return {Promise} Promise that evaluates to `true` if box is/gets unchecked successfully, `false` otherwise. */ }, { key: 'uncheckCompound', value: function uncheckCompound(row) { var selector = this.getSelector(row, '.compound input'); _wpE2eWebdriver.WebDriverHelper.setCheckbox(this.driver, selector); return _wpE2eWebdriver.WebDriverHelper.unsetCheckbox(this.driver, selector); } /** * Check the "Shipping" checkbox. * * @param {int} row - Row number of checkbox. * @return {Promise} Promise that evaluates to `true` if box is/gets checked successfully, `false` otherwise. */ }, { key: 'checkShipping', value: function checkShipping(row) { var selector = this.getSelector(row, '.apply_to_shipping input'); _wpE2eWebdriver.WebDriverHelper.unsetCheckbox(this.driver, selector); return _wpE2eWebdriver.WebDriverHelper.setCheckbox(this.driver, selector); } /** * Uncheck the "Compound" checkbox. * * @param {int} row - Row number of checkbox. * @return {Promise} Promise that evaluates to `true` if box is/gets unchecked successfully, `false` otherwise. */ }, { key: 'uncheckShipping', value: function uncheckShipping(row) { var selector = this.getSelector(row, '.apply_to_shipping input'); _wpE2eWebdriver.WebDriverHelper.setCheckbox(this.driver, selector); return _wpE2eWebdriver.WebDriverHelper.unsetCheckbox(this.driver, selector); } /** * Click the "Insert Row" button. * * @return {Promise} Promise that evaluates to `true` if button gets clicked successfully, `false` otherwise. */ }, { key: 'insertRow', value: function insertRow() { return _wpE2eWebdriver.WebDriverHelper.clickWhenClickable(this.driver, INSERT_ROW_SELECTOR); } /** * Click the "Remove Selected Row(s)" button. * * @return {Promise} Promise that evaluates to `true` if button gets clicked successfully, `false` otherwise. */ }, { key: 'removeSelectedRows', value: function removeSelectedRows() { return _wpE2eWebdriver.WebDriverHelper.clickWhenClickable(this.driver, REMOVE_SELECTED_ROWS_SELECTOR); } /** * Remove a row. * * @param {int} row - Row number to remove. * @return {Promise} Promise that evaluates to `true` if row removed successfully using UI, `false` otherwise. */ }, { key: 'removeRow', value: function removeRow(row) { var _this2 = this; return _wpE2eWebdriver.WebDriverHelper.clickWhenClickable(this.driver, this.getSelector(row, '.wc_input_country_iso')).then(function () { return _this2.removeSelectedRows(); }); } /** * Get the selector for an element in the tax rate form. * * @param {int} row - Row number element is in. * @param {string} childEl - An optional CSS selector to look for inside the row. Default: '' * @return {object} selector */ }, { key: 'getSelector', value: function getSelector(row) { var childEl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; return _seleniumWebdriver.By.css('#rates tr:nth-child(' + row + ') ' + childEl); } }]); return WPAdminWCSettingsTaxRates; }(_wpAdminWcSettings2.default); exports.default = WPAdminWCSettingsTaxRates; module.exports = exports['default'];