ccd4166a4155cd7e0969864b6cf66dcbe2aab9a6
[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(banner, 'banner.html', false);
51                                 cy.get('[data-cy=drag-and-drop]').upload(tooltips, 'tooltips.json', false);
52                             });
53
54                         cy.get('[data-cy=form-submit-btn]').click();
55                         cy.get('[data-cy=form-submit-btn]').should('not.exist');
56                         cy.get('[data-cy=collection-files-right-panel]')
57                             .contains('banner.html').should('exist');
58                         cy.get('[data-cy=collection-files-right-panel]')
59                             .contains('tooltips.json').should('exist');
60                     });
61             });
62             cy.on('uncaught:exception', (err, runnable) => {console.error(err)});
63     });
64
65     beforeEach(function () {
66         cy.clearCookies();
67         cy.clearLocalStorage();
68         cy.intercept({ method: 'GET', url: '**/arvados/v1/config?nocache=*' }, (req) => {
69             req.reply((res) => {
70                 res.body.Workbench.BannerUUID = collectionUUID;
71             });
72         });
73     });
74
75     it('should re-show the banner', () => {
76         cy.loginAs(adminUser);
77
78         cy.wait(2000);
79
80         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
81
82         cy.get('[title=Notifications]').click();
83         cy.get('li').contains('Restore Banner').click();
84
85         cy.wait(2000);
86
87         cy.get('[data-cy=confirmation-dialog-ok-btn]').should('be.visible');
88     });
89
90
91     it('should show tooltips and remove tooltips as localStorage key is present', () => {
92         cy.loginAs(adminUser);
93
94         cy.wait(2000);
95
96         cy.get('[data-cy=side-panel-tree]').then(($el) => {
97             const el = $el.get(0) //native DOM element
98             expect(el._tippy).to.exist;
99         });
100
101         cy.wait(2000);
102
103         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
104
105         cy.get('[title=Notifications]').click();
106         cy.get('li').contains('Disable tooltips').click();
107
108         cy.get('[data-cy=side-panel-tree]').then(($el) => {
109             const el = $el.get(0) //native DOM element
110             expect(el._tippy).to.be.undefined;
111         });
112     });
113 });