21535: test spec tweaks Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa.knox@curii...
[arvados.git] / services / workbench2 / cypress / e2e / banner-tooltip.cy.js
index 295bc380c3d20ed716da34f9240f41fb11bf192b..f8100961aa26f670f5571298451a8a607eea1c29 100644 (file)
@@ -1,3 +1,4 @@
+
 // Copyright (C) The Arvados Authors. All rights reserved.
 //
 // SPDX-License-Identifier: AGPL-3.0
@@ -15,101 +16,97 @@ describe('Banner / tooltip tests', function () {
         cy.getUser('admin', 'Admin', 'User', true, true)
             .as('adminUser').then(function () {
                 adminUser = this.adminUser;
-            }
-            );
+            });
         cy.getUser('collectionuser1', 'Collection', 'User', false, true)
             .as('activeUser').then(function () {
                 activeUser = this.activeUser;
             });
-            cy.on('uncaught:exception', (err, runnable) => {console.error(err)});
+
+        cy.getAll('@adminUser').then(([adminUser]) => {
+            // This collection will not be deleted after each test, we'll
+            // clean it up manually.
+            cy.createCollection(adminUser.token, {
+                name: `BannerTooltipTest${Math.floor(Math.random() * 999999)}`,
+                owner_uuid: adminUser.user.uuid,
+            }, true).as('bannerCollection');
+        });
+
+        cy.getAll('@bannerCollection').then(function ([bannerCollection]) {
+            collectionUUID = bannerCollection.uuid;
+
+            cy.loginAs(adminUser);
+
+            cy.goToPath(`/collections/${bannerCollection.uuid}`);
+
+            cy.get('[data-cy=upload-button]').click();
+
+            cy.fixture('files/banner.html').as('banner');
+            cy.fixture('files/tooltips.txt').as('tooltips');
+
+            cy.getAll('@banner', '@tooltips').then(([banner, tooltips]) => {
+                cy.get('[data-cy=drag-and-drop]').upload(banner, 'banner.html', false);
+                cy.get('[data-cy=drag-and-drop]').upload(tooltips, 'tooltips.json', false);
+            });
+
+            cy.get('[data-cy=form-submit-btn]').click();
+            cy.get('[data-cy=form-submit-btn]').should('not.exist');
+            cy.get('[data-cy=collection-files-right-panel]')
+                .should('contain', 'banner.html');
+            cy.get('[data-cy=collection-files-right-panel]')
+                .should('contain', 'tooltips.json');
+        });
     });
 
     beforeEach(function () {
-        cy.clearCookies();
-        cy.clearLocalStorage();
+        cy.on('uncaught:exception', (err, runnable, promise) => {
+            Cypress.log({ message: `Application Error: ${err}`});
+            if (promise) {
+                return false;
+            }
+        });
+        cy.intercept({ method: 'GET', url: '**/arvados/v1/config?nocache=*' }, (req) => {
+            req.on('response', (res) => {
+                res.body.Workbench.BannerUUID = collectionUUID;
+            });
+        });
     });
 
-    it('should re-show the banner', () => {
-        setupTheEnvironment();
+    after(function () {
+        // Delete banner collection after all test used it.
+        cy.deleteResource(adminUser.token, "collections", collectionUUID);
+    });
 
+    it('should re-show the banner', () => {
         cy.loginAs(adminUser);
-
-        cy.wait(2000);
+        cy.waitForDom();
 
         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
+        cy.waitForDom();
+        cy.get('[data-cy=confirmation-dialog]').should('not.exist');
 
         cy.get('[title=Notifications]').click();
         cy.get('li').contains('Restore Banner').click();
 
-        cy.wait(2000);
-
         cy.get('[data-cy=confirmation-dialog-ok-btn]').should('be.visible');
     });
 
 
     it('should show tooltips and remove tooltips as localStorage key is present', () => {
-        setupTheEnvironment();
-
         cy.loginAs(adminUser);
 
-        cy.wait(2000);
-
-        cy.get('[data-cy=side-panel-tree]').then(($el) => {
-            const el = $el.get(0) //native DOM element
-            expect(el._tippy).to.exist;
-        });
-
-        cy.wait(2000);
-
         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
 
+        cy.contains('This allows you to navigate through the app').should('not.exist'); // This content comes from tooltips.txt
+        cy.get('[data-cy=side-panel-tree]').trigger('mouseover');
+        cy.get('[data-cy=side-panel-tree]').trigger('mouseenter');
+        cy.contains('This allows you to navigate through the app').should('be.visible');
+
         cy.get('[title=Notifications]').click();
         cy.get('li').contains('Disable tooltips').click();
 
-        cy.get('[data-cy=side-panel-tree]').then(($el) => {
-            const el = $el.get(0) //native DOM element
-            expect(el._tippy).to.be.undefined;
-        });
+        cy.contains('This allows you to navigate through the app').should('not.exist');
+        cy.get('[data-cy=side-panel-tree]').trigger('mouseover');
+        cy.get('[data-cy=side-panel-tree]').trigger('mouseenter');
+        cy.contains('This allows you to navigate through the app').should('not.exist');
     });
-
-    const setupTheEnvironment = () => {
-            cy.createCollection(adminUser.token, {
-                name: `BannerTooltipTest${Math.floor(Math.random() * 999999)}`,
-                owner_uuid: adminUser.user.uuid,
-            }).as('bannerCollection');
-
-            cy.getAll('@bannerCollection')
-                .then(function ([bannerCollection]) {
-
-                    collectionUUID=bannerCollection.uuid;
-
-                    cy.loginAs(adminUser);
-
-                    cy.goToPath(`/collections/${bannerCollection.uuid}`);
-
-                    cy.get('[data-cy=upload-button]').click();
-
-                    cy.fixture('files/banner.html').as('banner');
-                    cy.fixture('files/tooltips.txt').as('tooltips');
-
-                    cy.getAll('@banner', '@tooltips')
-                        .then(([banner, tooltips]) => {
-                            cy.get('[data-cy=drag-and-drop]').upload(banner, 'banner.html', false);
-                            cy.get('[data-cy=drag-and-drop]').upload(tooltips, 'tooltips.json', false);
-                        });
-
-                    cy.get('[data-cy=form-submit-btn]').click();
-                    cy.get('[data-cy=form-submit-btn]').should('not.exist');
-                    cy.get('[data-cy=collection-files-right-panel]')
-                        .contains('banner.html').should('exist');
-                    cy.get('[data-cy=collection-files-right-panel]')
-                        .contains('tooltips.json').should('exist');
-
-                        cy.intercept({ method: 'GET', url: '**/arvados/v1/config?nocache=*' }, (req) => {
-                            req.reply((res) => {
-                                res.body.Workbench.BannerUUID = collectionUUID;
-                            });
-                        });
-                });
-    }
 });