-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
className prop consistency #1950
Changes from 7 commits
35ce05b
33baa2e
d93c4f2
f11d32c
1230c05
d16d86b
853b14e
919559e
7d97b3b
6a57ebf
e1ecfcb
8666ad9
3caa3af
324372f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,9 @@ const Core = require("../dist"); | |
const tooltipContent = { content: React.createElement("h1", {}, "content") }; | ||
const customProps = { | ||
Hotkey: { combo: "mod+s", global: true, label: "save" }, | ||
Icon: { iconName: "pt-icon-build" }, | ||
KeyCombo: { combo: "?" }, | ||
Overlay: { lazy: false, inline: true }, | ||
SVGTooltip: tooltipContent, | ||
TagInput: { values: ["foo", "bar", "baz"] }, | ||
Tooltip: tooltipContent, | ||
|
@@ -29,9 +31,21 @@ const customChildren = { | |
Tooltip2: popoverTarget, | ||
}; | ||
|
||
const skipList = [ | ||
"Portal", // doesn't render any DOM inline | ||
"Tabs", // deprecated component, logs a warning | ||
] | ||
|
||
const classNameChildList = [ | ||
"Alert", | ||
"Dialog", | ||
"MenuItem", | ||
"Popover2", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
"Portal", | ||
"Toaster", | ||
"Tooltip2" | ||
] | ||
|
||
describe("Core isomorphic rendering", () => { | ||
generateIsomorphicTests(Core, customProps, customChildren, [ | ||
"Portal", // doesn't render any DOM inline | ||
"Tabs", // deprecated component, logs a warning | ||
]); | ||
generateIsomorphicTests(Core, customProps, customChildren, skipList, classNameChildList); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,23 +7,31 @@ const { generateIsomorphicTests } = require("@blueprintjs/test-commons"); | |
const React = require("react"); | ||
const Table = require("../dist"); | ||
|
||
const draggableElement = React.createElement("button"); | ||
const customChildren = { | ||
DragSelectable: draggableElement, | ||
Draggable: draggableElement, | ||
}; | ||
|
||
const customProps = { | ||
ResizeHandle: { | ||
// needs at least one handler or it returns undefined | ||
onDoubleClick: () => undefined, | ||
}, | ||
}; | ||
|
||
const classNameChildList = [ | ||
"CopyCellsMenuItem", | ||
"ResizeHandle" | ||
] | ||
|
||
const skipList = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @giladgray Classname doesn't propagate for these three components, but i'm not sure of the best way to handle these. It looks like they are just wrappers for eventHandlers, in which case maybe className doesn't need to propagate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
the other two, you're right, they're the exceptions! |
||
// Pass-through renders | ||
"DragSelectable", | ||
"Draggable", | ||
] | ||
|
||
|
||
describe("Table isomorphic rendering", () => { | ||
generateIsomorphicTests( | ||
Table, | ||
customProps, | ||
customChildren | ||
{}, | ||
skipList, | ||
classNameChildList | ||
); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
// TODO: make this an executable script that takes configuration from CLI arguments so we don't need | ||
// to use the `mocha` CLI and write an isotest.js file in every project | ||
|
||
import { assert } from "chai"; | ||
import * as Enzyme from "enzyme"; | ||
import * as Adapter from "enzyme-adapter-react-16"; | ||
import * as React from "react"; | ||
|
@@ -32,12 +33,15 @@ function isReactClass(Component: any): boolean { | |
* @param props custom props per component | ||
* @param children custom children per component | ||
* @param skipList array of component names to skip | ||
* @param classNameChildList array of component names for which className is legitimately passed down to | ||
* child element | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
*/ | ||
export function generateIsomorphicTests( | ||
Components: { [name: string]: any }, | ||
props: { [name: string]: any }, | ||
children: { [name: string]: React.ReactNode }, | ||
skipList: string[] = [], | ||
classNameChildList: string[] = [], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to document this new param in the function comment above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
) { | ||
Object.keys(Components) | ||
.sort() | ||
|
@@ -54,6 +58,21 @@ export function generateIsomorphicTests( | |
// errors will fail the test and log full stack traces to the console. nifty! | ||
Enzyme.render(element); | ||
}); | ||
it(`<${componentName}> className is applied to outer element`, () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test name is not always accurate... might want to do the |
||
const element = React.createElement( | ||
Component, | ||
{ | ||
...props[componentName], | ||
className: "test", | ||
}, | ||
children[componentName], | ||
); | ||
if (classNameChildList.includes(componentName)) { | ||
assert.isAtLeast(Enzyme.shallow(element).find(".test").length, 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❌ |
||
} else { | ||
assert.isTrue(Enzyme.render(element).hasClass("test")); | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
|
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.
why do we need this?
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.
we don't strictly need it and it's probably safe to remove. shall i do that?