494d0c6f275d60e5999e934623cac94a81ffb0b0
[arvados.git] / services / workbench2 / cypress / e2e / banner-tooltip.cy.js
1
2 // Copyright (C) The Arvados Authors. All rights reserved.
3 //
4 // SPDX-License-Identifier: AGPL-3.0
5
6 import { BANNER_LOCAL_STORAGE_KEY } from '../../src/views-components/baner/banner';
7
8 describe('Banner / tooltip tests', function () {
9     let activeUser;
10     let adminUser;
11
12     before(function () {
13         // Only set up common users once. These aren't set up as aliases because
14         // aliases are cleaned up after every test. Also it doesn't make sense
15         // to set the same users on beforeEach() over and over again, so we
16         // separate a little from Cypress' 'Best Practices' here.
17         cy.getUser('admin', 'Admin', 'User', true, true)
18             .as('adminUser').then(function () {
19                 adminUser = this.adminUser;
20             });
21         cy.getUser('collectionuser1', 'Collection', 'User', false, true)
22             .as('activeUser').then(function () {
23                 activeUser = this.activeUser;
24             });
25     });
26
27     beforeEach(function () {
28         cy.on('uncaught:exception', (err, runnable, promise) => {
29             Cypress.log({ message: `Application Error: ${err}`});
30             if (promise) {
31                 return false;
32             }
33         });
34     });
35     
36     it('should re-show the banner', () => {
37         cy.loginAs(adminUser);
38
39         cy.getAll('@adminUser').then(([adminUser]) => {
40             cy.createCollection(adminUser.token, {
41                 name: `BannerTooltipTest${Math.floor(Math.random() * 999999)}`,
42                 owner_uuid: adminUser.user.uuid,
43             }, true).as('bannerCollection');
44         });
45
46         cy.getAll('@bannerCollection').then(function ([bannerCollection]) {
47             cy.intercept({ method: 'GET', hostname: "127.0.0.1", url: '**/arvados/v1/config?nocache=*' }, (req) => {
48                 req.continue((res) => {
49                     if (res.body.Workbench) res.body.Workbench.BannerUUID = bannerCollection.uuid;
50                 });
51             });    
52             
53             cy.goToPath(`/collections/${bannerCollection.uuid}`);
54
55             cy.get('[data-cy=upload-button]').click();
56
57             cy.fixture('files/banner.html').as('banner');
58             cy.fixture('files/tooltips.txt').as('tooltips');
59
60             cy.getAll('@banner', '@tooltips').then(([banner, tooltips]) => {
61                 cy.get('[data-cy=drag-and-drop]').upload(banner, 'banner.html', false);
62                 cy.get('[data-cy=drag-and-drop]').upload(tooltips, 'tooltips.json', false);
63             });
64
65             cy.get('[data-cy=form-submit-btn]').click();
66             cy.get('[data-cy=form-submit-btn]').should('not.exist');
67             cy.get('[data-cy=collection-files-right-panel]')
68             .should('contain', 'banner.html');
69             cy.get('[data-cy=collection-files-right-panel]')
70             .should('contain', 'tooltips.json');
71         })
72         cy.getAll('@bannerCollection').then((bannerCollection)=>{
73             console.log('bannerCollection', bannerCollection[0]);
74             window.localStorage.setItem(BANNER_LOCAL_STORAGE_KEY, bannerCollection)});
75         
76         //manual reload instead of loginAs() to preserve localstorage
77         cy.reload();
78         cy.waitForDom();
79
80         //check that banner appears on reload
81         cy.waitForDom().get('[data-cy=confirmation-dialog]', {timeout: 10000}).should('be.visible');
82         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
83         cy.waitForDom().get('[data-cy=confirmation-dialog]', {timeout: 10000}).should('not.exist');
84
85         //check that banner appears on "Restore Banner"
86         cy.get('[title=Notifications]').click();
87         cy.get('li').contains('Restore Banner').click();
88
89         cy.waitForDom().get('[data-cy=confirmation-dialog-ok-btn]', {timeout: 10000}).should('be.visible');
90         cy.waitForDom().get('[data-cy=confirmation-dialog]', {timeout: 10000}).should('be.visible');
91         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
92         cy.waitForDom().get('[data-cy=confirmation-dialog]', {timeout: 10000}).should('not.exist');
93     });
94
95
96     it('should show tooltips and remove tooltips as localStorage key is present', () => {
97         cy.loginAs(adminUser);
98         cy.waitForDom();
99
100         cy.getAll('@adminUser').then(([adminUser]) => {
101             cy.createCollection(adminUser.token, {
102                 name: `BannerTooltipTest${Math.floor(Math.random() * 999999)}`,
103                 owner_uuid: adminUser.user.uuid,
104             }, true).as('bannerCollection');
105         });
106
107         cy.contains('This allows you to navigate through the app').should('not.exist'); // This content comes from tooltips.txt
108         cy.get('[data-cy=side-panel-tree]').trigger('mouseover');
109         cy.get('[data-cy=side-panel-tree]').trigger('mouseenter');
110         cy.contains('This allows you to navigate through the app').should('be.visible');
111
112         cy.get('[title=Notifications]').click();
113         cy.get('li').contains('Disable tooltips').click();
114
115         cy.contains('This allows you to navigate through the app').should('not.exist');
116         cy.get('[data-cy=side-panel-tree]').trigger('mouseover');
117         cy.get('[data-cy=side-panel-tree]').trigger('mouseenter');
118         cy.contains('This allows you to navigate through the app').should('not.exist');
119     });
120 });