Skip to content

Commit

Permalink
Merge pull request #8 from Exabyte-io/update/SOF-7203
Browse files Browse the repository at this point in the history
SOF-7203: new browser methods
  • Loading branch information
k0stik authored Apr 17, 2024
2 parents faebe32 + 0c517d9 commit 5b659fe
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
28 changes: 26 additions & 2 deletions src/js/cypress/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,12 @@ export class Browser {
return cy.xpath(path).click();
}

clickOnText(text: string) {
return cy.contains(text).click();
clickOnText(text: string, selector = "body") {
return cy.get(selector).contains(text).click();
}

clickOutside(x = 0, y = 0) {
return cy.get("body").click(x, y);
}

execute<T = unknown>(cb: (win: Cypress.AUTWindow) => T) {
Expand Down Expand Up @@ -214,4 +218,24 @@ export class Browser {
getElementText(selector: string) {
return cy.get(selector).invoke("text");
}

dispatchEvent(selector: string, event: Event) {
return cy.get(selector).then(($el) => {
// setting the value onto element and dispatching input
// event should trigger React's change event
$el[0].dispatchEvent(event);
});
}

check(selector: string) {
cy.get(selector).check();
}

uncheck(selector: string) {
cy.get(selector).uncheck();
}

getAttribute(selector: string, attribute: string) {
return cy.get(selector).invoke("attr", attribute);
}
}
11 changes: 10 additions & 1 deletion src/js/cypress/utils/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const REGEXES: Regex[] = [
{
name: "DATE_REGEX",
regex: /^\$DATE\{(.*)}/,
func: (str, regex) => new Date(matchRegexp(str, regex)),
func: (str, regex) => new Date(matchRegexp(str, regex)).toISOString(),
},
{
name: "BOOLEAN_REGEX",
Expand All @@ -165,6 +165,15 @@ const REGEXES: Regex[] = [
return JSON.parse(matched ? matched[1] : "");
},
},
{
name: "EVAL_REGEX",
regex: /^\$EVAL\{(.*)}/,
func: (str: string, regex) => {
const match = str.match(regex);
// eslint-disable-next-line no-new-func
return Function('"use strict";return (' + (match ? match[1] : null) + ")")();
},
},
{
name: "FLOAT_REGEX",
regex: /^\$FLOAT\{(.*)}/,
Expand Down

0 comments on commit 5b659fe

Please sign in to comment.