Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / cypress / integration / banner-tooltip.spec.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             );
20         cy.getUser('collectionuser1', 'Collection', 'User', false, true)
21             .as('activeUser').then(function () {
22                 activeUser = this.activeUser;
23             });
24             cy.on('uncaught:exception', (err, runnable) => {console.error(err)});
25     });
26
27     beforeEach(function () {
28         cy.clearCookies();
29         cy.clearLocalStorage();
30     });
31
32     it('should re-show the banner', () => {
33         setupTheEnvironment();
34
35         cy.loginAs(adminUser);
36
37         cy.wait(2000);
38
39         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
40
41         cy.get('[title=Notifications]').click();
42         cy.get('li').contains('Restore Banner').click();
43
44         cy.wait(2000);
45
46         cy.get('[data-cy=confirmation-dialog-ok-btn]').should('be.visible');
47     });
48
49
50     it('should show tooltips and remove tooltips as localStorage key is present', () => {
51         setupTheEnvironment();
52
53         cy.loginAs(adminUser);
54
55         cy.wait(2000);
56
57         cy.get('[data-cy=side-panel-tree]').then(($el) => {
58             const el = $el.get(0) //native DOM element
59             expect(el._tippy).to.exist;
60         });
61
62         cy.wait(2000);
63
64         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
65
66         cy.get('[title=Notifications]').click();
67         cy.get('li').contains('Disable tooltips').click();
68
69         cy.get('[data-cy=side-panel-tree]').then(($el) => {
70             const el = $el.get(0) //native DOM element
71             expect(el._tippy).to.be.undefined;
72         });
73     });
74
75     const setupTheEnvironment = () => {
76             cy.createCollection(adminUser.token, {
77                 name: `BannerTooltipTest${Math.floor(Math.random() * 999999)}`,
78                 owner_uuid: adminUser.user.uuid,
79             }).as('bannerCollection');
80
81             cy.getAll('@bannerCollection')
82                 .then(function ([bannerCollection]) {
83
84                     collectionUUID=bannerCollection.uuid;
85
86                     cy.loginAs(adminUser);
87
88                     cy.goToPath(`/collections/${bannerCollection.uuid}`);
89
90                     cy.get('[data-cy=upload-button]').click();
91
92                     cy.fixture('files/banner.html').as('banner');
93                     cy.fixture('files/tooltips.txt').as('tooltips');
94
95                     cy.getAll('@banner', '@tooltips')
96                         .then(([banner, tooltips]) => {
97                             cy.get('[data-cy=drag-and-drop]').upload(banner, 'banner.html', false);
98                             cy.get('[data-cy=drag-and-drop]').upload(tooltips, 'tooltips.json', false);
99                         });
100
101                     cy.get('[data-cy=form-submit-btn]').click();
102                     cy.get('[data-cy=form-submit-btn]').should('not.exist');
103                     cy.get('[data-cy=collection-files-right-panel]')
104                         .contains('banner.html').should('exist');
105                     cy.get('[data-cy=collection-files-right-panel]')
106                         .contains('tooltips.json').should('exist');
107
108                         cy.intercept({ method: 'GET', url: '**/arvados/v1/config?nocache=*' }, (req) => {
109                             req.reply((res) => {
110                                 res.body.Workbench.BannerUUID = collectionUUID;
111                             });
112                         });
113                 });
114     }
115 });