UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

201 lines • 7.78 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } import { InProductTestPageObject } from '@atlaskit/in-product-testing'; import { BlockCardPageObject, EmbedCardPageObject, InlineCardPageObject } from '@atlaskit/smart-card/in-product'; export var EditorSmartLinkPageObject = /*#__PURE__*/function (_InProductTestPageObj) { _inherits(EditorSmartLinkPageObject, _InProductTestPageObj); var _super = _createSuper(EditorSmartLinkPageObject); function EditorSmartLinkPageObject(cy, editor) { var _this; _classCallCheck(this, EditorSmartLinkPageObject); _this = _super.call(this, cy); _defineProperty(_assertThisInitialized(_this), "testIds", { viewSwitcher: 'link-toolbar-appearance-button', displayUrlOption: 'url-appearance', displayInlineOption: 'inline-appearance', displayCardOption: 'block-appearance', displayEmbedOption: 'embed-appearance', linkUrl: 'link-url', linkLabel: 'link-text' }); _defineProperty(_assertThisInitialized(_this), "ariaLabels", { editLink: 'Edit link', deleteLink: 'Remove', unlinkLink: 'Unlink' }); _this.cy = cy; _this.editor = editor; return _this; } _createClass(EditorSmartLinkPageObject, [{ key: "getViewSwitcher", value: function getViewSwitcher() { return this.cy.get(this.toTestId(this.testIds.viewSwitcher)); } }, { key: "openViewSwitcher", value: function openViewSwitcher() { return this.getViewSwitcher().click(); } }, { key: "getViewSwitcherOption", value: function getViewSwitcherOption() { var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'inline'; switch (type) { case 'url': { return this.cy.get(this.toTestId(this.testIds.displayUrlOption)); } case 'inline': { return this.cy.get(this.toTestId(this.testIds.displayInlineOption)); } case 'block': { return this.cy.get(this.toTestId(this.testIds.displayCardOption)); } case 'embed': { return this.cy.get(this.toTestId(this.testIds.displayEmbedOption)); } default: { throw Error("Attempted to switch to `".concat(type, "`: unknown Smart Link view switcher option!")); } } } }, { key: "selectViewSwitcherOption", value: function selectViewSwitcherOption() { var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'inline'; var viewSwitcherOption = this.getViewSwitcherOption(type); return viewSwitcherOption.click(); } }, { key: "insertSmartLinkByTyping", value: function insertSmartLinkByTyping(url) { var _this2 = this; return this.editor.getEditorArea().type("".concat(url, " "), { delay: 0 }).get('p>a').type('{leftArrow}{leftArrow}').get('[aria-label="Floating Toolbar"]').then(function () { _this2.openViewSwitcher(); _this2.selectViewSwitcherOption('inline'); }); } }, { key: "switchAfterInsert", value: function switchAfterInsert() { var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'inline'; // NOTE: inline inserted by default for all Smart Links. var inlineCard = new InlineCardPageObject(this.cy); inlineCard.click(); this.openViewSwitcher(); this.selectViewSwitcherOption(type); } }, { key: "getSmartLink", value: function getSmartLink() { var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'inline'; switch (type) { case 'inline': { return new InlineCardPageObject(this.cy); } case 'block': { return new BlockCardPageObject(this.cy); } case 'embed': { return new EmbedCardPageObject(this.cy); } case 'url': { return new InlineCardPageObject(this.cy); } } } }, { key: "getEditLinkButton", value: function getEditLinkButton() { return this.cy.get(this.toAriaLabel(this.ariaLabels.editLink)); } }, { key: "openEditLinkMenu", value: function openEditLinkMenu() { var button = this.getEditLinkButton(); return button.click(); } }, { key: "changeLinkLabel", value: function changeLinkLabel(title) { var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'inline'; var smartLink = this.getSmartLink(type); smartLink.click(); this.openEditLinkMenu(); this.typeIntoLabelField(title); } }, { key: "changeLinkUrl", value: function changeLinkUrl(url) { var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'inline'; this.getSmartLink(type).click(); this.openEditLinkMenu(); this.typeIntoUrlField(url); } }, { key: "typeIntoLabelField", value: function typeIntoLabelField(title) { var titleField = this.cy.get(this.toTestId(this.testIds.linkLabel)).focus(); titleField.clear(); titleField.type("".concat(title, "{enter}"), { delay: 0 }); } }, { key: "typeIntoUrlField", value: function typeIntoUrlField(url) { var urlField = this.cy.get(this.toTestId(this.testIds.linkUrl)).focus(); urlField.clear(); urlField.type("".concat(url, "{enter}"), { delay: 0 }); } }, { key: "deleteSmartLink", value: function deleteSmartLink() { var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'inline'; this.getSmartLink(type).click(); this.clickDeleteIcon(); } }, { key: "clickDeleteIcon", value: function clickDeleteIcon() { var ariaLabelSelector = this.toAriaLabel(this.ariaLabels.deleteLink); var deleteButtonSelector = "button".concat(ariaLabelSelector); return this.cy.get(deleteButtonSelector).click(); } }, { key: "unlink", value: function unlink() { var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'inline'; this.getSmartLink(type).click(); this.clickUnlinkIcon(); } }, { key: "clickUnlinkIcon", value: function clickUnlinkIcon() { var ariaLabelSelector = this.toAriaLabel(this.ariaLabels.unlinkLink); var unlinkButtonSelector = "button".concat(ariaLabelSelector); return this.cy.get(unlinkButtonSelector).click(); } }]); return EditorSmartLinkPageObject; }(InProductTestPageObject);