19836: Cypress tests added
authorDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Fri, 10 Feb 2023 16:56:37 +0000 (17:56 +0100)
committerDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Fri, 10 Feb 2023 16:56:37 +0000 (17:56 +0100)
Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla@contractors.roche.com>

cypress/fixtures/files/banner.html [new file with mode: 0644]
cypress/fixtures/files/tooltips.txt [new file with mode: 0644]
cypress/integration/banner-tooltip.spec.js [new file with mode: 0644]

diff --git a/cypress/fixtures/files/banner.html b/cypress/fixtures/files/banner.html
new file mode 100644 (file)
index 0000000..34966bd
--- /dev/null
@@ -0,0 +1,5 @@
+<div>
+    <h1>Hi there</h1>
+    <h3>This is my amazing</h3>
+    <h5 style="color: red">Banner</h5>
+</div>
\ No newline at end of file
diff --git a/cypress/fixtures/files/tooltips.txt b/cypress/fixtures/files/tooltips.txt
new file mode 100644 (file)
index 0000000..c3c2162
--- /dev/null
@@ -0,0 +1,3 @@
+{
+    "[data-cy=side-panel-tree]": "This allows you to navigate through the app"
+}
\ No newline at end of file
diff --git a/cypress/integration/banner-tooltip.spec.js b/cypress/integration/banner-tooltip.spec.js
new file mode 100644 (file)
index 0000000..f331a88
--- /dev/null
@@ -0,0 +1,108 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+describe('Collection panel tests', function () {
+    let activeUser;
+    let adminUser;
+    let collectionUUID;
+
+    before(function () {
+        // Only set up common users once. These aren't set up as aliases because
+        // aliases are cleaned up after every test. Also it doesn't make sense
+        // to set the same users on beforeEach() over and over again, so we
+        // separate a little from Cypress' 'Best Practices' here.
+        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.getAll('@adminUser')
+            .then(function([adminUser]) {
+                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]) => {
+                                console.log(tooltips)
+                                cy.get('[data-cy=drag-and-drop]').upload(btoa(banner), 'banner.html');
+                                cy.get('[data-cy=drag-and-drop]').upload(btoa(tooltips), 'tooltips.json');
+                            });
+  
+                        cy.get('[data-cy=form-submit-btn]').click();
+                    });
+            });
+            cy.on('uncaught:exception', (err, runnable) => {console.error(err)});
+    });
+
+    beforeEach(function () {
+        cy.clearCookies();
+        cy.clearLocalStorage();
+        cy.intercept({ method: 'GET', hostname: 'localhost', url: '**/arvados/v1/config?nocache=*' }, (req) => {
+            req.reply((res) => {
+                res.body.Workbench.BannerUUID = collectionUUID;
+            });
+        });
+    });
+
+    it('should re-show the banner', () => {
+        cy.loginAs(adminUser);
+
+        cy.wait(2000);
+
+        cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
+
+        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', () => {
+        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.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;
+        });
+    });
+});