21621: Add copy button to virtual code snippet for io panel json tab
[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 describe('Banner / tooltip tests', function () {
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.getAll('@adminUser').then(([adminUser]) => {
20             // This collection will not be deleted after each test, we'll
21             // clean it up manually.
22             cy.createCollection(adminUser.token, {
23                 name: `BannerTooltipTest${Math.floor(Math.random() * 999999)}`,
24                 owner_uuid: adminUser.user.uuid,
25             }, true).as('bannerCollection');
26         });
27
28         cy.getAll('@bannerCollection').then(function ([bannerCollection]) {
29             collectionUUID = bannerCollection.uuid;
30
31             cy.loginAs(adminUser);
32
33             cy.goToPath(`/collections/${bannerCollection.uuid}`);
34
35             cy.get('[data-cy=upload-button]').click();
36
37             cy.fixture('files/banner.html').as('banner');
38             cy.fixture('files/tooltips.txt').as('tooltips');
39
40             cy.getAll('@banner', '@tooltips').then(([banner, tooltips]) => {
41                 cy.get('[data-cy=drag-and-drop]').upload(banner, 'banner.html', false);
42                 cy.get('[data-cy=drag-and-drop]').upload(tooltips, 'tooltips.json', false);
43             });
44
45             cy.get('[data-cy=form-submit-btn]').click();
46             cy.get('[data-cy=form-submit-btn]').should('not.exist');
47             cy.get('[data-cy=collection-files-right-panel]')
48                 .should('contain', 'banner.html');
49             cy.get('[data-cy=collection-files-right-panel]')
50                 .should('contain', 'tooltips.json');
51         });
52     });
53
54     beforeEach(function () {
55         cy.on('uncaught:exception', (err, runnable, promise) => {
56             Cypress.log({ message: `Application Error: ${err}`});
57             if (promise) {
58                 return false;
59             }
60         });
61
62         //login here instead of in specific tests to preserve localStorage and intercept listener
63         cy.loginAs(adminUser);
64
65         //must be in localstorage to have banner option in notifications menu
66         //it doesn't matter what the value is, as long as it's truthy
67         window.localStorage.setItem('bannerFileData', 'foo');
68
69         cy.intercept({ method: 'GET', url: '**/arvados/v1/config?nocache=*' }, (req) => {
70             req.on('response', (res) => {
71                 res.body.Workbench.BannerUUID = collectionUUID;
72             });
73         });
74     });
75
76     after(function () {
77         // Delete banner collection after all test used it.
78         cy.deleteResource(adminUser.token, "collections", collectionUUID);
79     });
80
81     it('should re-show the banner', () => {
82         //reload instead of cy.loginAs() to preserve localStorage and intercept listener
83         //logged in as adminUser
84         cy.reload();
85         cy.waitForDom();
86
87         //check that banner appears on reload
88         cy.waitForDom().get('[data-cy=confirmation-dialog]', {timeout: 10000}).should('be.visible');
89         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
90         cy.waitForDom().get('[data-cy=confirmation-dialog]', {timeout: 10000}).should('not.exist');
91
92         //check that banner appears on toggle
93         cy.get('[title=Notifications]').click();
94         cy.get('li').contains('Restore Banner').click();
95
96         cy.waitForDom().get('[data-cy=confirmation-dialog-ok-btn]', {timeout: 10000}).should('be.visible');
97         cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
98         cy.waitForDom().get('[data-cy=confirmation-dialog]', {timeout: 10000}).should('not.exist');
99     });
100
101
102     it('should show tooltips and remove tooltips as localStorage key is present', () => {
103         //reload instead of cy.loginAs() to preserve localStorage and intercept listener
104         //logged in as adminUser
105         cy.reload();
106         cy.waitForDom();
107
108         //banner appears on reload
109         cy.waitForDom().get('[data-cy=confirmation-dialog]', {timeout: 10000}).should('be.visible');
110         cy.get('[data-cy=confirmation-dialog-ok-btn]').click({force: true});
111         cy.waitForDom().get('[data-cy=confirmation-dialog]', {timeout: 10000}).should('not.exist');
112
113         cy.contains('This allows you to navigate through the app').should('not.exist'); // This content comes from tooltips.txt
114         cy.get('[data-cy=side-panel-tree]').trigger('mouseover');
115         cy.get('[data-cy=side-panel-tree]').trigger('mouseenter');
116         cy.contains('This allows you to navigate through the app').should('be.visible');
117
118         cy.get('[title=Notifications]').click();
119         cy.get('li').contains('Disable tooltips').click();
120
121         cy.contains('This allows you to navigate through the app').should('not.exist');
122         cy.get('[data-cy=side-panel-tree]').trigger('mouseover');
123         cy.get('[data-cy=side-panel-tree]').trigger('mouseenter');
124         cy.contains('This allows you to navigate through the app').should('not.exist');
125     });
126 });