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