orc-shared 5.10.2-dev.4 → 5.99.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/dist/components/AppFrame/About.js +13 -13
  2. package/dist/components/AppFrame/Anchor.js +7 -7
  3. package/dist/components/AppFrame/AppFrame.js +3 -3
  4. package/dist/components/AppFrame/Help.js +4 -4
  5. package/dist/components/AppFrame/MenuItem.js +17 -26
  6. package/dist/components/AppFrame/Preferences.js +14 -14
  7. package/dist/components/AppFrame/Sidebar.js +6 -6
  8. package/dist/components/AppFrame/Topbar.js +6 -6
  9. package/dist/components/ApplicationModuleLoader.js +3 -2
  10. package/dist/components/Authenticate.js +29 -22
  11. package/dist/components/DropMenu/Menu.js +9 -9
  12. package/dist/components/ErrorPlaceholder.js +8 -24
  13. package/dist/components/Form/Field.js +4 -4
  14. package/dist/components/Form/Inputs/Button.js +2 -2
  15. package/dist/components/{IconButton.js → Form/Inputs/MultiSelector.js} +33 -31
  16. package/dist/components/Form/Inputs/index.js +1 -1
  17. package/dist/components/InternetExplorerWarningMessage.js +15 -15
  18. package/dist/components/LoadingIcon.js +38 -17
  19. package/dist/components/MaterialUI/DataDisplay/Modal.js +3 -3
  20. package/dist/components/MaterialUI/DataDisplay/PredefinedElements/Placeholder.js +6 -6
  21. package/dist/components/MaterialUI/DataDisplay/PredefinedElements/StepperModal.js +4 -4
  22. package/dist/components/MaterialUI/DataDisplay/SelectionList.js +1 -1
  23. package/dist/components/MaterialUI/DataDisplay/Table.js +2 -1
  24. package/dist/components/MaterialUI/DataDisplay/TableProps.js +3 -1
  25. package/dist/components/MaterialUI/DataDisplay/TransferList.js +1 -1
  26. package/dist/components/MaterialUI/Inputs/CheckboxGroup.js +1 -1
  27. package/dist/components/MaterialUI/Inputs/DatePicker.js +1 -1
  28. package/dist/components/MaterialUI/Inputs/InputBase.js +20 -188
  29. package/dist/components/MaterialUI/Inputs/PredefinedElements/SearchControl.js +1 -1
  30. package/dist/components/MaterialUI/Inputs/Select.js +10 -0
  31. package/dist/components/MaterialUI/Inputs/SelectProps.js +3 -1
  32. package/dist/components/MaterialUI/Inputs/Switch.js +1 -1
  33. package/dist/components/MaterialUI/Navigation/DropDownMenu.js +2 -4
  34. package/dist/components/MaterialUI/ScopeSelector/ScopeSelector.js +1 -1
  35. package/dist/components/MaterialUI/ScopeSelector/TreeItem.js +27 -42
  36. package/dist/components/MaterialUI/Surfaces/Paper.js +1 -1
  37. package/dist/components/MaterialUI/Surfaces/SectionExpansionPanel.js +3 -2
  38. package/dist/components/MaterialUI/muiThemes.js +2 -0
  39. package/dist/components/Provision.js +30 -13
  40. package/dist/components/Routing/SegmentPage.js +115 -56
  41. package/dist/components/Scope/ScopeNode.js +62 -57
  42. package/dist/components/Sidepanel.js +59 -23
  43. package/dist/components/Spritesheet.js +35 -17
  44. package/dist/components/Text.js +1 -60
  45. package/dist/components/ToastList.js +95 -64
  46. package/dist/components/Treeview/Branch.js +82 -20
  47. package/dist/components/Treeview/Label.js +108 -31
  48. package/dist/components/Treeview/Leaf.js +56 -12
  49. package/dist/components/Treeview/Node.js +22 -9
  50. package/dist/components/Treeview/index.js +7 -1
  51. package/dist/components/Treeview/settings.js +17 -6
  52. package/dist/utils/index.js +0 -4
  53. package/dist/utils/testUtils.js +1 -12
  54. package/dist/{components/Modal/Background.js → utils/toastHelper.js} +11 -14
  55. package/package.json +2 -2
  56. package/src/components/AppFrame/About.js +13 -13
  57. package/src/components/AppFrame/Anchor.js +7 -7
  58. package/src/components/AppFrame/AppFrame.js +3 -3
  59. package/src/components/AppFrame/Help.js +4 -4
  60. package/src/components/AppFrame/MenuItem.js +15 -23
  61. package/src/components/AppFrame/Preferences.js +14 -14
  62. package/src/components/AppFrame/Sidebar.js +6 -6
  63. package/src/components/AppFrame/Topbar.js +6 -6
  64. package/src/components/ApplicationModuleLoader.js +2 -2
  65. package/src/components/ApplicationModuleLoader.test.js +15 -28
  66. package/src/components/Authenticate.js +21 -23
  67. package/src/components/Authenticate.test.js +19 -27
  68. package/src/components/DropMenu/Menu.js +9 -9
  69. package/src/components/ErrorPlaceholder.js +4 -21
  70. package/src/components/ErrorPlaceholder.test.js +7 -14
  71. package/src/components/Form/Field.js +4 -4
  72. package/src/components/Form/InputField.test.js +2 -1
  73. package/src/components/Form/Inputs/Button.js +2 -2
  74. package/src/components/Form/Inputs/MultiSelector.js +23 -0
  75. package/src/components/Form/Inputs/MultiSelector.test.js +112 -0
  76. package/src/components/Form/Inputs/index.js +1 -1
  77. package/src/components/InternetExplorerWarningMessage.js +15 -15
  78. package/src/components/Loader.test.js +50 -59
  79. package/src/components/LoadingIcon.js +27 -14
  80. package/src/components/LoadingIcon.test.js +11 -15
  81. package/src/components/MaterialUI/DataDisplay/Modal.js +3 -3
  82. package/src/components/MaterialUI/DataDisplay/PredefinedElements/Placeholder.js +6 -6
  83. package/src/components/MaterialUI/DataDisplay/PredefinedElements/StepperModal.js +3 -3
  84. package/src/components/MaterialUI/DataDisplay/PredefinedElements/StepperModal.test.js +0 -74
  85. package/src/components/MaterialUI/DataDisplay/PredefinedElements/Translations.test.js +6 -18
  86. package/src/components/MaterialUI/DataDisplay/SelectionList.js +1 -1
  87. package/src/components/MaterialUI/DataDisplay/Table.js +6 -1
  88. package/src/components/MaterialUI/DataDisplay/Table.test.js +21 -1
  89. package/src/components/MaterialUI/DataDisplay/TableProps.js +2 -0
  90. package/src/components/MaterialUI/DataDisplay/TableProps.test.js +20 -2
  91. package/src/components/MaterialUI/DataDisplay/TransferList.js +1 -1
  92. package/src/components/MaterialUI/Inputs/CheckboxGroup.js +1 -1
  93. package/src/components/MaterialUI/Inputs/DatePicker.js +1 -1
  94. package/src/components/MaterialUI/Inputs/InputBase.js +31 -214
  95. package/src/components/MaterialUI/Inputs/InputBase.test.js +1 -460
  96. package/src/components/MaterialUI/Inputs/PredefinedElements/SearchControl.js +1 -1
  97. package/src/components/MaterialUI/Inputs/PredefinedElements/SearchControl.test.js +1 -1
  98. package/src/components/MaterialUI/Inputs/Select.js +7 -0
  99. package/src/components/MaterialUI/Inputs/Select.test.js +45 -0
  100. package/src/components/MaterialUI/Inputs/SelectProps.js +2 -0
  101. package/src/components/MaterialUI/Inputs/SelectProps.test.js +2 -0
  102. package/src/components/MaterialUI/Inputs/Switch.js +1 -1
  103. package/src/components/MaterialUI/Navigation/DropDownMenu.js +2 -2
  104. package/src/components/MaterialUI/Navigation/DropDownMenu.test.js +5 -6
  105. package/src/components/MaterialUI/ScopeSelector/ScopeSelector.js +1 -2
  106. package/src/components/MaterialUI/ScopeSelector/TreeItem.js +8 -31
  107. package/src/components/MaterialUI/Surfaces/Paper.js +1 -1
  108. package/src/components/MaterialUI/Surfaces/SectionExpansionPanel.js +2 -1
  109. package/src/components/MaterialUI/muiThemes.js +3 -0
  110. package/src/components/Navigation/Navigation.test.js +0 -5
  111. package/src/components/Navigation/useNavigationState.test.js +79 -222
  112. package/src/components/Provision.js +36 -42
  113. package/src/components/Provision.test.js +10 -26
  114. package/src/components/Routing/SegmentPage.js +68 -52
  115. package/src/components/Routing/SegmentPage.test.js +4 -12
  116. package/src/components/Scope/ScopeNode.js +44 -55
  117. package/src/components/Scope/ScopeNode.test.js +84 -163
  118. package/src/components/ScopeExtendedConfigurationLoader.test.js +1 -4
  119. package/src/components/Sidepanel.js +38 -32
  120. package/src/components/Sidepanel.test.js +54 -27
  121. package/src/components/Spritesheet.js +23 -21
  122. package/src/components/Spritesheet.test.js +10 -10
  123. package/src/components/Text.js +0 -49
  124. package/src/components/ToastList.js +79 -90
  125. package/src/components/ToastList.test.js +29 -103
  126. package/src/components/Treeview/Branch.js +65 -47
  127. package/src/components/Treeview/Branch.test.js +2 -43
  128. package/src/components/Treeview/Label.js +68 -54
  129. package/src/components/Treeview/Label.test.js +55 -63
  130. package/src/components/Treeview/Leaf.js +41 -22
  131. package/src/components/Treeview/Leaf.test.js +1 -15
  132. package/src/components/Treeview/Node.js +16 -9
  133. package/src/components/Treeview/Node.test.js +269 -200
  134. package/src/components/Treeview/Treeview.test.js +248 -248
  135. package/src/components/Treeview/index.js +6 -0
  136. package/src/components/Treeview/settings.js +10 -6
  137. package/src/utils/index.js +0 -4
  138. package/src/utils/testUtils.js +0 -10
  139. package/src/utils/testUtils.test.js +0 -68
  140. package/src/utils/toastHelper.js +8 -0
  141. package/src/utils/toastHelper.test.js +41 -0
  142. package/dist/components/Button.js +0 -70
  143. package/dist/components/CategoryList.js +0 -197
  144. package/dist/components/Checkbox.js +0 -103
  145. package/dist/components/Icon.js +0 -69
  146. package/dist/components/Input.js +0 -101
  147. package/dist/components/List/DataCell.js +0 -129
  148. package/dist/components/List/HeadCell.js +0 -125
  149. package/dist/components/List/HeadRow.js +0 -73
  150. package/dist/components/List/List.js +0 -274
  151. package/dist/components/List/Row.js +0 -109
  152. package/dist/components/List/enhanceColumnDefs.js +0 -111
  153. package/dist/components/List/index.js +0 -59
  154. package/dist/components/Modal/Dialog.js +0 -75
  155. package/dist/components/Modal/Wrapper.js +0 -69
  156. package/dist/components/Modal/index.js +0 -86
  157. package/dist/components/MultiSelector.js +0 -187
  158. package/dist/components/Navigation/Bar.js +0 -293
  159. package/dist/components/Navigation/Tab.js +0 -182
  160. package/dist/components/Placeholder.js +0 -114
  161. package/dist/components/Scope/Selector.js +0 -123
  162. package/dist/components/Selector.js +0 -185
  163. package/dist/components/Switch.js +0 -128
  164. package/dist/components/Toolbar.js +0 -227
  165. package/dist/components/Tooltip.js +0 -66
  166. package/dist/getTheme.js +0 -158
  167. package/dist/getThemeOverrides.js +0 -93
  168. package/dist/hocs/withAuthentication.js +0 -72
  169. package/dist/utils/styledPropFuncs.js +0 -88
  170. package/src/components/Button.js +0 -90
  171. package/src/components/Button.test.js +0 -49
  172. package/src/components/CategoryList.js +0 -140
  173. package/src/components/CategoryList.test.js +0 -667
  174. package/src/components/Checkbox.js +0 -63
  175. package/src/components/Checkbox.test.js +0 -122
  176. package/src/components/Icon.js +0 -18
  177. package/src/components/IconButton.js +0 -30
  178. package/src/components/IconButton.test.js +0 -61
  179. package/src/components/Input.js +0 -35
  180. package/src/components/Input.test.js +0 -34
  181. package/src/components/List/DataCell.js +0 -77
  182. package/src/components/List/DataCell.test.js +0 -357
  183. package/src/components/List/HeadCell.js +0 -105
  184. package/src/components/List/HeadCell.test.js +0 -331
  185. package/src/components/List/HeadRow.js +0 -21
  186. package/src/components/List/HeadRow.test.js +0 -27
  187. package/src/components/List/List.js +0 -162
  188. package/src/components/List/List.test.js +0 -705
  189. package/src/components/List/Row.js +0 -72
  190. package/src/components/List/Row.test.js +0 -194
  191. package/src/components/List/enhanceColumnDefs.js +0 -54
  192. package/src/components/List/enhanceColumnDefs.test.js +0 -179
  193. package/src/components/List/index.js +0 -6
  194. package/src/components/Modal/Background.js +0 -10
  195. package/src/components/Modal/Dialog.js +0 -27
  196. package/src/components/Modal/Dialog.test.js +0 -20
  197. package/src/components/Modal/Modal.test.js +0 -52
  198. package/src/components/Modal/Wrapper.js +0 -32
  199. package/src/components/Modal/Wrapper.test.js +0 -55
  200. package/src/components/Modal/index.js +0 -22
  201. package/src/components/MultiSelector.js +0 -104
  202. package/src/components/MultiSelector.test.js +0 -348
  203. package/src/components/Navigation/Bar.js +0 -212
  204. package/src/components/Navigation/Bar.test.js +0 -552
  205. package/src/components/Navigation/Tab.js +0 -156
  206. package/src/components/Navigation/Tab.test.js +0 -404
  207. package/src/components/Placeholder.js +0 -61
  208. package/src/components/Placeholder.test.js +0 -106
  209. package/src/components/Scope/Selector.js +0 -70
  210. package/src/components/Scope/Selector.test.js +0 -138
  211. package/src/components/Selector.js +0 -191
  212. package/src/components/Selector.test.js +0 -157
  213. package/src/components/Switch.js +0 -112
  214. package/src/components/Switch.test.js +0 -130
  215. package/src/components/Text.test.js +0 -132
  216. package/src/components/Toolbar.js +0 -178
  217. package/src/components/Toolbar.test.js +0 -478
  218. package/src/components/Tooltip.js +0 -51
  219. package/src/components/Tooltip.test.js +0 -21
  220. package/src/getTheme.js +0 -103
  221. package/src/getTheme.test.js +0 -92
  222. package/src/getThemeOverrides.js +0 -27
  223. package/src/hocs/withAuthentication.js +0 -18
  224. package/src/hocs/withAuthentication.test.js +0 -120
  225. package/src/utils/styledPropFuncs.js +0 -20
  226. package/src/utils/styledPropFuncs.test.js +0 -166
@@ -1,92 +0,0 @@
1
- import getTheme from "./getTheme";
2
-
3
- jest.mock("typeface-open-sans", () => ({}));
4
- jest.mock("typeface-roboto-condensed", () => ({}));
5
-
6
- describe("getTheme", () => {
7
- it("gives a theme object containing colors, icon names", () =>
8
- expect(getTheme, "called with", [], "to satisfy", {
9
- colors: { error: "#ce4844" },
10
- treeSettings: {},
11
- icons: {},
12
- fonts: {
13
- base: "Open Sans, sans-serif",
14
- header: "Roboto Condensed, sans-serif",
15
- },
16
- }));
17
-
18
- it("has default app colors", () =>
19
- expect(getTheme, "called with", [], "to satisfy", {
20
- colors: {
21
- application: {
22
- base: "#cccccc",
23
- primary: "#cccccc",
24
- highlight: "#f7f7f7",
25
- select: "#efefef",
26
- dark: "#a3a3a3",
27
- },
28
- },
29
- }));
30
-
31
- it("creates app colors from base", () =>
32
- expect(getTheme, "called with", [{ colors: { application: { base: "#cc33cc" } } }], "to satisfy", {
33
- colors: {
34
- application: {
35
- base: "#cc33cc",
36
- primary: "#cc33cc",
37
- highlight: "#f7e2f7",
38
- select: "#efc1ef",
39
- dark: "#a328a3",
40
- },
41
- },
42
- }));
43
-
44
- it("accepts preset app colors", () =>
45
- expect(
46
- getTheme,
47
- "called with",
48
- [
49
- {
50
- colors: {
51
- application: {
52
- base: "#cc33cc",
53
- primary: "#ff00ff",
54
- highlight: "#6666d8",
55
- select: "#efc1c1",
56
- dark: "#a32828",
57
- },
58
- },
59
- },
60
- ],
61
- "to satisfy",
62
- {
63
- colors: {
64
- application: {
65
- base: "#cc33cc",
66
- primary: "#ff00ff",
67
- highlight: "#6666d8",
68
- select: "#efc1c1",
69
- dark: "#a32828",
70
- },
71
- },
72
- },
73
- ));
74
-
75
- it("handles overrides, including deep merges", () =>
76
- expect(
77
- getTheme,
78
- "called with",
79
- [{ colors: { error: "#FF00FF" }, fonts: { base: "serif", extra: "cursive" } }],
80
- "to satisfy",
81
- {
82
- colors: { error: "#FF00FF" },
83
- treeSettings: {},
84
- icons: {},
85
- fonts: {
86
- base: "serif",
87
- header: "Roboto Condensed, sans-serif",
88
- extra: "cursive",
89
- },
90
- },
91
- ));
92
- });
@@ -1,27 +0,0 @@
1
- /* istanbul ignore file */
2
- // Override values to use Orckestra icon sheet and colors
3
- // See also orc-shared/src/getTheme.js#setApplicationColors()
4
- const colors = {
5
- orckestraBlue: "#00b2e2",
6
- pim: { base: "#0a98cf", highlight: "#8ad5f2" },
7
- oms: {
8
- base: "#1f5b7f",
9
- primary: "#b4cfe3",
10
- highlight: "#b4cfe3",
11
- select: "#b4cfe3",
12
- },
13
- marketing: { base: "#fd6b35", highlight: "#fd6b35" },
14
- analytics: { base: "#ffa205", dark: "#cf8409", highlight: "#f1eae0" },
15
- };
16
-
17
- const getThemeOverrides = appName => {
18
- const application = colors[appName] || {
19
- base: "#ff00ff", // Deliberately godawful default value
20
- highlight: "#efefef",
21
- };
22
- return {
23
- colors: { ...colors, application },
24
- };
25
- };
26
-
27
- export default getThemeOverrides;
@@ -1,18 +0,0 @@
1
- import { compose, branch, renderComponent, mapProps, withProps } from "recompose";
2
- import { useAuthenticationData, Loader, Error } from "../components/Authenticate";
3
-
4
- console.warn("Higher order component withAuthentication has been deprecated in favor of component Authenticate");
5
-
6
- const isAuthenticated = withProps(useAuthenticationData);
7
-
8
- const withAuthentication = compose(
9
- isAuthenticated,
10
- branch(({ loading }) => loading, renderComponent(Loader)),
11
- branch(
12
- ({ authedUser }) => !authedUser,
13
- renderComponent(Error),
14
- mapProps(({ authedUser, loading, requestError, needLogin, ...props }) => props),
15
- ),
16
- );
17
-
18
- export default withAuthentication;
@@ -1,120 +0,0 @@
1
- import React from "react";
2
- import Immutable from "immutable";
3
- import { Provider } from "react-redux";
4
- import { ThemeProvider } from "styled-components";
5
- import withAuthentication from "./withAuthentication";
6
- import { Wrapper, Loader } from "../components/Authenticate";
7
- import { ERROR, LOGOUT } from "../reducers/request";
8
- import { GET_AUTHENTICATION_PROFILE } from "../actions/authentication";
9
-
10
- const TestComp = () => {
11
- return <div className="test"></div>;
12
- };
13
-
14
- describe("withAuthentication", () => {
15
- let state, store, AuthedComp;
16
- beforeEach(() => {
17
- state = Immutable.fromJS({
18
- requests: {},
19
- authentication: {
20
- name: "foo@bar.com",
21
- },
22
- });
23
- store = state => ({
24
- subscribe: () => {},
25
- getState: () => state,
26
- dispatch: () => {},
27
- });
28
- AuthedComp = withAuthentication(TestComp);
29
- });
30
-
31
- it("shows the wrapped component if authenticated", () =>
32
- expect(
33
- <Provider store={store(state)}>
34
- <AuthedComp />
35
- </Provider>,
36
- "when mounted",
37
- "to exhaustively satisfy",
38
- <TestComp />,
39
- ));
40
-
41
- it("shows a load indicator component if authentication is ongoing", () => {
42
- state = state.setIn(["requests", "actives", GET_AUTHENTICATION_PROFILE], true);
43
- return expect(
44
- <Provider store={store(state)}>
45
- <ThemeProvider theme={{}}>
46
- <AuthedComp />
47
- </ThemeProvider>
48
- </Provider>,
49
- "when mounted",
50
- "to exhaustively satisfy",
51
- <ThemeProvider theme={{}}>
52
- <Loader />
53
- </ThemeProvider>,
54
- );
55
- });
56
-
57
- it("shows an error screen if not logged in", () => {
58
- state = state.deleteIn(["authentication", "name"]).setIn(["requests", LOGOUT], true);
59
- return expect(
60
- <Provider store={store(state)}>
61
- <AuthedComp />
62
- </Provider>,
63
- "when mounted",
64
- "to exhaustively satisfy",
65
- <Wrapper>
66
- <h1>Not logged in</h1>
67
- </Wrapper>,
68
- );
69
- });
70
-
71
- it("shows an error screen if an error occured", () => {
72
- state = state.deleteIn(["authentication", "name"]).setIn(
73
- ["requests", ERROR],
74
- Immutable.fromJS({
75
- type: "TEST_ACTION",
76
- payload: { status: 404, message: "404 - NotFound" },
77
- }),
78
- );
79
- return expect(
80
- <Provider store={store(state)}>
81
- <AuthedComp />
82
- </Provider>,
83
- "when mounted",
84
- "to exhaustively satisfy",
85
- <Wrapper>
86
- <h1>404 - NotFound</h1>
87
- {"Last failing action: "}
88
- <pre>
89
- {"{\n" +
90
- ' "type": "TEST_ACTION",\n' +
91
- ' "payload": {\n' +
92
- ' "status": 404,\n' +
93
- ' "message": "404 - NotFound"\n' +
94
- " }\n" +
95
- "}"}
96
- </pre>
97
- </Wrapper>,
98
- );
99
- });
100
-
101
- it("shows an error screen if an error without payload occured", () => {
102
- state = state.deleteIn(["authentication", "name"]).setIn(
103
- ["requests", ERROR],
104
- Immutable.fromJS({
105
- type: "TEST_ACTION",
106
- }),
107
- );
108
- return expect(
109
- <Provider store={store(state)}>
110
- <AuthedComp />
111
- </Provider>,
112
- "when mounted",
113
- "to exhaustively satisfy",
114
- <Wrapper>
115
- <h1>An error occurred</h1>
116
- Last failing action: <pre>{'{\n "type": "TEST_ACTION"\n}'}</pre>
117
- </Wrapper>,
118
- );
119
- });
120
- });
@@ -1,20 +0,0 @@
1
- import safeGet from "./safeGet";
2
-
3
- const feedPropFunc = props => value => typeof value === "function" ? value(props) : value;
4
-
5
- /* Safely gets a (potentially nested) theme property, can run a function on the resulting value */
6
- export const getThemeProp =
7
- (path, defaultValue, func = x => x) =>
8
- props =>
9
- func(safeGet(props, "theme", ...path.map(feedPropFunc(props))) || feedPropFunc(props)(defaultValue));
10
-
11
- /* Use in styled components to check if a prop has a truthy value and
12
- return values based on that. */
13
- export const ifFlag =
14
- (name, thenVal, elseVal = "") =>
15
- props =>
16
- props[name] ? feedPropFunc(props)(thenVal) : feedPropFunc(props)(elseVal);
17
-
18
- /* Creates a prop function that checks a field against a list of cases,
19
- and gives back a found case, or a default */
20
- export const switchEnum = (enumField, cases) => props => cases[props[enumField]] || cases["default"];
@@ -1,166 +0,0 @@
1
- import { getThemeProp, ifFlag, switchEnum } from "./styledPropFuncs";
2
-
3
- describe("getThemeProp", () => {
4
- let props;
5
- beforeEach(() => {
6
- props = {
7
- theme: { hot: { potato: "ooh so tasty" } },
8
- temp: "hot",
9
- weird: "flavortown",
10
- };
11
- });
12
-
13
- it("returns a function that gets a value from the theme prop", () =>
14
- expect(
15
- getThemeProp,
16
- "when called with",
17
- [["hot", "potato"], "a mess"],
18
- "when called with",
19
- [props],
20
- "to equal",
21
- "ooh so tasty",
22
- ));
23
-
24
- it("gets the default if theme prop not found", () =>
25
- expect(
26
- getThemeProp,
27
- "when called with",
28
- [["hot", "tomato"], "a mess"],
29
- "when called with",
30
- [props],
31
- "to equal",
32
- "a mess",
33
- ));
34
-
35
- it("can use prop functions in the path", () =>
36
- expect(
37
- getThemeProp,
38
- "when called with",
39
- [[props => props.temp, "potato"], "a mess"],
40
- "when called with",
41
- [props],
42
- "to equal",
43
- "ooh so tasty",
44
- ));
45
-
46
- it("can use prop functions in the default", () =>
47
- expect(
48
- getThemeProp,
49
- "when called with",
50
- [["hot", "tomato"], props => props.weird],
51
- "when called with",
52
- [props],
53
- "to equal",
54
- "flavortown",
55
- ));
56
-
57
- describe("with function parameter", () => {
58
- let func;
59
- beforeEach(() => {
60
- func = x => x.toUpperCase();
61
- });
62
-
63
- it("calls the passed function on the value from the theme prop", () =>
64
- expect(
65
- getThemeProp,
66
- "when called with",
67
- [["hot", "potato"], "a mess", func],
68
- "when called with",
69
- [props],
70
- "to equal",
71
- "OOH SO TASTY",
72
- ));
73
-
74
- it("calls the passed function on the default if theme prop not found", () =>
75
- expect(
76
- getThemeProp,
77
- "when called with",
78
- [["hot", "tomato"], "a mess", func],
79
- "when called with",
80
- [props],
81
- "to equal",
82
- "A MESS",
83
- ));
84
- });
85
- });
86
-
87
- describe("ifFlag", () => {
88
- let props;
89
- beforeEach(() => {
90
- props = { yesFlag: true, noFlag: false, value: "this is it" };
91
- });
92
-
93
- it("makes a prop function that returns second parameter if first parameter true", () =>
94
- expect(
95
- ifFlag,
96
- "when called with",
97
- ["yesFlag", "no fooling", "not this"],
98
- "when called with",
99
- [props],
100
- "to equal",
101
- "no fooling",
102
- ));
103
-
104
- it("makes a prop function that returns third parameter if first parameter false", () =>
105
- expect(
106
- ifFlag,
107
- "when called with",
108
- ["noFlag", "no fooling", "not this"],
109
- "when called with",
110
- [props],
111
- "to equal",
112
- "not this",
113
- ));
114
-
115
- it("returns empty string if no third parameter", () =>
116
- expect(ifFlag, "when called with", ["noFlag", "no fooling"], "when called with", [props], "to equal", ""));
117
-
118
- it("handles prop funcs as second parameter", () =>
119
- expect(
120
- ifFlag,
121
- "when called with",
122
- ["yesFlag", props => props.value, "not this"],
123
- "when called with",
124
- [props],
125
- "to equal",
126
- "this is it",
127
- ));
128
-
129
- it("handles prop funcs as third parameter", () =>
130
- expect(
131
- ifFlag,
132
- "when called with",
133
- ["noFlag", "no fooling", props => props.value],
134
- "when called with",
135
- [props],
136
- "to equal",
137
- "this is it",
138
- ));
139
- });
140
-
141
- describe("switchEnum", () => {
142
- let cases;
143
- beforeEach(() => {
144
- cases = { one: "One 111", two: "Two 222" };
145
- });
146
-
147
- it("yields a property function which checks a field against a list of cases", () =>
148
- expect(switchEnum, "when called with", ["enum", cases]).then(func =>
149
- expect(func, "when called with", [{ enum: "one" }], "to equal", "One 111")
150
- .and("when called with", [{ enum: "two" }], "to equal", "Two 222")
151
- .and("when called with", [{ enum: "three" }], "to be undefined"),
152
- ));
153
-
154
- it("yields a default if one is set", () => {
155
- cases.default = "A default";
156
- return expect(
157
- switchEnum,
158
- "when called with",
159
- ["enum", cases],
160
- "when called with",
161
- [{ enum: "three" }],
162
- "to equal",
163
- "A default",
164
- );
165
- });
166
- });