21535: test spec tweaks Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa.knox@curii...
[arvados.git] / services / workbench2 / cypress / e2e / process.cy.js
index f647560a5fcc7bcee66b1b3007d9aecf47c49823..2a5a62927fd981f09132d1a9c5eb6a1db9205c2f 100644 (file)
@@ -25,11 +25,6 @@ describe("Process tests", function () {
             });
     });
 
-    beforeEach(function () {
-        cy.clearCookies();
-        cy.clearLocalStorage();
-    });
-
     function setupDockerImage(image_name) {
         // Create a collection that will be used as a docker image for the tests.
         cy.createCollection(adminUser.token, {
@@ -153,7 +148,7 @@ describe("Process tests", function () {
 
             // Fake submitted by another user
             cy.intercept({ method: "GET", url: "**/arvados/v1/container_requests/*" }, req => {
-                req.reply(res => {
+                req.on('response', res => {
                     res.body.modified_by_user_uuid = "zzzzz-tpzed-000000000000000";
                 });
             });
@@ -224,7 +219,7 @@ describe("Process tests", function () {
             // Force container_count for testing
             let containerCount = 2;
             cy.intercept({ method: "GET", url: "**/arvados/v1/container_requests/*" }, req => {
-                req.reply(res => {
+                req.on('response', res => {
                     res.body.container_count = containerCount;
                 });
             });
@@ -337,6 +332,7 @@ describe("Process tests", function () {
             createContainerRequest(activeUser, crUncommitted, "arvados/jobs", ["echo", "hello world"], false, "Uncommitted").then(function (
                 containerRequest
             ) {
+                cy.loginAs(activeUser);
                 // Navigate to process and verify run / cancel button
                 cy.goToPath(`/processes/${containerRequest.uuid}`);
                 cy.waitForDom();
@@ -353,7 +349,7 @@ describe("Process tests", function () {
             ) {
                 // Fake container uuid
                 cy.intercept({ method: "GET", url: `**/arvados/v1/container_requests/${containerRequest.uuid}` }, req => {
-                    req.reply(res => {
+                    req.on('response', res => {
                         res.body.output_uuid = fakeCrUuid;
                         res.body.priority = 500;
                         res.body.state = "Committed";
@@ -385,7 +381,7 @@ describe("Process tests", function () {
             ) {
                 // Fake container uuid
                 cy.intercept({ method: "GET", url: `**/arvados/v1/container_requests/${containerRequest.uuid}` }, req => {
-                    req.reply(res => {
+                    req.on('response', res => {
                         res.body.output_uuid = fakeCrLockedUuid;
                         res.body.priority = 500;
                         res.body.state = "Committed";
@@ -417,7 +413,7 @@ describe("Process tests", function () {
             ) {
                 // Fake container uuid
                 cy.intercept({ method: "GET", url: `**/arvados/v1/container_requests/${containerRequest.uuid}` }, req => {
-                    req.reply(res => {
+                    req.on('response', res => {
                         res.body.output_uuid = fakeCrOnHoldUuid;
                         res.body.priority = 0;
                         res.body.state = "Committed";
@@ -447,7 +443,7 @@ describe("Process tests", function () {
     describe("Logs panel", function () {
         it("shows live process logs", function () {
             cy.intercept({ method: "GET", url: "**/arvados/v1/containers/*" }, req => {
-                req.reply(res => {
+                req.on('response', res => {
                     res.body.state = ContainerState.RUNNING;
                 });
             });
@@ -579,23 +575,23 @@ describe("Process tests", function () {
 
                 cy.getAll("@node-info", "@stdout", "@stderr").then(() => {
                     // Verify sorted main logs
-                    cy.get("[data-cy=process-logs] pre", { timeout: 7000 }).eq(0).should("contain", "2023-07-18T20:14:48.128642814Z first");
-                    cy.get("[data-cy=process-logs] pre").eq(1).should("contain", "2023-07-18T20:14:48.528642814Z second");
-                    cy.get("[data-cy=process-logs] pre").eq(2).should("contain", "2023-07-18T20:14:49.128642814Z third");
+                    cy.get("[data-cy=process-logs] span > p", { timeout: 7000 }).eq(0).should("contain", "2023-07-18T20:14:48.128642814Z first");
+                    cy.get("[data-cy=process-logs] span > p").eq(1).should("contain", "2023-07-18T20:14:48.528642814Z second");
+                    cy.get("[data-cy=process-logs] span > p").eq(2).should("contain", "2023-07-18T20:14:49.128642814Z third");
 
                     // Switch to All logs
                     cy.get("[data-cy=process-logs-filter]").click();
                     cy.get("body").contains("li", "All logs").click();
                     // Verify non-sorted lines were preserved
-                    cy.get("[data-cy=process-logs] pre").eq(0).should("contain", "3: nodeinfo 1");
-                    cy.get("[data-cy=process-logs] pre").eq(1).should("contain", "2: nodeinfo 2");
-                    cy.get("[data-cy=process-logs] pre").eq(2).should("contain", "1: nodeinfo 3");
-                    cy.get("[data-cy=process-logs] pre").eq(3).should("contain", "2: nodeinfo 4");
-                    cy.get("[data-cy=process-logs] pre").eq(4).should("contain", "3: nodeinfo 5");
+                    cy.get("[data-cy=process-logs] span > p").eq(0).should("contain", "3: nodeinfo 1");
+                    cy.get("[data-cy=process-logs] span > p").eq(1).should("contain", "2: nodeinfo 2");
+                    cy.get("[data-cy=process-logs] span > p").eq(2).should("contain", "1: nodeinfo 3");
+                    cy.get("[data-cy=process-logs] span > p").eq(3).should("contain", "2: nodeinfo 4");
+                    cy.get("[data-cy=process-logs] span > p").eq(4).should("contain", "3: nodeinfo 5");
                     // Verify sorted logs
-                    cy.get("[data-cy=process-logs] pre").eq(5).should("contain", "2023-07-18T20:14:48.128642814Z first");
-                    cy.get("[data-cy=process-logs] pre").eq(6).should("contain", "2023-07-18T20:14:48.528642814Z second");
-                    cy.get("[data-cy=process-logs] pre").eq(7).should("contain", "2023-07-18T20:14:49.128642814Z third");
+                    cy.get("[data-cy=process-logs] span > p").eq(5).should("contain", "2023-07-18T20:14:48.128642814Z first");
+                    cy.get("[data-cy=process-logs] span > p").eq(6).should("contain", "2023-07-18T20:14:48.528642814Z second");
+                    cy.get("[data-cy=process-logs] span > p").eq(7).should("contain", "2023-07-18T20:14:49.128642814Z third");
                 });
             });
         });
@@ -633,16 +629,16 @@ describe("Process tests", function () {
                     cy.get("[data-cy=process-logs-filter]").click();
                     cy.get("body").contains("li", "All logs").click();
                     // Verify sorted logs
-                    cy.get("[data-cy=process-logs] pre").eq(0).should("contain", "2023-07-18T20:14:46.000000000Z A out 1");
-                    cy.get("[data-cy=process-logs] pre").eq(1).should("contain", "2023-07-18T20:14:47.000000000Z Z err 1");
-                    cy.get("[data-cy=process-logs] pre").eq(2).should("contain", "2023-07-18T20:14:48.128642814Z B err 2");
-                    cy.get("[data-cy=process-logs] pre").eq(3).should("contain", "2023-07-18T20:14:48.128642814Z C err 3");
-                    cy.get("[data-cy=process-logs] pre").eq(4).should("contain", "2023-07-18T20:14:48.128642814Z Y err 4");
-                    cy.get("[data-cy=process-logs] pre").eq(5).should("contain", "2023-07-18T20:14:48.128642814Z Z err 5");
-                    cy.get("[data-cy=process-logs] pre").eq(6).should("contain", "2023-07-18T20:14:48.128642814Z A err 6");
-                    cy.get("[data-cy=process-logs] pre").eq(7).should("contain", "2023-07-18T20:14:48.128642814Z A out 2");
-                    cy.get("[data-cy=process-logs] pre").eq(8).should("contain", "2023-07-18T20:14:48.128642814Z X out 3");
-                    cy.get("[data-cy=process-logs] pre").eq(9).should("contain", "2023-07-18T20:14:48.128642814Z A out 4");
+                    cy.get("[data-cy=process-logs] span > p").eq(0).should("contain", "2023-07-18T20:14:46.000000000Z A out 1");
+                    cy.get("[data-cy=process-logs] span > p").eq(1).should("contain", "2023-07-18T20:14:47.000000000Z Z err 1");
+                    cy.get("[data-cy=process-logs] span > p").eq(2).should("contain", "2023-07-18T20:14:48.128642814Z B err 2");
+                    cy.get("[data-cy=process-logs] span > p").eq(3).should("contain", "2023-07-18T20:14:48.128642814Z C err 3");
+                    cy.get("[data-cy=process-logs] span > p").eq(4).should("contain", "2023-07-18T20:14:48.128642814Z Y err 4");
+                    cy.get("[data-cy=process-logs] span > p").eq(5).should("contain", "2023-07-18T20:14:48.128642814Z Z err 5");
+                    cy.get("[data-cy=process-logs] span > p").eq(6).should("contain", "2023-07-18T20:14:48.128642814Z A err 6");
+                    cy.get("[data-cy=process-logs] span > p").eq(7).should("contain", "2023-07-18T20:14:48.128642814Z A out 2");
+                    cy.get("[data-cy=process-logs] span > p").eq(8).should("contain", "2023-07-18T20:14:48.128642814Z X out 3");
+                    cy.get("[data-cy=process-logs] span > p").eq(9).should("contain", "2023-07-18T20:14:48.128642814Z A out 4");
                 });
             });
         });
@@ -666,15 +662,60 @@ describe("Process tests", function () {
 
                 cy.getAll("@stdout").then(() => {
                     // Verify first 64KB and snipline
-                    cy.get("[data-cy=process-logs] pre", { timeout: 7000 })
+                    cy.get("[data-cy=process-logs] span > p", { timeout: 7000 })
                         .eq(0)
                         .should("contain", "X".repeat(63999) + "_\n" + SNIPLINE);
                     // Verify last 64KB
-                    cy.get("[data-cy=process-logs] pre")
+                    cy.get("[data-cy=process-logs] span > p")
                         .eq(1)
                         .should("contain", "_" + "X".repeat(63999));
                     // Verify none of the Os got through
-                    cy.get("[data-cy=process-logs] pre").should("not.contain", "O");
+                    cy.get("[data-cy=process-logs] span > p").should("not.contain", "O");
+                });
+            });
+        });
+
+        it("correctly break long lines when no obvious line separation exists", function () {
+            function randomString(length) {
+                const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
+                let res = '';
+                for (let i = 0; i < length; i++) {
+                    res += chars.charAt(Math.floor(Math.random() * chars.length));
+                }
+                return res;
+            }
+
+            const logLinesQty = 10;
+            const logLines = [];
+            for (let i = 0; i < logLinesQty; i++) {
+                const length = Math.floor(Math.random() * 500) + 500;
+                logLines.push(randomString(length));
+            }
+
+            createContainerRequest(activeUser, "test_container_request", "arvados/jobs", ["echo", "hello world"], false, "Committed").then(function (
+                containerRequest
+            ) {
+                cy.appendLog(adminUser.token, containerRequest.uuid, "stdout.txt", logLines).as("stdoutLogs");
+
+                cy.getAll("@stdoutLogs").then(function () {
+                    cy.loginAs(activeUser);
+                    cy.goToPath(`/processes/${containerRequest.uuid}`);
+                    // Select 'stdout' log filter
+                    cy.get("[data-cy=process-logs-filter]").click();
+                    cy.get("body").contains("li", "stdout").click();
+                    cy.get("[data-cy=process-logs] span > p")
+                        .should('have.length', logLinesQty)
+                        .each($p => {
+                            expect($p.text().length).to.be.greaterThan(499);
+
+                            // This looks like an ugly hack, but I was not able
+                            // to get [client|scroll]Width attributes through
+                            // the usual Cypress methods.
+                            const parentClientWidth = $p[0].parentElement.clientWidth;
+                            const parentScrollWidth = $p[0].parentElement.scrollWidth
+                            // Scrollbar should not be visible
+                            expect(parentClientWidth).to.be.eq(parentScrollWidth);
+                        });
                 });
             });
         });
@@ -1308,7 +1349,7 @@ describe("Process tests", function () {
             cy.getAll("@testOutputCollection").then(([testOutputCollection]) => {
                 // Add output uuid and inputs to container request
                 cy.intercept({ method: "GET", url: "**/arvados/v1/container_requests/*" }, req => {
-                    req.reply(res => {
+                    req.on('response', res => {
                         res.body.output_uuid = testOutputCollection.uuid;
                         res.body.mounts["/var/lib/cwl/cwl.input.json"] = {
                             content: testInputs.map(param => param.input).reduce((acc, val) => Object.assign(acc, val), {}),
@@ -1439,7 +1480,7 @@ describe("Process tests", function () {
 
             // Add output uuid and inputs to container request
             cy.intercept({ method: "GET", url: "**/arvados/v1/container_requests/*" }, req => {
-                req.reply(res => {
+                req.on('response', res => {
                     res.body.output_uuid = fakeOutputUUID;
                     res.body.mounts["/var/lib/cwl/cwl.input.json"] = {
                         content: {},