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