|
| 1 | +describe("Homepage", () => { |
| 2 | + beforeEach(() => { |
| 3 | + cy.visit("/"); |
| 4 | + }); |
| 5 | + |
| 6 | + it("should have all inputs present and in the correct initial state", () => { |
| 7 | + // Test inputs are present and valid |
| 8 | + cy.get("[data-cy=dockerignore-input] > textarea") |
| 9 | + .should("exist") |
| 10 | + .and("be.enabled"); |
| 11 | + cy.get("[data-cy=dockerignore-input] > label") |
| 12 | + .should("exist") |
| 13 | + .and("have.text", ".dockerignore"); |
| 14 | + |
| 15 | + cy.get("[data-cy=files-input] > textarea") |
| 16 | + .should("exist") |
| 17 | + .and("be.enabled"); |
| 18 | + cy.get("[data-cy=files-input] > label") |
| 19 | + .should("exist") |
| 20 | + .and("have.text", "Files"); |
| 21 | + |
| 22 | + cy.get("[data-cy=options] > input[name=showIgnored]") |
| 23 | + .should("exist") |
| 24 | + .and("be.checked"); |
| 25 | + |
| 26 | + cy.get("[data-cy=validate-button]").should("exist").and("be.enabled"); |
| 27 | + |
| 28 | + // Test output is present and in the correct state |
| 29 | + cy.get("[data-cy=result-output] > textarea") |
| 30 | + .should("exist") |
| 31 | + .and("be.disabled"); |
| 32 | + cy.get("[data-cy=result-output] > label") |
| 33 | + .should("exist") |
| 34 | + .and("have.text", "Ignored Files"); |
| 35 | + }); |
| 36 | + |
| 37 | + it("should allow form submission with correct ", () => { |
| 38 | + const dockerignore = "node_modules"; |
| 39 | + const files = "node_modules\npackage.json"; |
| 40 | + |
| 41 | + // Output text with "Show ignored files" checked |
| 42 | + const expectedIgnoredOutput = "node_modules"; |
| 43 | + // Output text with "Show ignored files" unchecked |
| 44 | + const expectedCopyFilesOutput = "package.json"; |
| 45 | + // API Response |
| 46 | + const expectedRes = [true, false]; |
| 47 | + |
| 48 | + // Ensure the correct data is being sent and received |
| 49 | + cy.intercept("POST", "/api/validate", (req) => { |
| 50 | + expect(JSON.parse(req.body)).to.deep.equal({ |
| 51 | + dockerignore: ["node_modules"], |
| 52 | + files: ["node_modules", "package.json"], |
| 53 | + }); |
| 54 | + req.continue((res) => { |
| 55 | + expect(res.statusCode).to.equal(200); |
| 56 | + expect(res.body).to.deep.equal(expectedRes); |
| 57 | + }); |
| 58 | + }).as("validate"); |
| 59 | + |
| 60 | + cy.get("[data-cy=dockerignore-input] > textarea").type(dockerignore); |
| 61 | + cy.get("[data-cy=files-input] > textarea").type(files); |
| 62 | + |
| 63 | + // Ensure the output is empty and the loading state is not present |
| 64 | + cy.get("[data-cy=result-output] > textarea").should("be.empty"); |
| 65 | + cy.get("[data-cy=textarea-loading]").should("not.exist"); |
| 66 | + |
| 67 | + // Once clicked, the result should be replaced with a loading state |
| 68 | + cy.get("[data-cy=validate-button]").click(); |
| 69 | + cy.get("[data-cy=result-output]").should("not.exist"); |
| 70 | + cy.get("[data-cy=textarea-loading]").should("exist"); |
| 71 | + cy.get("[data-cy=textarea-loading] > label").should( |
| 72 | + "have.text", |
| 73 | + "Matching patterns..." |
| 74 | + ); |
| 75 | + |
| 76 | + cy.wait("@validate"); |
| 77 | + |
| 78 | + // Loading state should be removed and the result should be present |
| 79 | + cy.get("[data-cy=textarea-loading]").should("not.exist"); |
| 80 | + cy.get("[data-cy=result-output]").should("exist"); |
| 81 | + |
| 82 | + // Ensure the result has the correct output for both checked |
| 83 | + // and unchecked states of "Show ignored files" |
| 84 | + cy.get("[data-cy=result-output] > textarea").should( |
| 85 | + "have.text", |
| 86 | + expectedIgnoredOutput |
| 87 | + ); |
| 88 | + |
| 89 | + cy.get("[data-cy=options] > input[name=showIgnored]").uncheck(); |
| 90 | + cy.get("[data-cy=result-output] > label").should( |
| 91 | + "have.text", |
| 92 | + "Files to Copy" |
| 93 | + ); |
| 94 | + cy.get("[data-cy=result-output] > textarea").should( |
| 95 | + "have.text", |
| 96 | + expectedCopyFilesOutput |
| 97 | + ); |
| 98 | + }); |
| 99 | +}); |
0 commit comments