-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Solidify DisableDrop * Added Cypress * Finalize tests * Don't provide internal root id to create * Tests Pass * Update Change Log
- Loading branch information
Showing
27 changed files
with
1,421 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Version 3.0.0 | ||
|
||
## Features | ||
|
||
- Disable Edit | ||
- Disable Drop Dynamically | ||
|
||
### Disable Edit | ||
|
||
The `disableEdit` prop was added to the tree to specify nodes that cannot be edited. This also fixed a bug when pressing the keyboard shortcut "Enter" on a node that did not render a form. The tree would get stuck in the "editing" mode and could not return to the normal mode. | ||
|
||
### Disable Drop Dynamically | ||
|
||
The `disableDrop` prop now accepts a function with the arguments described below. Previously you could only provide a static list of nodes that were not droppable, but now you can determine it dynamically. | ||
|
||
## Breaking Changes | ||
|
||
### Tree Component `disableDrop` Prop | ||
|
||
If you were passing a function to the `disableDrop` prop, you'll need to update it to use the following signature: | ||
|
||
```ts | ||
declare function disableDrop(args: { | ||
dragNodes: NodeApi[]; // The nodes being dragged | ||
parentNode: NodeApi; // The new parent of the dragNodes if dropped | ||
index: number; // The new child index of the dragNodes if dropped | ||
}): boolean; | ||
``` | ||
|
||
This lets you disallow a drop based on the items being dragged and which node you are hovering over. You might notice it matches the function signature of the onMove handler. It is still possible to pass a string or a boolean to the `disableDrop` prop to prevent drops statically. | ||
|
||
### NodeApi `isDroppable` property | ||
|
||
The `.isDroppable` property has been removed from the NodeApi class. This is now determined dynamically from the tree's state. It doesn't make sense to ask an single node if it is droppable anymore. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# e2e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const { defineConfig } = require("cypress"); | ||
|
||
module.exports = defineConfig({ | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
// implement node event listeners here | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import "@4tw/cypress-drag-drop"; | ||
|
||
describe("template spec", () => { | ||
beforeEach(() => { | ||
cy.visit("http://localhost:3000/gmail"); | ||
cy.get("[role=treeitem]").as("item"); | ||
}); | ||
|
||
it("Edits The Social Node", () => { | ||
cy.get("[role=treeitem").contains("Social").click(); | ||
cy.focused().type("{enter}"); | ||
cy.focused().type("My Favorite Social Sites{enter}"); | ||
cy.get("[role=treeitem]").contains("My Favorite Social Sites"); | ||
}); | ||
|
||
it("Collapses and Expands the Categories", () => { | ||
cy.get("@item").should("have.length", "16"); | ||
cy.get("@item").contains("Categories").click(); | ||
cy.get("@item").should("have.length", "12"); | ||
cy.get("@item").contains("Categories").click(); | ||
cy.get("@item").should("have.length", "16"); | ||
}); | ||
|
||
it("Up and Down Arrows", () => { | ||
cy.get("@item").first().click(); | ||
cy.focused().type("{downArrow}"); | ||
cy.focused().should("contain.text", "Starred"); | ||
cy.focused().type("{downArrow}"); | ||
cy.focused().should("contain.text", "Snoozed"); | ||
cy.focused().type("{upArrow}{upArrow}{upArrow}{upArrow}"); | ||
cy.focused().should("contain.text", "Inbox"); | ||
}); | ||
|
||
it("Left and Right Arrows", () => { | ||
cy.get("@item").should("have.length", 16); | ||
cy.get("@item").contains("Categories").click(); | ||
cy.focused().type("{leftArrow}"); | ||
cy.get("@item").should("have.length", 12); | ||
cy.focused().type("{rightArrow}"); | ||
cy.get("@item").should("have.length", 16); | ||
cy.focused().should("contain.text", "Categories"); | ||
cy.focused().type("{rightArrow}"); | ||
cy.focused().should("contain.text", "Social"); | ||
cy.focused().type("{downArrow}"); | ||
cy.focused().type("{downArrow}"); | ||
cy.focused().should("contain.text", "Forums"); | ||
}); | ||
|
||
it("Creates Leaf Nodes", () => { | ||
// At the root level | ||
cy.get("@item").first().click(); | ||
cy.focused().type("a"); | ||
cy.focused().type("Turn A New Leaf{enter}"); | ||
cy.get("@item").should("have.length", 17); | ||
|
||
// In a Folder | ||
cy.get("@item").contains("Social").click(); | ||
cy.focused().type("a"); | ||
cy.focused().type("Turn More Leaves{enter}"); | ||
cy.get("@item").should("have.length", 18); | ||
|
||
// On a folder that is closed | ||
cy.get("@item").contains("Categories").click(); // closed it | ||
cy.focused().type("a"); | ||
cy.focused().type("Root{enter}"); | ||
cy.get("@item").contains("Root").click(); | ||
cy.focused().should("have.attr", "aria-level", "0"); | ||
|
||
// On a folder that is open | ||
cy.get("@item").contains("Categories").click(); // opened it | ||
cy.focused().type("a"); | ||
cy.focused().type("Child{enter}"); | ||
cy.get("@item").contains("Child").click(); | ||
cy.focused().should("have.attr", "aria-level", "1"); | ||
}); | ||
|
||
it("Creates Internal Nodes", () => { | ||
// At the root level | ||
cy.get("@item").first().click(); | ||
cy.focused().type("A"); | ||
cy.focused().type("Turn A New Internal{enter}"); | ||
cy.get("@item").should("have.length", 17); | ||
cy.focused().children().should("have.class", "isInternal"); | ||
|
||
// In a Folder | ||
cy.get("@item").contains("Social").click(); | ||
cy.focused().type("A"); | ||
cy.focused().type("Turn More Inernals{enter}"); | ||
cy.get("@item").should("have.length", 18); | ||
cy.focused().children().should("have.class", "isInternal"); | ||
|
||
// On a folder that is closed | ||
cy.get("@item").contains("Categories").click(); // closed it | ||
cy.focused().type("A"); | ||
cy.focused().type("Root{enter}"); | ||
cy.get("@item").contains("Root").click(); | ||
cy.focused().children().should("have.class", "isInternal"); | ||
cy.focused().should("have.attr", "aria-level", "0"); | ||
|
||
// On a folder that is open | ||
cy.get("@item").contains("Categories").click(); // opened it | ||
cy.focused().type("A"); | ||
cy.focused().type("Child{enter}"); | ||
cy.get("@item").contains("Child").click(); | ||
cy.focused().should("have.attr", "aria-level", "1"); | ||
}); | ||
|
||
it("drags and drops in its list", () => { | ||
cy.get("@item") | ||
.contains("Inbox") | ||
.drag("[role=treeitem]:nth-child(5)", "bottom"); | ||
|
||
cy.get("@item").contains("Inbox").click(); | ||
cy.focused().invoke("index").should("eq", 4); | ||
}); | ||
|
||
it("drags and drops into folder", () => { | ||
cy.get("@item").contains("Starred").drag("[role=treeitem]:nth-child(12)"); | ||
|
||
cy.get("@item").contains("Starred").click(); | ||
cy.focused().invoke("index").should("eq", 11); | ||
}); | ||
|
||
it("prevents Inbox from Dragging into Categories", () => { | ||
cy.get("@item").contains("Inbox").drag("[role=treeitem]:nth-child(12)"); | ||
cy.get("@item").contains("Inbox").click(); | ||
cy.focused().invoke("index").should("eq", 0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "Using fixtures to represent data", | ||
"email": "[email protected]", | ||
"body": "Fixtures are a great way to mock data for responses to routes" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// *********************************************** | ||
// This example commands.js shows you how to | ||
// create various custom commands and overwrite | ||
// existing commands. | ||
// | ||
// For more comprehensive examples of custom | ||
// commands please read more here: | ||
// https://on.cypress.io/custom-commands | ||
// *********************************************** | ||
// | ||
// | ||
// -- This is a parent command -- | ||
// Cypress.Commands.add('login', (email, password) => { ... }) | ||
// | ||
// | ||
// -- This is a child command -- | ||
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This is a dual command -- | ||
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This will overwrite an existing command -- | ||
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// *********************************************************** | ||
// This example support/e2e.js is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// Import commands.js using ES2015 syntax: | ||
import './commands' | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "e2e", | ||
"packageManager": "[email protected]", | ||
"dependencies": { | ||
"@4tw/cypress-drag-drop": "^2.2.3", | ||
"cypress": "^12.4.1", | ||
"cypress-drag-drop": "^1.1.1", | ||
"typescript": "^4.9.4" | ||
}, | ||
"scripts": { | ||
"test": "yarn cypress run", | ||
"open": "yarn cypress open" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"target": "es5", | ||
"lib": ["es5", "dom"], | ||
"types": ["cypress", "node"] | ||
}, | ||
"include": ["**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.