1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 describe("Search tests", 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)
17 adminUser = this.adminUser;
19 cy.getUser("collectionuser1", "Collection", "User", false, true)
22 activeUser = this.activeUser;
26 beforeEach(function () {
28 cy.clearLocalStorage();
31 it("can search for old collection versions", function () {
32 const colName = `Versioned Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
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,
43 expect(this.collections).to.be.empty;
45 // Creates the collection using the admin token so we can set up
46 // a bogus manifest text without block signatures.
47 cy.createCollection(adminUser.token, {
49 owner_uuid: activeUser.user.uuid,
50 preserve_version: true,
51 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n",
53 .as("originalVersion")
55 // Change the file name to create a new version.
56 cy.updateCollection(adminUser.token, this.originalVersion.uuid, {
57 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:foo\n",
59 colUuid = this.originalVersion.uuid;
61 // Confirm that there are 2 versions of the collection
62 cy.doRequest("GET", "/arvados/v1/collections", null, {
63 filters: `[["name", "=", "${colName}"]]`,
64 include_old_versions: true,
69 expect(this.collections).to.have.lengthOf(2);
70 this.collections.map(function (aCollection) {
71 expect(aCollection.current_version_uuid).to.equal(colUuid);
72 if (aCollection.uuid !== aCollection.current_version_uuid) {
73 oldVersionUuid = aCollection.uuid;
76 cy.loginAs(activeUser);
77 const searchQuery = `${colName} type:arvados#collection`;
78 // Search for only collection's current version
79 cy.doSearch(`${searchQuery}`);
80 cy.get("[data-cy=search-results]").should("contain", "head version");
81 cy.get("[data-cy=search-results]").should("not.contain", "version 1");
82 // ...and then, include old versions.
83 cy.doSearch(`${searchQuery} is:pastVersion`);
84 cy.get("[data-cy=search-results]").should("contain", "head version");
85 cy.get("[data-cy=search-results]").should("contain", "version 1");
89 it("can display path of the selected item", function () {
90 const colName = `Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
92 // Creates the collection using the admin token so we can set up
93 // a bogus manifest text without block signatures.
94 cy.createCollection(adminUser.token, {
96 owner_uuid: activeUser.user.uuid,
97 preserve_version: true,
98 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n",
100 cy.loginAs(activeUser);
102 cy.doSearch(colName);
104 cy.get("[data-cy=search-results]").should("contain", colName);
106 cy.get("[data-cy=search-results]").contains(colName).closest("tr").click();
108 cy.get("[data-cy=element-path]").should("contain", `/ Projects / ${colName}`);
112 it("can search items using quotes", function () {
113 const random = Math.floor(Math.random() * Math.floor(999999));
114 const colName = `Collection ${random}`;
115 const colName2 = `Collection test ${random}`;
117 // Creates the collection using the admin token so we can set up
118 // a bogus manifest text without block signatures.
119 cy.createCollection(adminUser.token, {
121 owner_uuid: activeUser.user.uuid,
122 preserve_version: true,
123 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n",
124 }).as("collection1");
126 cy.createCollection(adminUser.token, {
128 owner_uuid: activeUser.user.uuid,
129 preserve_version: true,
130 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n",
131 }).as("collection2");
133 cy.getAll("@collection1", "@collection2").then(function () {
134 cy.loginAs(activeUser);
136 cy.doSearch(colName);
137 cy.get("[data-cy=search-results] table tbody tr").should("have.length", 2);
139 cy.doSearch(`"${colName}"`);
140 cy.get("[data-cy=search-results] table tbody tr").should("have.length", 1);
144 it("can display owner of the item", function () {
145 const colName = `Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
147 cy.createCollection(adminUser.token, {
149 owner_uuid: activeUser.user.uuid,
150 preserve_version: true,
151 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n",
152 }).then(function () {
153 cy.loginAs(activeUser);
155 cy.doSearch(colName);
157 cy.get("[data-cy=search-results]").should("contain", colName);
159 cy.get("[data-cy=search-results]")
163 cy.get("p").contains(activeUser.user.uuid).should("contain", activeUser.user.full_name);
168 it("shows search context menu", function () {
169 const colName = `Home Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
170 const federatedColName = `Federated Collection ${Math.floor(Math.random() * Math.floor(999999))}`;
171 const federatedColUuid = "xxxxx-4zz18-000000000000000";
173 // Intercept config to insert remote cluster
174 cy.intercept({ method: "GET", hostname: "127.0.0.1", url: "**/arvados/v1/config?nocache=*" }, req => {
176 res.body.RemoteClusters = {
177 "*": res.body.RemoteClusters["*"],
180 Host: "xxxxx.fakecluster.tld",
189 // Fake remote cluster config
193 hostname: "xxxxx.fakecluster.tld",
194 url: "**/arvados/v1/config",
205 Mail: { SupportEmailAddress: "arvados@example.com" },
208 ActivateUsers: false,
216 Composer: { ExternalURL: "" },
217 Controller: { ExternalURL: "https://xxxxx.fakecluster.tld:34763/" },
218 DispatchCloud: { ExternalURL: "" },
219 DispatchLSF: { ExternalURL: "" },
220 DispatchSLURM: { ExternalURL: "" },
221 GitHTTP: { ExternalURL: "https://xxxxx.fakecluster.tld:39105/" },
222 GitSSH: { ExternalURL: "" },
223 Health: { ExternalURL: "https://xxxxx.fakecluster.tld:42915/" },
224 Keepbalance: { ExternalURL: "" },
225 Keepproxy: { ExternalURL: "https://xxxxx.fakecluster.tld:46773/" },
226 Keepstore: { ExternalURL: "" },
227 RailsAPI: { ExternalURL: "" },
228 WebDAV: { ExternalURL: "https://xxxxx.fakecluster.tld:36041/" },
229 WebDAVDownload: { ExternalURL: "https://xxxxx.fakecluster.tld:42957/" },
230 WebShell: { ExternalURL: "" },
231 Websocket: { ExternalURL: "wss://xxxxx.fakecluster.tld:37121/websocket" },
232 Workbench1: { ExternalURL: "https://wb1.xxxxx.fakecluster.tld/" },
233 Workbench2: { ExternalURL: "https://wb2.xxxxx.fakecluster.tld/" },
236 default: { Default: true, Priority: 0 },
245 cy.createCollection(adminUser.token, {
247 owner_uuid: activeUser.user.uuid,
248 preserve_version: true,
249 manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n",
250 }).then(function (testCollection) {
251 cy.loginAs(activeUser);
253 // Intercept search results to add federated result
254 cy.intercept({ method: "GET", url: "**/arvados/v1/groups/contents?*" }, req => {
259 ...res.body.items[0],
260 uuid: federatedColUuid,
261 portable_data_hash: "00000000000000000000000000000000+0",
262 name: federatedColName,
263 href: res.body.items[0].href.replace(testCollection.uuid, federatedColUuid),
266 res.body.items_available += 1;
270 cy.doSearch(colName);
273 cy.window().then(win => {
274 cy.stub(win, "open").as("Open");
277 // Check copy to clipboard
278 cy.get("[data-cy=search-results]").contains(colName).rightclick();
279 cy.get("[data-cy=context-menu]").within(ctx => {
280 // Check that there are 4 items in the menu
281 cy.get(ctx).children().should("have.length", 4);
282 cy.contains("API Details");
283 cy.contains("Copy to clipboard");
284 cy.contains("Open in new tab");
285 cy.contains("View details");
287 cy.contains("Copy to clipboard").click();
289 cy.window().then(win =>
290 win.navigator.clipboard.readText().then(text => {
291 expect(text).to.match(new RegExp(`/collections/${testCollection.uuid}$`));
296 // Check open in new tab
297 cy.get("[data-cy=search-results]").contains(colName).rightclick();
298 cy.get("[data-cy=context-menu]").within(() => {
299 cy.contains("Open in new tab").click();
301 cy.get("@Open").should("have.been.calledOnceWith", `${window.location.origin}/collections/${testCollection.uuid}`);
304 // Check federated result copy to clipboard
305 cy.get("[data-cy=search-results]").contains(federatedColName).rightclick();
306 cy.get("[data-cy=context-menu]").within(() => {
307 cy.contains("Copy to clipboard").click();
309 cy.window().then(win =>
310 win.navigator.clipboard.readText().then(text => {
311 expect(text).to.equal(`https://wb2.xxxxx.fakecluster.tld/collections/${federatedColUuid}`);
315 // Check open in new tab
316 cy.get("[data-cy=search-results]").contains(federatedColName).rightclick();
317 cy.get("[data-cy=context-menu]").within(() => {
318 cy.contains("Open in new tab").click();
320 cy.get("@Open").should("have.been.calledWith", `https://wb2.xxxxx.fakecluster.tld/collections/${federatedColUuid}`);