From 7f6ae51c45643b35364b76c8643a2996f401839a Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Wed, 3 Apr 2024 18:45:22 +0300 Subject: [PATCH 1/5] update: new browser methods --- src/js/cypress/Browser.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/js/cypress/Browser.ts b/src/js/cypress/Browser.ts index 16a050f..5325503 100644 --- a/src/js/cypress/Browser.ts +++ b/src/js/cypress/Browser.ts @@ -179,8 +179,8 @@ 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(); } execute(cb: (win: Cypress.AUTWindow) => T) { @@ -214,4 +214,12 @@ 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); + }); + } } From 73b583a9570dac8f202dc9b2450a38271653b513 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 5 Apr 2024 17:17:24 +0300 Subject: [PATCH 2/5] update: date logic --- src/js/cypress/utils/table.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/cypress/utils/table.ts b/src/js/cypress/utils/table.ts index e587b0a..1fa74d9 100644 --- a/src/js/cypress/utils/table.ts +++ b/src/js/cypress/utils/table.ts @@ -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", From b75480963ab263e5c086b6aa52c770bbfc2e2547 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 5 Apr 2024 17:18:53 +0300 Subject: [PATCH 3/5] update: add clickOutside method --- src/js/cypress/Browser.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/js/cypress/Browser.ts b/src/js/cypress/Browser.ts index 5325503..d7c9803 100644 --- a/src/js/cypress/Browser.ts +++ b/src/js/cypress/Browser.ts @@ -183,6 +183,10 @@ export class Browser { return cy.get(selector).contains(text).click(); } + clickOutside(x = 0, y = 0) { + return cy.get("body").click(x, y); + } + execute(cb: (win: Cypress.AUTWindow) => T) { return cy.window().then((win) => cb(win)); } From 15c0709fd4b1677e394824f03e48f0d85a490a14 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Fri, 5 Apr 2024 22:26:29 +0300 Subject: [PATCH 4/5] update: add EVAL_REGEX --- src/js/cypress/utils/table.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/js/cypress/utils/table.ts b/src/js/cypress/utils/table.ts index 1fa74d9..a9c29ed 100644 --- a/src/js/cypress/utils/table.ts +++ b/src/js/cypress/utils/table.ts @@ -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\{(.*)}/, From 0c517d9d72ed6bdd31de6c4fdf7877ea1e23adf4 Mon Sep 17 00:00:00 2001 From: Kostiantyn Dvornik Date: Mon, 15 Apr 2024 15:15:13 +0300 Subject: [PATCH 5/5] update: new browser methods --- src/js/cypress/Browser.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/js/cypress/Browser.ts b/src/js/cypress/Browser.ts index d7c9803..19dbda1 100644 --- a/src/js/cypress/Browser.ts +++ b/src/js/cypress/Browser.ts @@ -226,4 +226,16 @@ export class Browser { $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); + } }