19231: Add smaller page sizes (10 and 20 items) to load faster
[arvados-workbench2.git] / cypress / integration / search.spec.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 describe('Search tests', function() {
6     let activeUser;
7     let adminUser;
8
9     before(function() {
10         // Only set up common users once. These aren't set up as aliases because
11         // aliases are cleaned up after every test. Also it doesn't make sense
12         // to set the same users on beforeEach() over and over again, so we
13         // separate a little from Cypress' 'Best Practices' here.
14         cy.getUser('admin', 'Admin', 'User', true, true)
15             .as('adminUser').then(function() {
16                 adminUser = this.adminUser;
17             }
18         );
19         cy.getUser('collectionuser1', 'Collection', 'User', false, true)
20             .as('activeUser').then(function() {
21                 activeUser = this.activeUser;
22             }
23         );
24     })
25
26     beforeEach(function() {
27         cy.clearCookies()
28         cy.clearLocalStorage()
29     })
30
31     it('can search for old collection versions', function() {
32         const colName = `Versioned Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
33         let colUuid = '';
34         let oldVersionUuid = '';
35         // Make sure no other collections with this name exist
36         cy.doRequest('GET', '/arvados/v1/collections', null, {
37             filters: `[["name", "=", "${colName}"]]`,
38             include_old_versions: true
39         })
40         .its('body.items').as('collections')
41         .then(function() {
42             expect(this.collections).to.be.empty;
43         });
44         // Creates the collection using the admin token so we can set up
45         // a bogus manifest text without block signatures.
46         cy.createCollection(adminUser.token, {
47             name: colName,
48             owner_uuid: activeUser.user.uuid,
49             preserve_version: true,
50             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"})
51         .as('originalVersion').then(function() {
52             // Change the file name to create a new version.
53             cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
54                 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n"
55             })
56             colUuid = this.originalVersion.uuid;
57         });
58         // Confirm that there are 2 versions of the collection
59         cy.doRequest('GET', '/arvados/v1/collections', null, {
60             filters: `[["name", "=", "${colName}"]]`,
61             include_old_versions: true
62         })
63         .its('body.items').as('collections')
64         .then(function() {
65             expect(this.collections).to.have.lengthOf(2);
66             this.collections.map(function(aCollection) {
67                 expect(aCollection.current_version_uuid).to.equal(colUuid);
68                 if (aCollection.uuid !== aCollection.current_version_uuid) {
69                     oldVersionUuid = aCollection.uuid;
70                 }
71             });
72             cy.loginAs(activeUser);
73             const searchQuery = `${colName} type:arvados#collection`;
74             // Search for only collection's current version
75             cy.doSearch(`${searchQuery}`);
76             cy.get('[data-cy=search-results]').should('contain', 'head version');
77             cy.get('[data-cy=search-results]').should('not.contain', 'version 1');
78             // ...and then, include old versions.
79             cy.doSearch(`${searchQuery} is:pastVersion`);
80             cy.get('[data-cy=search-results]').should('contain', 'head version');
81             cy.get('[data-cy=search-results]').should('contain', 'version 1');
82         });
83     });
84
85     it('can display path of the selected item', function() {
86         const colName = `Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
87
88         // Creates the collection using the admin token so we can set up
89         // a bogus manifest text without block signatures.
90         cy.createCollection(adminUser.token, {
91             name: colName,
92             owner_uuid: activeUser.user.uuid,
93             preserve_version: true,
94             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
95         }).then(function() {
96             cy.loginAs(activeUser);
97
98             cy.doSearch(colName);
99
100             cy.get('[data-cy=search-results]').should('contain', colName);
101
102             cy.get('[data-cy=search-results]').contains(colName).closest('tr').click();
103
104             cy.get('[data-cy=element-path]').should('contain', `/ Projects / ${colName}`);
105         });
106     });
107
108     it('can display owner of the item', function() {
109         const colName = `Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
110
111         cy.createCollection(adminUser.token, {
112             name: colName,
113             owner_uuid: activeUser.user.uuid,
114             preserve_version: true,
115             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
116         }).then(function() {
117             cy.loginAs(activeUser);
118
119             cy.doSearch(colName);
120
121             cy.get('[data-cy=search-results]').should('contain', colName);
122
123             cy.get('[data-cy=search-results]').contains(colName).closest('tr')
124                 .within(() => {
125                     cy.get('p').contains(activeUser.user.uuid).should('contain', activeUser.user.full_name);
126                 });
127         });
128     });
129
130     it('shows search context menu', function() {
131         const colName = `Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
132         const federatedColName = `Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
133         const federatedColUuid = "xxxxx-4zz18-000000000000000";
134
135         // Intercept config to insert remote cluster
136         cy.intercept({method: 'GET', hostname: 'localhost', url: '**/arvados/v1/config?nocache=*'}, (req) => {
137             req.reply((res) => {
138                 res.body.RemoteClusters = {
139                     "*": res.body.RemoteClusters["*"],
140                     "xxxxx": {
141                         "ActivateUsers": true,
142                         "Host": "xxxxx.fakecluster.tld",
143                         "Insecure": false,
144                         "Proxy": true,
145                         "Scheme": ""
146                     }
147                 };
148             });
149         });
150
151         // Fake remote cluster config
152         cy.intercept(
153           {
154             method: "GET",
155             hostname: "xxxxx.fakecluster.tld",
156             url: "**/arvados/v1/config",
157           },
158           {
159             statusCode: 200,
160             body: {
161               API: {},
162               ClusterID: "xxxxx",
163               Collections: {},
164               Containers: {},
165               InstanceTypes: {},
166               Login: {},
167               Mail: { SupportEmailAddress: "arvados@example.com" },
168               RemoteClusters: {
169                 "*": {
170                   ActivateUsers: false,
171                   Host: "",
172                   Insecure: false,
173                   Proxy: false,
174                   Scheme: "https",
175                 },
176               },
177               Services: {
178                 Composer: { ExternalURL: "" },
179                 Controller: { ExternalURL: "https://xxxxx.fakecluster.tld:34763/" },
180                 DispatchCloud: { ExternalURL: "" },
181                 DispatchLSF: { ExternalURL: "" },
182                 DispatchSLURM: { ExternalURL: "" },
183                 GitHTTP: { ExternalURL: "https://xxxxx.fakecluster.tld:39105/" },
184                 GitSSH: { ExternalURL: "" },
185                 Health: { ExternalURL: "https://xxxxx.fakecluster.tld:42915/" },
186                 Keepbalance: { ExternalURL: "" },
187                 Keepproxy: { ExternalURL: "https://xxxxx.fakecluster.tld:46773/" },
188                 Keepstore: { ExternalURL: "" },
189                 RailsAPI: { ExternalURL: "" },
190                 WebDAV: { ExternalURL: "https://xxxxx.fakecluster.tld:36041/" },
191                 WebDAVDownload: { ExternalURL: "https://xxxxx.fakecluster.tld:42957/" },
192                 WebShell: { ExternalURL: "" },
193                 Websocket: { ExternalURL: "wss://xxxxx.fakecluster.tld:37121/websocket" },
194                 Workbench1: { ExternalURL: "https://wb1.xxxxx.fakecluster.tld/" },
195                 Workbench2: { ExternalURL: "https://wb2.xxxxx.fakecluster.tld/" },
196               },
197               StorageClasses: {
198                 default: { Default: true, Priority: 0 },
199               },
200               Users: {},
201               Volumes: {},
202               Workbench: {},
203             },
204           }
205         );
206
207         cy.createCollection(adminUser.token, {
208             name: colName,
209             owner_uuid: activeUser.user.uuid,
210             preserve_version: true,
211             manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
212         }).then(function(testCollection) {
213             cy.loginAs(activeUser);
214
215             // Intercept search results to add federated result
216             cy.intercept({method: 'GET', url: '**/arvados/v1/groups/contents?*'}, (req) => {
217                 req.reply((res) => {
218                     res.body.items = [
219                         res.body.items[0],
220                         {
221                             ...res.body.items[0],
222                             uuid: federatedColUuid,
223                             portable_data_hash: "00000000000000000000000000000000+0",
224                             name: federatedColName,
225                             href: res.body.items[0].href.replace(testCollection.uuid, federatedColUuid),
226                         }
227                     ];
228                     res.body.items_available += 1;
229                 });
230             });
231
232             cy.doSearch(colName);
233
234             // Stub new window
235             cy.window().then(win => {
236                 cy.stub(win, 'open').as('Open')
237             });
238
239             // Check copy to clipboard
240             cy.get('[data-cy=search-results]').contains(colName).rightclick();
241             cy.get('[data-cy=context-menu]').within((ctx) => {
242                 // Check that there are 4 items in the menu
243                 cy.get(ctx).children().should('have.length', 4);
244                 cy.contains('Advanced');
245                 cy.contains('Copy to clipboard');
246                 cy.contains('Open in new tab');
247                 cy.contains('View details');
248
249                 cy.contains('Copy to clipboard').click();
250                 cy.window().then((win) => (
251                     win.navigator.clipboard.readText().then((text) => {
252                         expect(text).to.match(new RegExp(`/collections/${testCollection.uuid}$`));
253                     })
254                 ));
255             });
256
257             // Check open in new tab
258             cy.get('[data-cy=search-results]').contains(colName).rightclick();
259             cy.get('[data-cy=context-menu]').within(() => {
260                 cy.contains('Open in new tab').click();
261                 cy.get('@Open').should('have.been.calledOnceWith', `${window.location.origin}/collections/${testCollection.uuid}`)
262             });
263
264             // Check federated result copy to clipboard
265             cy.get('[data-cy=search-results]').contains(federatedColName).rightclick();
266             cy.get('[data-cy=context-menu]').within(() => {
267                 cy.contains('Copy to clipboard').click();
268                 cy.window().then((win) => (
269                     win.navigator.clipboard.readText().then((text) => {
270                         expect(text).to.equal(`https://wb2.xxxxx.fakecluster.tld/collections/${federatedColUuid}`);
271                     })
272                 ));
273             });
274             // Check open in new tab
275             cy.get('[data-cy=search-results]').contains(federatedColName).rightclick();
276             cy.get('[data-cy=context-menu]').within(() => {
277                 cy.contains('Open in new tab').click();
278                 cy.get('@Open').should('have.been.calledWith', `https://wb2.xxxxx.fakecluster.tld/collections/${federatedColUuid}`)
279             });
280
281         });
282     });
283 });