|
| 1 | +import "@4tw/cypress-drag-drop"; |
| 2 | + |
| 3 | +describe("template spec", () => { |
| 4 | + beforeEach(() => { |
| 5 | + cy.visit("http://localhost:3000/gmail"); |
| 6 | + cy.get("[role=treeitem]").as("item"); |
| 7 | + }); |
| 8 | + |
| 9 | + it("Edits The Social Node", () => { |
| 10 | + cy.get("[role=treeitem").contains("Social").click(); |
| 11 | + cy.focused().type("{enter}"); |
| 12 | + cy.focused().type("My Favorite Social Sites{enter}"); |
| 13 | + cy.get("[role=treeitem]").contains("My Favorite Social Sites"); |
| 14 | + }); |
| 15 | + |
| 16 | + it("Collapses and Expands the Categories", () => { |
| 17 | + cy.get("@item").should("have.length", "16"); |
| 18 | + cy.get("@item").contains("Categories").click(); |
| 19 | + cy.get("@item").should("have.length", "12"); |
| 20 | + cy.get("@item").contains("Categories").click(); |
| 21 | + cy.get("@item").should("have.length", "16"); |
| 22 | + }); |
| 23 | + |
| 24 | + it("Up and Down Arrows", () => { |
| 25 | + cy.get("@item").first().click(); |
| 26 | + cy.focused().type("{downArrow}"); |
| 27 | + cy.focused().should("contain.text", "Starred"); |
| 28 | + cy.focused().type("{downArrow}"); |
| 29 | + cy.focused().should("contain.text", "Snoozed"); |
| 30 | + cy.focused().type("{upArrow}{upArrow}{upArrow}{upArrow}"); |
| 31 | + cy.focused().should("contain.text", "Inbox"); |
| 32 | + }); |
| 33 | + |
| 34 | + it("Left and Right Arrows", () => { |
| 35 | + cy.get("@item").should("have.length", 16); |
| 36 | + cy.get("@item").contains("Categories").click(); |
| 37 | + cy.focused().type("{leftArrow}"); |
| 38 | + cy.get("@item").should("have.length", 12); |
| 39 | + cy.focused().type("{rightArrow}"); |
| 40 | + cy.get("@item").should("have.length", 16); |
| 41 | + cy.focused().should("contain.text", "Categories"); |
| 42 | + cy.focused().type("{rightArrow}"); |
| 43 | + cy.focused().should("contain.text", "Social"); |
| 44 | + cy.focused().type("{downArrow}"); |
| 45 | + cy.focused().type("{downArrow}"); |
| 46 | + cy.focused().should("contain.text", "Forums"); |
| 47 | + }); |
| 48 | + |
| 49 | + it("Creates Leaf Nodes", () => { |
| 50 | + // At the root level |
| 51 | + cy.get("@item").first().click(); |
| 52 | + cy.focused().type("a"); |
| 53 | + cy.focused().type("Turn A New Leaf{enter}"); |
| 54 | + cy.get("@item").should("have.length", 17); |
| 55 | + |
| 56 | + // In a Folder |
| 57 | + cy.get("@item").contains("Social").click(); |
| 58 | + cy.focused().type("a"); |
| 59 | + cy.focused().type("Turn More Leaves{enter}"); |
| 60 | + cy.get("@item").should("have.length", 18); |
| 61 | + |
| 62 | + // On a folder that is closed |
| 63 | + cy.get("@item").contains("Categories").click(); // closed it |
| 64 | + cy.focused().type("a"); |
| 65 | + cy.focused().type("Root{enter}"); |
| 66 | + cy.get("@item").contains("Root").click(); |
| 67 | + cy.focused().should("have.attr", "aria-level", "0"); |
| 68 | + |
| 69 | + // On a folder that is open |
| 70 | + cy.get("@item").contains("Categories").click(); // opened it |
| 71 | + cy.focused().type("a"); |
| 72 | + cy.focused().type("Child{enter}"); |
| 73 | + cy.get("@item").contains("Child").click(); |
| 74 | + cy.focused().should("have.attr", "aria-level", "1"); |
| 75 | + }); |
| 76 | + |
| 77 | + it("Creates Internal Nodes", () => { |
| 78 | + // At the root level |
| 79 | + cy.get("@item").first().click(); |
| 80 | + cy.focused().type("A"); |
| 81 | + cy.focused().type("Turn A New Internal{enter}"); |
| 82 | + cy.get("@item").should("have.length", 17); |
| 83 | + cy.focused().children().should("have.class", "isInternal"); |
| 84 | + |
| 85 | + // In a Folder |
| 86 | + cy.get("@item").contains("Social").click(); |
| 87 | + cy.focused().type("A"); |
| 88 | + cy.focused().type("Turn More Inernals{enter}"); |
| 89 | + cy.get("@item").should("have.length", 18); |
| 90 | + cy.focused().children().should("have.class", "isInternal"); |
| 91 | + |
| 92 | + // On a folder that is closed |
| 93 | + cy.get("@item").contains("Categories").click(); // closed it |
| 94 | + cy.focused().type("A"); |
| 95 | + cy.focused().type("Root{enter}"); |
| 96 | + cy.get("@item").contains("Root").click(); |
| 97 | + cy.focused().children().should("have.class", "isInternal"); |
| 98 | + cy.focused().should("have.attr", "aria-level", "0"); |
| 99 | + |
| 100 | + // On a folder that is open |
| 101 | + cy.get("@item").contains("Categories").click(); // opened it |
| 102 | + cy.focused().type("A"); |
| 103 | + cy.focused().type("Child{enter}"); |
| 104 | + cy.get("@item").contains("Child").click(); |
| 105 | + cy.focused().should("have.attr", "aria-level", "1"); |
| 106 | + }); |
| 107 | + |
| 108 | + it("drags and drops in its list", () => { |
| 109 | + cy.get("@item") |
| 110 | + .contains("Inbox") |
| 111 | + .drag("[role=treeitem]:nth-child(5)", "bottom"); |
| 112 | + |
| 113 | + cy.get("@item").contains("Inbox").click(); |
| 114 | + cy.focused().invoke("index").should("eq", 4); |
| 115 | + }); |
| 116 | + |
| 117 | + it("drags and drops into folder", () => { |
| 118 | + cy.get("@item").contains("Starred").drag("[role=treeitem]:nth-child(12)"); |
| 119 | + |
| 120 | + cy.get("@item").contains("Starred").click(); |
| 121 | + cy.focused().invoke("index").should("eq", 11); |
| 122 | + }); |
| 123 | + |
| 124 | + it("prevents Inbox from Dragging into Categories", () => { |
| 125 | + cy.get("@item").contains("Inbox").drag("[role=treeitem]:nth-child(12)"); |
| 126 | + cy.get("@item").contains("Inbox").click(); |
| 127 | + cy.focused().invoke("index").should("eq", 0); |
| 128 | + }); |
| 129 | +}); |
0 commit comments