|
| 1 | +/// <reference types="cypress" /> |
| 2 | +/// <reference path="support/index.d.ts" /> |
| 3 | + |
| 4 | +import { |
| 5 | + setupJobMonitorDashboard, |
| 6 | + ensureMinimumJobs, |
| 7 | +} from "./support/jobMonitorUtils"; |
| 8 | + |
| 9 | +describe("Job Monitor - Columns", () => { |
| 10 | + beforeEach(() => { |
| 11 | + cy.login(); |
| 12 | + |
| 13 | + cy.visit("/"); |
| 14 | + setupJobMonitorDashboard(); |
| 15 | + |
| 16 | + cy.contains("Job Monitor").click(); |
| 17 | + |
| 18 | + ensureMinimumJobs(55); |
| 19 | + }); |
| 20 | + |
| 21 | + it("should hide/show columns", () => { |
| 22 | + // Make sure "VO" is not in the header and "Status" is |
| 23 | + cy.get("table thead tr th").should("not.contain", "VO"); |
| 24 | + cy.get("table thead tr th").should("contain", "Status"); |
| 25 | + |
| 26 | + // Click on the visibility icon |
| 27 | + cy.get('[data-testid="column-visibility-button"]').click(); |
| 28 | + cy.get('[data-testid="column-visibility-popover"]').should("be.visible"); |
| 29 | + |
| 30 | + // Hide the "Site" column and Show the "VO" column |
| 31 | + cy.get('[data-testid="column-visibility-popover"]') |
| 32 | + .contains("Site") |
| 33 | + .parent() |
| 34 | + .find('input[type="checkbox"]') |
| 35 | + .click(); |
| 36 | + cy.get('[data-testid="column-visibility-popover"]') |
| 37 | + .contains("VO") |
| 38 | + .parent() |
| 39 | + .find('input[type="checkbox"]') |
| 40 | + .click(); |
| 41 | + |
| 42 | + // Close the popover by clicking outside |
| 43 | + cy.get("body").click(0, 0); |
| 44 | + cy.get('[data-testid="column-visibility-popover"]').should("not.exist"); |
| 45 | + |
| 46 | + // Wait for the table to re-render with updated columns |
| 47 | + cy.wait(1000); |
| 48 | + |
| 49 | + // Verify "VO" is now present and "Site" is gone |
| 50 | + cy.get("table thead tr th").should("contain", "VO"); |
| 51 | + cy.get("table thead tr th").should("not.contain", "Site"); |
| 52 | + }); |
| 53 | + |
| 54 | + it("should resize a column", () => { |
| 55 | + cy.get("table thead tr th") |
| 56 | + .eq(2) |
| 57 | + .invoke("width") |
| 58 | + .then((initialWidth) => { |
| 59 | + // Convert the width to a number |
| 60 | + const initialWidthNum = Number(initialWidth); |
| 61 | + |
| 62 | + // Resize the column |
| 63 | + cy.get( |
| 64 | + ".MuiTableHead-root > .MuiTableRow-root > :nth-child(3) > .MuiBox-root", |
| 65 | + ) |
| 66 | + .trigger("mousedown", { which: 1 }) // Start the drag |
| 67 | + .trigger("mousemove", { clientX: 200 }) // Move to the desired location |
| 68 | + .trigger("mouseup"); // Release to finish resizing |
| 69 | + |
| 70 | + // Check if the column width has changed (it should be larger than the initial width) |
| 71 | + cy.get("table thead tr th") |
| 72 | + .eq(2) |
| 73 | + .invoke("width") |
| 74 | + .then((newWidth) => { |
| 75 | + // Convert the new width to a number and compare |
| 76 | + const newWidthNum = Number(newWidth); |
| 77 | + expect(initialWidthNum).to.be.greaterThan(newWidthNum); |
| 78 | + }); |
| 79 | + }); |
| 80 | + }); |
| 81 | + |
| 82 | + it("should sort column", () => { |
| 83 | + let firstValue: number; |
| 84 | + let firstValueSorted: number; |
| 85 | + let firstValueAgain: number; |
| 86 | + |
| 87 | + // Get the first visible row value (e.g. 55) |
| 88 | + cy.get("table tbody tr") |
| 89 | + .first() |
| 90 | + .find("td") |
| 91 | + .eq(1) |
| 92 | + .invoke("text") |
| 93 | + .then((text) => { |
| 94 | + firstValue = parseInt(text.trim(), 10); |
| 95 | + }); |
| 96 | + |
| 97 | + cy.get('[data-testid="sort-JobID"]').click(); |
| 98 | + |
| 99 | + cy.get("table tbody tr") |
| 100 | + .first() |
| 101 | + .find("td") |
| 102 | + .eq(1) |
| 103 | + .invoke("text") |
| 104 | + .then((text) => { |
| 105 | + firstValueSorted = parseInt(text.trim(), 10); |
| 106 | + expect(firstValue).to.be.greaterThan(firstValueSorted); |
| 107 | + }); |
| 108 | + |
| 109 | + cy.get('[data-testid="sort-JobID"]').click(); |
| 110 | + |
| 111 | + cy.get("table tbody tr") |
| 112 | + .first() |
| 113 | + .find("td") |
| 114 | + .eq(1) |
| 115 | + .invoke("text") |
| 116 | + .then((text) => { |
| 117 | + firstValueAgain = parseInt(text.trim(), 10); |
| 118 | + expect(firstValueAgain).to.be.greaterThan(firstValueSorted); |
| 119 | + expect(firstValue).to.be.equal(firstValueAgain); |
| 120 | + }); |
| 121 | + }); |
| 122 | +}); |
0 commit comments