mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-22 07:33:48 +01:00
Remove getId for now
This commit is contained in:
parent
6352704608
commit
7ef7fc1b26
@ -1,83 +0,0 @@
|
||||
import "@testing-library/cypress/add-commands";
|
||||
|
||||
interface ItemLocator<T> {
|
||||
name: T;
|
||||
item: string;
|
||||
index?: never;
|
||||
}
|
||||
interface IndexLocator<T> {
|
||||
name: T;
|
||||
index: number;
|
||||
item?: never;
|
||||
}
|
||||
type Locator<T> = string | ItemLocator<T> | IndexLocator<T>;
|
||||
declare global {
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
namespace Cypress {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
interface Chainable<Subject> {
|
||||
/**
|
||||
* Get an element by data-test attribute.
|
||||
* @example
|
||||
* cy.getId("print-button")
|
||||
*/
|
||||
getId<T = string>(
|
||||
id: Locator<T> | Array<Locator<T>>,
|
||||
options?: Partial<Loggable & Timeoutable>,
|
||||
): Chainable<JQuery<HTMLElement>>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @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",
|
||||
<T = string>(
|
||||
locators: Locator<T> | Array<Locator<T>>,
|
||||
options: Partial<Cypress.Loggable & Cypress.Timeoutable> = {},
|
||||
) => {
|
||||
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,
|
||||
);
|
||||
},
|
||||
);
|
@ -15,7 +15,7 @@
|
||||
|
||||
// Import commands.js using ES2015 syntax:
|
||||
import "./globalHooks";
|
||||
import "./commands";
|
||||
// import "./commands";
|
||||
|
||||
// Alternatively you can use CommonJS syntax:
|
||||
// require('./commands')
|
||||
|
Loading…
Reference in New Issue
Block a user