-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Development warning for conditionally-rendered panels (#174)
Development warning added to PanelGroup for conditionally-rendered Panel(s) that don't have 'id' and 'order' props
- Loading branch information
Showing
12 changed files
with
215 additions
and
23 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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<!DOCTYPE html> | ||
<!doctype html> | ||
<html> | ||
<html> | ||
<head> | ||
|
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
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
144 changes: 144 additions & 0 deletions
144
packages/react-resizable-panels-website/tests/DevelopmentWarnings.spec.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import { expect, test } from "@playwright/test"; | ||
import { createElement } from "react"; | ||
import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels"; | ||
|
||
import { goToUrl, updateUrl } from "./utils/url"; | ||
|
||
function createElements({ | ||
numPanels, | ||
omitIdProp = false, | ||
omitOrderProp = false, | ||
}: { | ||
numPanels: 1 | 2; | ||
omitIdProp?: boolean; | ||
omitOrderProp?: boolean; | ||
}) { | ||
const panels = [ | ||
createElement(Panel, { | ||
collapsible: true, | ||
defaultSize: numPanels === 2 ? 50 : 100, | ||
id: omitIdProp ? undefined : "left", | ||
order: omitOrderProp ? undefined : 1, | ||
}), | ||
]; | ||
|
||
if (numPanels === 2) { | ||
panels.push( | ||
createElement(PanelResizeHandle, { id: "right-handle" }), | ||
createElement(Panel, { | ||
collapsible: true, | ||
defaultSize: 50, | ||
id: omitIdProp ? undefined : "right", | ||
order: omitOrderProp ? undefined : 2, | ||
}) | ||
); | ||
} | ||
|
||
return createElement( | ||
PanelGroup, | ||
{ direction: "horizontal", id: "group" }, | ||
...panels | ||
); | ||
} | ||
|
||
test.describe("Development warnings", () => { | ||
test.describe("conditional panels", () => { | ||
test("should warning about missing id props", async ({ page }) => { | ||
await goToUrl( | ||
page, | ||
createElements({ | ||
omitIdProp: true, | ||
numPanels: 1, | ||
}) | ||
); | ||
|
||
const warnings: string[] = []; | ||
page.on("console", (message) => { | ||
if (message.type() === "warning") { | ||
warnings.push(message.text()); | ||
} | ||
}); | ||
|
||
await updateUrl( | ||
page, | ||
createElements({ | ||
omitIdProp: true, | ||
numPanels: 2, | ||
}) | ||
); | ||
expect(warnings).toHaveLength(1); | ||
expect(warnings[0]).toContain("id and order props recommended"); | ||
|
||
await updateUrl( | ||
page, | ||
createElements({ | ||
omitIdProp: true, | ||
numPanels: 1, | ||
}) | ||
); | ||
expect(warnings).toHaveLength(1); | ||
}); | ||
|
||
test("should warning about missing order props", async ({ page }) => { | ||
await goToUrl( | ||
page, | ||
createElements({ | ||
omitOrderProp: true, | ||
numPanels: 1, | ||
}) | ||
); | ||
|
||
const warnings: string[] = []; | ||
page.on("console", (message) => { | ||
if (message.type() === "warning") { | ||
warnings.push(message.text()); | ||
} | ||
}); | ||
|
||
await updateUrl( | ||
page, | ||
createElements({ | ||
omitOrderProp: true, | ||
numPanels: 2, | ||
}) | ||
); | ||
expect(warnings).toHaveLength(1); | ||
expect(warnings[0]).toContain("id and order props recommended"); | ||
|
||
await updateUrl( | ||
page, | ||
createElements({ | ||
omitOrderProp: true, | ||
numPanels: 1, | ||
}) | ||
); | ||
expect(warnings).toHaveLength(1); | ||
}); | ||
|
||
test("should not warn if id an order props are specified", async ({ | ||
page, | ||
}) => { | ||
await goToUrl( | ||
page, | ||
createElements({ | ||
numPanels: 1, | ||
}) | ||
); | ||
|
||
const warnings: string[] = []; | ||
page.on("console", (message) => { | ||
if (message.type() === "warning") { | ||
warnings.push(message.text()); | ||
} | ||
}); | ||
|
||
await updateUrl( | ||
page, | ||
createElements({ | ||
numPanels: 2, | ||
}) | ||
); | ||
expect(warnings).toHaveLength(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
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
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.
acc5362
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
react-resizable-panels – ./
react-resizable-panels-git-main-bvaughn.vercel.app
react-resizable-panels-bvaughn.vercel.app
react-resizable-panels.vercel.app