21507: tweaked banner test Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa.knox@curii...
[arvados.git] / services / workbench2 / cypress / e2e / banner-tooltip.cy.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 describe('Banner / tooltip tests', function () {
6     let activeUser;
7     let adminUser;
8     let collectionUUID;
9
10     before(function () {
11         // Only set up common users once. These aren't set up as aliases because
12         // aliases are cleaned up after every test. Also it doesn't make sense
13         // to set the same users on beforeEach() over and over again, so we
14         // separate a little from Cypress' 'Best Practices' here.
15         cy.getUser('admin', 'Admin', 'User', true, true)
16             .as('adminUser').then(function () {
17                 adminUser = this.adminUser;
18             });
19         cy.getUser('collectionuser1', 'Collection', 'User', false, true)
20             .as('activeUser').then(function () {
21                 activeUser = this.activeUser;
22             });
23     });
24
25     beforeEach(function () {
26         cy.on('uncaught:exception', (err, runnable, promise) => {
27             Cypress.log({ message: `Application Error: ${err}`});
28             if (promise) {
29                 return false;
30             }
31         });
32
33         cy.createCollection(adminUser.token, {
34             name: `BannerTooltipTest${Math.floor(Math.random() * 999999)}`,
35             owner_uuid: adminUser.user.uuid,
36         }).as('bannerCollection');
37
38         cy.getAll('@bannerCollection').then(function ([bannerCollection]) {
39             collectionUUID=bannerCollection.uuid;
40
41             cy.loginAs(adminUser);
42
43             cy.goToPath(`/collections/${bannerCollection.uuid}`);
44
45             cy.get('[data-cy=upload-button]').click();
46
47             cy.fixture('files/banner.html').as('banner');
48             cy.fixture('files/tooltips.txt').as('tooltips');
49
50             cy.getAll('@banner', '@tooltips').then(([banner, tooltips]) => {
51                 cy.get('[data-cy=drag-and-drop]').upload(banner, 'banner.html', false);
52                 cy.get('[data-cy=drag-and-drop]').upload(tooltips, 'tooltips.json', false);
53             });
54
55             cy.get('[data-cy=form-submit-btn]').click();
56             cy.get('[data-cy=form-submit-btn]').should('not.exist');
57             cy.get('[data-cy=collection-files-right-panel]')
58                 .should('contain', 'banner.html');
59             cy.get('[data-cy=collection-files-right-panel]')
60                 .should('contain', 'tooltips.json');
61
62             cy.intercept({ method: 'GET', url: '**/arvados/v1/config?nocache=*' }, (req) => {
63                 req.reply((res) => {
64                     res.body.Workbench.BannerUUID = collectionUUID;
65                 });
66             });
67         });
68     });
69
70     it('should re-show the banner', () => {
71         cy.loginAs(adminUser);
72
73         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
74
75         cy.get('[title=Notifications]').click({ force: true });
76         cy.get('li').contains('Restore Banner').click();
77
78         cy.get('[data-cy=confirmation-dialog-ok-btn]').should('be.visible');
79     });
80
81
82     it('should show tooltips and remove tooltips as localStorage key is present', () => {
83         cy.loginAs(adminUser);
84
85         cy.get('[data-cy=side-panel-tree]').then(($el) => {
86             const el = $el.get(0) //native DOM element
87             expect(el._tippy).to.exist;
88         });
89
90         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
91
92         cy.get('[title=Notifications]').click();
93         cy.get('li').contains('Disable tooltips').click();
94
95         cy.get('[data-cy=side-panel-tree]').then(($el) => {
96             const el = $el.get(0) //native DOM element
97             expect(el._tippy).to.be.undefined;
98         });
99     });
100 });