From 7ef7fc1b2646a0a0646c68b7e3994d6b9157d8ab Mon Sep 17 00:00:00 2001 From: David Edmondson Date: Sun, 5 Sep 2021 00:32:00 -0700 Subject: [PATCH] Remove getId for now --- cypress/support/commands.ts | 83 ------------------------------------- cypress/support/index.js | 2 +- 2 files changed, 1 insertion(+), 84 deletions(-) delete mode 100644 cypress/support/commands.ts diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts deleted file mode 100644 index a6eb441cb..000000000 --- a/cypress/support/commands.ts +++ /dev/null @@ -1,83 +0,0 @@ -import "@testing-library/cypress/add-commands"; - -interface ItemLocator { - name: T; - item: string; - index?: never; -} -interface IndexLocator { - name: T; - index: number; - item?: never; -} -type Locator = string | ItemLocator | IndexLocator; -declare global { - // eslint-disable-next-line @typescript-eslint/no-namespace - namespace Cypress { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - interface Chainable { - /** - * Get an element by data-test attribute. - * @example - * cy.getId("print-button") - */ - getId( - id: Locator | Array>, - options?: Partial, - ): Chainable>; - } - } -} - -// @ts-ignore -Cypress.SelectorPlayground.defaults({ - selectorPriority: ["data-test"], - onElement: (element: JQuery) => { - const test = element.data("test"); - if (!test) { - return ""; - } - - const parents = Array.from(element.parents("[data-test]")) - .reverse() - .map((parent) => { - const id = parent.dataset["test"]; - const itemId = parent.dataset["test-item"]; - if (itemId) { - return `{ name: "${id}", item: "${itemId}" }`; - } - return `"${id}"`; - }) - .join(", "); - - const testItem = element.data("test-item"); - const selector = testItem - ? `{ name: "${test}", item: "${testItem}" }` - : `"${test}"`; - return parents ? `[${parents}, ${selector}]` : `${selector}`; - }, -}); -Cypress.Commands.add( - "getId", - ( - locators: Locator | Array>, - options: Partial = {}, - ) => { - locators = Array.isArray(locators) ? locators : [locators]; - - return cy.get( - locators - .map((locator) => { - if (typeof locator === "string") { - return `[data-test=${locator}]`; - } - if (locator.item !== undefined) { - return `[data-test=${locator.name}][data-test-item=${locator.item}]`; - } - return `[data-test=${locator.name}]:eq(${locator.index})`; - }) - .join(" "), - options, - ); - }, -); diff --git a/cypress/support/index.js b/cypress/support/index.js index 9ab24bc24..ac8e4cc61 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -15,7 +15,7 @@ // Import commands.js using ES2015 syntax: import "./globalHooks"; -import "./commands"; +// import "./commands"; // Alternatively you can use CommonJS syntax: // require('./commands')