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