From 4e3cb5b9b070305b5253b6b438f7f39c6469a318 Mon Sep 17 00:00:00 2001 From: Gilad Gray Date: Thu, 1 Nov 2018 14:04:55 -0700 Subject: [PATCH] refactor isotest suites to new config object --- packages/core/test/isotest.js | 79 ++++++++++++++++++++++--------- packages/datetime/test/isotest.js | 7 ++- packages/icons/test/isotest.js | 6 +-- packages/select/test/isotest.js | 52 +++++++++----------- packages/table/test/isotest.js | 24 +++------- packages/timezone/test/isotest.js | 9 +--- 6 files changed, 91 insertions(+), 86 deletions(-) diff --git a/packages/core/test/isotest.js b/packages/core/test/isotest.js index f83abba3a1..a3b8155c90 100644 --- a/packages/core/test/isotest.js +++ b/packages/core/test/isotest.js @@ -8,29 +8,64 @@ const { generateIsomorphicTests } = require("@blueprintjs/test-commons"); const React = require("react"); const Core = require("../lib/cjs"); -const tooltipContent = { content: React.createElement("h1", {}, "content") }; -const customProps = { - Hotkey: { combo: "mod+s", global: true, label: "save" }, - Icon: { iconName: "build" }, - KeyCombo: { combo: "?" }, - OverflowList: { items: [], overflowRenderer: () => null, visibleItemRenderer: () => null }, - Overlay: { lazy: false, usePortal: false }, - PanelStack: { initialPanel: { component: () => null, props: {}, title: "" } }, - TagInput: { values: ["foo", "bar", "baz"] }, - Tooltip: tooltipContent, - Toaster: { usePortal: false }, -}; - const requiredChild = React.createElement("button"); -const customChildren = { - Hotkeys: React.createElement(Core.Hotkey, customProps.Hotkey), - Popover: requiredChild, - ResizeSensor: requiredChild, - Tabs: React.createElement(Core.Tab, { key: 1, id: 1, title: "Tab one" }), - Tooltip: requiredChild, - Toaster: React.createElement(Core.Toast, { message: "Toast" }), -}; +const hotkeyProps = { combo: "mod+s", global: true, label: "save" }; describe("Core isomorphic rendering", () => { - generateIsomorphicTests(Core, customProps, customChildren); + generateIsomorphicTests(Core, { + Alert: { + props: { isOpen: true, usePortal: false }, + }, + Dialog: { + props: { isOpen: true, usePortal: false }, + }, + Hotkey: { + props: hotkeyProps, + }, + Hotkeys: { + children: React.createElement(Core.Hotkey, hotkeyProps), + }, + Icon: { + props: { icon: "build" }, + }, + KeyCombo: { + props: { combo: "?" }, + }, + OverflowList: { + props: { items: [], overflowRenderer: () => null, visibleItemRenderer: () => null }, + }, + Overlay: { + props: { lazy: false, usePortal: false }, + }, + PanelStack: { + props: { + initialPanel: { component: () => null, props: {}, title: "" } + }, + children: "" + }, + Portal: { + className: false, // only renders in browser (`document`) + }, + Popover: { + children: requiredChild, + }, + ResizeSensor: { + children: requiredChild, + className: false, + }, + Tabs: { + children: React.createElement(Core.Tab, { key: 1, id: 1, title: "Tab one" }), + }, + TagInput: { + props: { values: ["foo", "bar", "baz"] }, + }, + Tooltip: { + props: { content: React.createElement("h1", {}, "content") }, + children: requiredChild + }, + Toaster: { + props: { usePortal: false }, + children: React.createElement(Core.Toast, { message: "Toast" }) + }, + }); }); diff --git a/packages/datetime/test/isotest.js b/packages/datetime/test/isotest.js index e5618f6a6c..6d3922a524 100644 --- a/packages/datetime/test/isotest.js +++ b/packages/datetime/test/isotest.js @@ -17,9 +17,8 @@ describe("DateTime isomorphic rendering", () => { generateIsomorphicTests( DateTime, { - "DateInput": formatProps, - "DateRangeInput": formatProps, - }, - {} + DateInput: { props: formatProps }, + DateRangeInput: { props: formatProps }, + } ); }); diff --git a/packages/icons/test/isotest.js b/packages/icons/test/isotest.js index 0e8764198b..fd2e05c811 100644 --- a/packages/icons/test/isotest.js +++ b/packages/icons/test/isotest.js @@ -9,9 +9,5 @@ const React = require("react"); const Icons = require("../lib/cjs"); describe("Icons isomorphic rendering", () => { - generateIsomorphicTests( - Icons, - {}, - {} - ); + generateIsomorphicTests(Icons); }); diff --git a/packages/select/test/isotest.js b/packages/select/test/isotest.js index f376cdebf9..af77f22919 100644 --- a/packages/select/test/isotest.js +++ b/packages/select/test/isotest.js @@ -8,35 +8,27 @@ const { generateIsomorphicTests } = require("@blueprintjs/test-commons"); const React = require("react"); const Select = require("../lib/cjs"); -const customChildren = { -}; - -const customProps = { - MultiSelect: { - items: [], - query: "", - selectedItems: [], - tagRenderer: () => null, - }, - QueryList: { - // needs at least one handler or it returns undefined - renderer: () => null - }, - Select: { - items: [], - }, - Suggest: { - items: [], - }, - Omnibar: { - items: [], - } -}; - -const skipList = [ - "QueryList", // doesn't render any DOM itself -] - describe("Select isomorphic rendering", () => { - generateIsomorphicTests(Select, customProps, customChildren, skipList); + generateIsomorphicTests(Select, { + MultiSelect: { + props: { items: [], query: "", selectedItems: [], tagRenderer: () => null }, + }, + QueryList: { + // needs at least one handler or it returns undefined + props: { renderer: () => null }, + skip: true, + }, + Select: { + props: { items: [] }, + }, + Suggest: { + props: { items: [] }, + }, + Omnibar: { + props: { items: [], isOpen: true, overlayProps: { usePortal: false } }, + }, + QueryList: { + skip: true, + } + }); }); diff --git a/packages/table/test/isotest.js b/packages/table/test/isotest.js index 99d00b8790..95df9d6b7e 100644 --- a/packages/table/test/isotest.js +++ b/packages/table/test/isotest.js @@ -8,25 +8,15 @@ const { generateIsomorphicTests } = require("@blueprintjs/test-commons"); const React = require("react"); const Table = require("../lib/cjs"); -const customProps = { - ResizeHandle: { - // needs at least one handler or it returns undefined - onDoubleClick: () => undefined, - }, -}; - -const skipList = [ - // Pass-through renders - "DragSelectable", - "Draggable", -] - - describe("Table isomorphic rendering", () => { generateIsomorphicTests( Table, - customProps, - {}, - skipList + { + // Pass-through renders + DragSelectable: { skip: true }, + Draggable: { skip: true }, + // needs at least one handler or it returns undefined + ResizeHandle: { props: { onDoubleClick: () => undefined } }, + } ); }); diff --git a/packages/timezone/test/isotest.js b/packages/timezone/test/isotest.js index 1a48a7b24f..846d0612bb 100644 --- a/packages/timezone/test/isotest.js +++ b/packages/timezone/test/isotest.js @@ -8,13 +8,6 @@ const { generateIsomorphicTests } = require("@blueprintjs/test-commons"); const React = require("react"); const Timezone = require("../lib/cjs"); -const skipList = [] - describe("Timezone isomorphic rendering", () => { - generateIsomorphicTests( - Timezone, - {}, - {}, - skipList - ); + generateIsomorphicTests(Timezone); });