[Libreoffice-commits] online.git: cypress_test/integration_tests

Tamás Zolnai (via logerrit) logerrit at kemper.freedesktop.org
Fri Apr 17 11:41:48 UTC 2020


 cypress_test/integration_tests/mobile/writer/insert_object_spec.js |   52 +++++-----
 1 file changed, 28 insertions(+), 24 deletions(-)

New commits:
commit 729e8f8679d5a943547aa069a27cadf874c05986
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Fri Apr 17 12:55:12 2020 +0200
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Fri Apr 17 13:41:29 2020 +0200

    cypress: mobile: use a better workflow for using aliases / variables.
    
    Since we are in an asynchronous environment, we can't just use
    variables locally that easy. Cypress has alias feature to
    introduce global variables and access them. Since these are
    global we should init them anytime before use.
    So a stable workflow seems to be this one:
    * Set alias to an initial value (e.g. 0)
    * Wait until it's actually set (e.g. cy.get().should())
    * Set the alias to the value you need in the test
    * Wait until it's actually set
    * Move on with your test and assert on something using this alias
    
    So we need indicators also for this variable to be set, before we
    use it. This will make it work a sequential way, how we need it
    to work.
    
    Change-Id: I047373aa884b1ac7bac419cfb1811534c0e95862
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92417
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>

diff --git a/cypress_test/integration_tests/mobile/writer/insert_object_spec.js b/cypress_test/integration_tests/mobile/writer/insert_object_spec.js
index ac8213030..f45233e9f 100644
--- a/cypress_test/integration_tests/mobile/writer/insert_object_spec.js
+++ b/cypress_test/integration_tests/mobile/writer/insert_object_spec.js
@@ -16,6 +16,28 @@ describe('Insert objects via insertion wizard.', function() {
 		helper.afterAll('insert_object.odt');
 	});
 
+	function initAliasToZero(aliasName) {
+		cy.get('body')
+			.invoke('offset')
+			.its('left')
+			.as(aliasName);
+
+		cy.get('@' + aliasName)
+			.should('be.equal', 0);
+	}
+
+	function getCursorPos(offsetProperty, aliasName) {
+		initAliasToZero(aliasName);
+
+		cy.get('.blinking-cursor')
+			.invoke('offset')
+			.its(offsetProperty)
+			.as(aliasName);
+
+		cy.get('@' + aliasName)
+			.should('be.greaterThan', 0);
+	}
+
 	it('Insert local image.', function() {
 		mobileHelper.openInsertionWizard();
 
@@ -124,10 +146,7 @@ describe('Insert objects via insertion wizard.', function() {
 		// Get the blinking cursor pos
 		cy.get('#document-container').type('xxxx');
 
-		cy.get('.blinking-cursor')
-			.invoke('offset')
-			.its('left')
-			.as('cursorOrigLeft');
+		getCursorPos('left', 'cursorOrigLeft');
 
 		mobileHelper.openInsertionWizard();
 
@@ -159,10 +178,7 @@ describe('Insert objects via insertion wizard.', function() {
 		cy.get('#document-container')
 			.type('xxxx');
 
-		cy.get('.blinking-cursor')
-			.invoke('offset')
-			.its('top')
-			.as('cursorOrigTop');
+		getCursorPos('top', 'cursorOrigTop');
 
 		mobileHelper.openInsertionWizard();
 
@@ -195,10 +211,7 @@ describe('Insert objects via insertion wizard.', function() {
 		cy.get('#document-container')
 			.type('xxxx');
 
-		cy.get('.blinking-cursor')
-			.invoke('offset')
-			.its('top')
-			.as('cursorOrigTop');
+		getCursorPos('top', 'cursorOrigTop');
 
 		mobileHelper.openInsertionWizard();
 
@@ -221,10 +234,7 @@ describe('Insert objects via insertion wizard.', function() {
 		cy.get('#document-container')
 			.type('xxxx');
 
-		cy.get('.blinking-cursor')
-			.invoke('offset')
-			.its('top')
-			.as('cursorOrigTop');
+		getCursorPos('top', 'cursorOrigTop');
 
 		mobileHelper.openInsertionWizard();
 
@@ -247,10 +257,7 @@ describe('Insert objects via insertion wizard.', function() {
 		cy.get('#document-container')
 			.type('xxxx');
 
-		cy.get('.blinking-cursor')
-			.invoke('offset')
-			.its('top')
-			.as('cursorOrigTop');
+		getCursorPos('top', 'cursorOrigTop');
 
 		mobileHelper.openInsertionWizard();
 
@@ -273,10 +280,7 @@ describe('Insert objects via insertion wizard.', function() {
 		cy.get('#document-container')
 			.type('xxxx');
 
-		cy.get('.blinking-cursor')
-			.invoke('offset')
-			.its('top')
-			.as('cursorOrigTop');
+		getCursorPos('top', 'cursorOrigTop');
 
 		mobileHelper.openInsertionWizard();
 


More information about the Libreoffice-commits mailing list