orc-shared 1.2.0-dev.2 → 1.2.0-dev.6

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 (74) hide show
  1. package/dist/actions/modules.js +63 -1
  2. package/dist/actions/scopes.js +59 -22
  3. package/dist/components/AppFrame/MenuItem.js +5 -14
  4. package/dist/components/AppFrame/Sidebar.js +11 -5
  5. package/dist/components/ApplicationModuleLoader.js +143 -0
  6. package/dist/components/Authenticate.js +12 -12
  7. package/dist/components/MaterialUI/DataDisplay/SelectionList.js +1 -1
  8. package/dist/components/MaterialUI/Navigation/ExternalLink.js +113 -0
  9. package/dist/components/MaterialUI/muiThemes.js +5 -0
  10. package/dist/components/Modules.js +126 -41
  11. package/dist/components/Routing/FullPage.js +3 -1
  12. package/dist/components/Routing/Page.js +5 -3
  13. package/dist/components/Routing/Segment.js +1 -1
  14. package/dist/components/Routing/withWaypointing.js +6 -2
  15. package/dist/components/Scope/useScopeConfirmationModalState.js +7 -16
  16. package/dist/components/Scope/useScopeData.js +4 -13
  17. package/dist/constants.js +19 -2
  18. package/dist/content/iconsSheet.svg +3 -0
  19. package/dist/reducers/modules.js +39 -1
  20. package/dist/reducers/scopes.js +27 -0
  21. package/dist/reducers/settings.js +31 -2
  22. package/dist/selectors/authentication.js +57 -18
  23. package/dist/selectors/modules.js +15 -1
  24. package/dist/selectors/scope.js +7 -1
  25. package/dist/selectors/settings.js +13 -1
  26. package/package.json +6 -5
  27. package/src/actions/modules.js +30 -0
  28. package/src/actions/modules.test.js +50 -1
  29. package/src/actions/scopes.js +33 -7
  30. package/src/actions/scopes.test.js +84 -14
  31. package/src/components/AppFrame/AppFrame.test.js +9 -0
  32. package/src/components/AppFrame/MenuItem.js +3 -5
  33. package/src/components/AppFrame/MenuItem.test.js +2 -24
  34. package/src/components/AppFrame/Sidebar.js +8 -1
  35. package/src/components/AppFrame/Sidebar.test.js +18 -0
  36. package/src/components/ApplicationModuleLoader.js +52 -0
  37. package/src/components/ApplicationModuleLoader.test.js +149 -0
  38. package/src/components/Authenticate.js +5 -4
  39. package/src/components/Authenticate.test.js +23 -4
  40. package/src/components/MaterialUI/DataDisplay/SelectionList.js +1 -1
  41. package/src/components/MaterialUI/DataDisplay/SelectionList.test.js +2 -2
  42. package/src/components/MaterialUI/Navigation/ExternalLink.js +25 -0
  43. package/src/components/MaterialUI/Navigation/ExternalLink.test.js +26 -0
  44. package/src/components/MaterialUI/muiThemes.js +5 -0
  45. package/src/components/Modules.js +103 -20
  46. package/src/components/Modules.test.js +315 -28
  47. package/src/components/Provision.test.js +34 -0
  48. package/src/components/Routing/FullPage.js +2 -1
  49. package/src/components/Routing/FullPage.test.js +23 -0
  50. package/src/components/Routing/Page.js +2 -2
  51. package/src/components/Routing/Page.test.js +20 -0
  52. package/src/components/Routing/Segment.js +1 -1
  53. package/src/components/Routing/withWaypointing.js +2 -2
  54. package/src/components/Routing/withWaypointing.test.js +33 -5
  55. package/src/components/Scope/useScopeConfirmationModalState.js +5 -16
  56. package/src/components/Scope/useScopeConfirmationModalState.test.js +39 -13
  57. package/src/components/Scope/useScopeData.js +0 -3
  58. package/src/components/Scope/useScopeData.test.js +0 -27
  59. package/src/constants.js +15 -0
  60. package/src/content/iconsSheet.svg +3 -0
  61. package/src/hocs/withScopeData.test.js +0 -31
  62. package/src/reducers/modules.js +48 -2
  63. package/src/reducers/modules.test.js +117 -2
  64. package/src/reducers/scopes.js +30 -0
  65. package/src/reducers/scopes.test.js +45 -1
  66. package/src/reducers/settings.js +26 -2
  67. package/src/reducers/settings.test.js +74 -6
  68. package/src/selectors/authentication.js +53 -27
  69. package/src/selectors/authentication.test.js +600 -12
  70. package/src/selectors/modules.js +7 -0
  71. package/src/selectors/modules.test.js +16 -1
  72. package/src/selectors/scope.js +2 -0
  73. package/src/selectors/scope.test.js +5 -0
  74. package/src/selectors/settings.js +6 -0
@@ -1,16 +1,17 @@
1
1
  import { RSAA } from "redux-api-middleware";
2
2
  import {
3
- GET_SCOPES_REQUEST,
4
- GET_SCOPES_SUCCESS,
5
- GET_SCOPES_FAILURE,
6
3
  getScopes,
7
4
  GET_MY_SCOPE_REQUEST,
8
5
  GET_MY_SCOPE_SUCCESS,
9
6
  GET_MY_SCOPE_FAILURE,
10
7
  getDefaultScope,
11
- validateOvertureModule,
8
+ validateOvertureApplication,
12
9
  APPLICATION_SCOPE_HAS_CHANGED,
13
10
  applicationScopeHasChanged,
11
+ getAppModules,
12
+ GET_APPLICATION_MODULES_REQUEST,
13
+ GET_APPLICATION_MODULES_SUCCESS,
14
+ GET_APPLICATION_MODULES_FAILURE,
14
15
  } from "./scopes";
15
16
 
16
17
  jest.mock("../utils/buildUrl", () => {
@@ -20,19 +21,71 @@ jest.mock("../utils/buildUrl", () => {
20
21
  return modExport;
21
22
  });
22
23
 
24
+ describe("getAppModules", () => {
25
+ it("creates a RSAA to fetch application modules", () => {
26
+ expect(getAppModules, "when called", "to exhaustively satisfy", {
27
+ [RSAA]: {
28
+ types: [GET_APPLICATION_MODULES_REQUEST, GET_APPLICATION_MODULES_SUCCESS, GET_APPLICATION_MODULES_FAILURE],
29
+ endpoint: 'URL: modules/byApplicationName/anApplication ""',
30
+ method: "GET",
31
+ body: undefined,
32
+ credentials: "include",
33
+ bailout: expect.it("to be a function"),
34
+ headers: {
35
+ Accept: "application/json; charset=utf-8",
36
+ "Content-Type": "application/json",
37
+ },
38
+ options: { redirect: "follow" },
39
+ },
40
+ });
41
+ });
42
+ });
43
+
23
44
  describe("getScopes", () => {
24
- beforeEach(() => {});
25
- afterEach(() => {});
45
+ let originalApplication;
46
+
47
+ beforeEach(() => {
48
+ originalApplication = global.OVERTURE_APPLICATION;
49
+ });
50
+
51
+ afterEach(() => {
52
+ global.OVERTURE_APPLICATION = originalApplication;
53
+ });
26
54
 
27
55
  it("creates a RSAA to fetch authorized scope tree", () =>
28
- expect(getScopes, "when called", "to exhaustively satisfy", {
56
+ expect(getScopes, "when called with", ["aModule"], "to exhaustively satisfy", {
29
57
  [RSAA]: {
30
- types: [GET_SCOPES_REQUEST, GET_SCOPES_SUCCESS, GET_SCOPES_FAILURE],
58
+ types: [
59
+ { type: "GET_SCOPES_REQUEST", meta: { module: "aModule" } },
60
+ { type: "GET_SCOPES_SUCCESS", meta: { module: "aModule" } },
61
+ { type: "GET_SCOPES_FAILURE", meta: { module: "aModule" } },
62
+ ],
31
63
  endpoint: "URL: my/scope/aModule/tree {}",
32
64
  method: "GET",
33
65
  body: undefined,
34
66
  credentials: "include",
35
- bailout: expect.it("to be a function"),
67
+ bailout: false,
68
+ headers: {
69
+ Accept: "application/json; charset=utf-8",
70
+ "Content-Type": "application/json",
71
+ },
72
+ options: { redirect: "follow" },
73
+ },
74
+ }));
75
+
76
+ it("creates a RSAA to fetch authorized scope tree for system module", () =>
77
+ expect(getScopes, "when called with", ["System"], "to exhaustively satisfy", {
78
+ [RSAA]: {
79
+ types: [
80
+ { type: "GET_SCOPES_REQUEST", meta: { module: "System" } },
81
+ { type: "GET_SCOPES_SUCCESS", meta: { module: "System" } },
82
+ { type: "GET_SCOPES_FAILURE", meta: { module: "System" } },
83
+ ],
84
+ endpoint: "URL: my/scope/Order/tree {}",
85
+ method: "GET",
86
+ body: undefined,
87
+ credentials: "include",
88
+ bailout: false,
36
89
  headers: {
37
90
  Accept: "application/json; charset=utf-8",
38
91
  "Content-Type": "application/json",
@@ -42,14 +95,31 @@ describe("getScopes", () => {
42
95
  }));
43
96
 
44
97
  it("creates a RSAA to fetch default user scope", () =>
45
- expect(getDefaultScope, "when called", "to exhaustively satisfy", {
98
+ expect(getDefaultScope, "when called with", ["aModule"], "to exhaustively satisfy", {
46
99
  [RSAA]: {
47
100
  types: [GET_MY_SCOPE_REQUEST, GET_MY_SCOPE_SUCCESS, GET_MY_SCOPE_FAILURE],
48
101
  endpoint: 'URL: my/scope/aModule ""',
49
102
  method: "GET",
50
103
  body: undefined,
51
104
  credentials: "include",
52
- bailout: expect.it("to be a function"),
105
+ bailout: false,
106
+ headers: {
107
+ Accept: "application/json; charset=utf-8",
108
+ "Content-Type": "application/json",
109
+ },
110
+ options: { redirect: "follow" },
111
+ },
112
+ }));
113
+
114
+ it("creates a RSAA to fetch default user scope for System module", () =>
115
+ expect(getDefaultScope, "when called with", ["System"], "to exhaustively satisfy", {
116
+ [RSAA]: {
117
+ types: [GET_MY_SCOPE_REQUEST, GET_MY_SCOPE_SUCCESS, GET_MY_SCOPE_FAILURE],
118
+ endpoint: 'URL: my/scope/Order ""',
119
+ method: "GET",
120
+ body: undefined,
121
+ credentials: "include",
122
+ bailout: false,
53
123
  headers: {
54
124
  Accept: "application/json; charset=utf-8",
55
125
  "Content-Type": "application/json",
@@ -59,11 +129,11 @@ describe("getScopes", () => {
59
129
  }));
60
130
 
61
131
  it("throws an error if no class found on DOM element", () => {
62
- global.OVERTURE_MODULE = "";
132
+ global.OVERTURE_APPLICATION = "";
63
133
  expect(
64
- () => expect(validateOvertureModule, "when called with", []),
134
+ () => expect(validateOvertureApplication, "when called with", []),
65
135
  "to throw",
66
- '"overtureModule.name" is missing in the configuration.',
136
+ '"overtureApplication.name" is missing in the configuration.',
67
137
  );
68
138
  });
69
139
  });
@@ -202,6 +202,15 @@ describe("AppFrame", () => {
202
202
  bar: true,
203
203
  },
204
204
  },
205
+ modules: {
206
+ tree: "modulesTree",
207
+ visibleModules: ["a", "module123", "test1", "test2", "test3"],
208
+ lastScopeAndModuleSelection: {
209
+ scope: "Norway",
210
+ moduleName: "Profiles",
211
+ routingPerformed: false,
212
+ },
213
+ },
205
214
  settings: { defaultScope: "myScope", defaultApp: "12" },
206
215
  versionInfo: { version: "4.2", defaultHelpUrl: "help_url", moduleHelpUrls: [] },
207
216
  view: { scopeSelector: { filter: "1" }, __prefsDialog: { show: false } },
@@ -1,5 +1,4 @@
1
1
  import React, { useRef } from "react";
2
- import { useSelector } from "react-redux";
3
2
  import styled, { css } from "styled-components";
4
3
  import transition from "styled-transition-group";
5
4
  import { Link } from "react-router-dom";
@@ -124,13 +123,11 @@ const MenuItem = ({
124
123
  alert,
125
124
  pageScopeSelector,
126
125
  closingTabHandler,
127
- hide,
126
+ hide, // This props is not used in the component, but we need to destructure it so props can be used in ItemWrapper
127
+ isHidden = false,
128
128
  href,
129
129
  ...props
130
130
  }) => {
131
- let hideSelector = state => (typeof hide === "function" ? hide(state) : hide ?? false);
132
- const isHidden = useSelector(hideSelector);
133
-
134
131
  let ItemWrapper = Block;
135
132
  if (props.menuToggle) {
136
133
  ItemWrapper = BlockWithA;
@@ -139,6 +136,7 @@ const MenuItem = ({
139
136
  if (alert && alert.message) {
140
137
  alertMessage.current = alert.message;
141
138
  }
139
+
142
140
  return (
143
141
  !isHidden && (
144
142
  <ItemWrapper to={href} {...props}>
@@ -168,7 +168,7 @@ describe("MenuItem", () => {
168
168
  </MemoryRouter>,
169
169
  ));
170
170
 
171
- it("shows nothing if hide is true", () => {
171
+ it("shows nothing if isHidden is true", () => {
172
172
  expect(
173
173
  <Provider store={store}>
174
174
  <MemoryRouter>
@@ -178,29 +178,7 @@ describe("MenuItem", () => {
178
178
  icon="cake"
179
179
  label="Test"
180
180
  alert={{ message: "Test message", type: "warn" }}
181
- hide={true}
182
- />
183
- </MemoryRouter>
184
- </Provider>,
185
- "when mounted",
186
- "to equal",
187
- null,
188
- );
189
- });
190
-
191
- it("shows nothing if hide selector returns true", () => {
192
- const hide = state => true;
193
-
194
- expect(
195
- <Provider store={store}>
196
- <MemoryRouter>
197
- <MenuItem
198
- id="test"
199
- href="/foo/test"
200
- icon="cake"
201
- label="Test"
202
- alert={{ message: "Test message", type: "warn" }}
203
- hide={hide}
181
+ isHidden={true}
204
182
  />
205
183
  </MemoryRouter>
206
184
  </Provider>,
@@ -5,6 +5,7 @@ import { useLocation } from "react-router-dom";
5
5
  import { getThemeProp } from "../../utils";
6
6
  import { selectPrependHrefConfig } from "../../selectors/navigation";
7
7
  import MenuItem from "./MenuItem";
8
+ import { getScopeModuleInformationSelector } from "../../selectors/modules";
8
9
 
9
10
  export const Bar = styled.div`
10
11
  box-sizing: border-box;
@@ -40,7 +41,13 @@ const useEnhancement = id => {
40
41
  };
41
42
  };
42
43
 
43
- export const EnhancedMenuItem = ({ id, ...props }) => <MenuItem {...props} {...useEnhancement(id)} />;
44
+ export const EnhancedMenuItem = ({ id, ...props }) => {
45
+ const defaultModule = useSelector(getScopeModuleInformationSelector);
46
+
47
+ const isHidden = !defaultModule.visibleModules.includes(id);
48
+
49
+ return <MenuItem {...props} {...useEnhancement(id)} isHidden={isHidden} />;
50
+ };
44
51
 
45
52
  const LogoSvg = styled.svg`
46
53
  flex: 0 0 auto;
@@ -24,6 +24,15 @@ describe("Sidebar", () => {
24
24
  state = Immutable.fromJS({
25
25
  navigation: { route: { match: { params: { scope: "Global" } } }, config: { prependHref: "/Global/" } },
26
26
  settings: { defaultScope: "myScope" },
27
+ modules: {
28
+ tree: "modulesTree",
29
+ visibleModules: ["a", "module123"],
30
+ lastScopeAndModuleSelection: {
31
+ scope: "Norway",
32
+ moduleName: "Profiles",
33
+ routingPerformed: false,
34
+ },
35
+ },
27
36
  });
28
37
  store = {
29
38
  subscribe: () => {},
@@ -153,6 +162,15 @@ describe("EnhancedMenuItem", () => {
153
162
  },
154
163
  config: { prependHref: "/Global/" },
155
164
  },
165
+ modules: {
166
+ tree: "modulesTree",
167
+ visibleModules: ["route"],
168
+ lastScopeAndModuleSelection: {
169
+ scope: "Norway",
170
+ moduleName: "Profiles",
171
+ routingPerformed: false,
172
+ },
173
+ },
156
174
  settings: { defaultScope: "myScope" },
157
175
  }),
158
176
  };
@@ -0,0 +1,52 @@
1
+ import React, { useEffect, useState } from "react";
2
+ import { useDispatch, useSelector } from "react-redux";
3
+ import { getDefaultScope, getScopes } from "../actions/scopes";
4
+ import {
5
+ defaultScopeSelector,
6
+ getApplicationModulesSelector,
7
+ getLoadedModulesScopeSelector,
8
+ } from "../selectors/settings";
9
+ import { Loader } from "./Authenticate";
10
+ import { overtureModule, scopeTypes } from "../constants";
11
+ import { initializeFirstModuleScope } from "../actions/modules";
12
+
13
+ const ApplicationModuleLoader = ({ children }) => {
14
+ const dispatch = useDispatch();
15
+
16
+ const [scopesLoaded, setScopesLoaded] = useState(false);
17
+
18
+ const loadedModules = useSelector(getLoadedModulesScopeSelector);
19
+ const applicationModules = useSelector(getApplicationModulesSelector);
20
+ const defaultScope = useSelector(defaultScopeSelector);
21
+
22
+ useEffect(() => {
23
+ if (applicationModules.length > 0 && scopesLoaded === false) {
24
+ if (applicationModules.includes(overtureModule.System)) {
25
+ dispatch(initializeFirstModuleScope(scopeTypes.global));
26
+ }
27
+
28
+ applicationModules.forEach(x => {
29
+ // For the default scope, the latest that will be returned will be the chosen one
30
+ dispatch(getDefaultScope(x));
31
+ // For scopes, they need to be merged
32
+ dispatch(getScopes(x));
33
+ });
34
+
35
+ setScopesLoaded(true);
36
+ }
37
+ }, [dispatch, applicationModules, scopesLoaded]);
38
+
39
+ const scopeLoadedFromAllModules =
40
+ applicationModules.length > 0 &&
41
+ applicationModules.reduce((prev, current) => prev && loadedModules.includes(current), true);
42
+
43
+ const applicationModuleReady = scopeLoadedFromAllModules && defaultScope != null;
44
+
45
+ if (!applicationModuleReady) {
46
+ return <Loader />;
47
+ }
48
+
49
+ return React.Children.only(children);
50
+ };
51
+
52
+ export default ApplicationModuleLoader;
@@ -0,0 +1,149 @@
1
+ import React from "react";
2
+ import Immutable from "immutable";
3
+ import { Provider } from "react-redux";
4
+ import { ThemeProvider } from "styled-components";
5
+ import { Loader } from "./Authenticate";
6
+ import ApplicationModuleLoader from "./ApplicationModuleLoader";
7
+ import { mount } from "enzyme";
8
+ import { getDefaultScope, getScopes } from "../actions/scopes";
9
+ import sinon from "sinon";
10
+ import { initializeFirstModuleScope } from "../actions/modules";
11
+ import { scopeTypes } from "../constants";
12
+
13
+ const TestComp = () => {
14
+ return <div className="test" />;
15
+ };
16
+
17
+ jest.mock("../utils/buildUrl", () => {
18
+ const modExport = {};
19
+ modExport.loadConfig = () => Promise.resolve({});
20
+ modExport.buildUrl = (path = [], params = "") => "URL: " + path.join("/") + " " + JSON.stringify(params);
21
+ return modExport;
22
+ });
23
+
24
+ describe("ApplicationModuleLoader", () => {
25
+ let state, store;
26
+
27
+ beforeEach(() => {
28
+ state = Immutable.fromJS({
29
+ requests: {},
30
+ scopes: {
31
+ test1: {
32
+ id: "test1",
33
+ name: { "en-CA": "Test 1", "en-US": "Test 1" },
34
+ children: ["test2"],
35
+ },
36
+ },
37
+ authentication: {
38
+ name: "foo@bar.com",
39
+ },
40
+ settings: {
41
+ defaultScope: "aDefaultScope",
42
+ loadedModulesScope: ["moduleA", "moduleB"],
43
+ modules: ["moduleA", "moduleB"],
44
+ },
45
+ });
46
+ store = state => ({
47
+ subscribe: () => {},
48
+ getState: () => state,
49
+ dispatch: sinon.spy().named("dispatch"),
50
+ });
51
+ });
52
+
53
+ it("shows the component when scopes configuration are all loaded", () =>
54
+ expect(
55
+ <Provider store={store(state)}>
56
+ <ApplicationModuleLoader>
57
+ <TestComp />
58
+ </ApplicationModuleLoader>
59
+ </Provider>,
60
+ "when mounted",
61
+ "to exhaustively satisfy",
62
+ <TestComp />,
63
+ ));
64
+
65
+ it("shows a load indicator component when default scope is still unknown", () => {
66
+ state = state.setIn(["settings", "defaultScope"], null);
67
+ return expect(
68
+ <Provider store={store(state)}>
69
+ <ThemeProvider theme={{}}>
70
+ <ApplicationModuleLoader>
71
+ <TestComp />
72
+ </ApplicationModuleLoader>
73
+ </ThemeProvider>
74
+ </Provider>,
75
+ "when mounted",
76
+ "to exhaustively satisfy",
77
+ <ThemeProvider theme={{}}>
78
+ <Loader />
79
+ </ThemeProvider>,
80
+ );
81
+ });
82
+
83
+ it("shows a load indicator component when scopes trees are not loaded for all modules", () => {
84
+ state = state.setIn(["settings", "loadedModulesScope"], Immutable.fromJS(["moduleA"]));
85
+ return expect(
86
+ <Provider store={store(state)}>
87
+ <ThemeProvider theme={{}}>
88
+ <ApplicationModuleLoader>
89
+ <TestComp />
90
+ </ApplicationModuleLoader>
91
+ </ThemeProvider>
92
+ </Provider>,
93
+ "when mounted",
94
+ "to exhaustively satisfy",
95
+ <ThemeProvider theme={{}}>
96
+ <Loader />
97
+ </ThemeProvider>,
98
+ );
99
+ });
100
+
101
+ it("scopes tree and default scope should be loaded when rendering the component", () => {
102
+ const theStore = store(state);
103
+
104
+ const component = (
105
+ <Provider store={theStore}>
106
+ <ThemeProvider theme={{}}>
107
+ <ApplicationModuleLoader>
108
+ <TestComp />
109
+ </ApplicationModuleLoader>
110
+ </ThemeProvider>
111
+ </Provider>
112
+ );
113
+
114
+ mount(component);
115
+
116
+ expect(theStore.dispatch, "to have calls satisfying", [
117
+ { args: [getDefaultScope("moduleA")] },
118
+ { args: [getScopes("moduleA")] },
119
+ { args: [getDefaultScope("moduleB")] },
120
+ { args: [getScopes("moduleB")] },
121
+ ]);
122
+ });
123
+
124
+ it("First module scope should be initialized when System is part application modules", () => {
125
+ state = state.setIn(["settings", "modules"], Immutable.fromJS(["moduleA", "System"]));
126
+
127
+ const theStore = store(state);
128
+
129
+ const component = (
130
+ <Provider store={theStore}>
131
+ <ThemeProvider theme={{}}>
132
+ <ApplicationModuleLoader>
133
+ <TestComp />
134
+ </ApplicationModuleLoader>
135
+ </ThemeProvider>
136
+ </Provider>
137
+ );
138
+
139
+ mount(component);
140
+
141
+ expect(theStore.dispatch, "to have calls satisfying", [
142
+ { args: [initializeFirstModuleScope(scopeTypes.global)] },
143
+ { args: [getDefaultScope("moduleA")] },
144
+ { args: [getScopes("moduleA")] },
145
+ { args: [getDefaultScope("System")] },
146
+ { args: [getScopes("System")] },
147
+ ]);
148
+ });
149
+ });
@@ -6,10 +6,10 @@ import { useSelector } from "react-redux";
6
6
  import { unwrapImmutable } from "../utils";
7
7
  import { GET_AUTHENTICATION_PROFILE } from "../actions/authentication";
8
8
  import { ERROR, LOGOUT } from "../reducers/request";
9
+ import ApplicationModuleLoader from "./ApplicationModuleLoader";
9
10
 
10
11
  export const useAuthenticationData = () => ({
11
12
  loading: useSelector(state => state.getIn(["requests", "actives", GET_AUTHENTICATION_PROFILE])),
12
- defaultScope: useSelector(state => state.getIn(["settings", "defaultScope"])) || null,
13
13
  authedUser: useSelector(state => state.getIn(["authentication", "name"])),
14
14
  requestError: unwrapImmutable(useSelector(state => state.getIn(["requests", ERROR]) || null)),
15
15
  needLogin: useSelector(state => state.getIn(["requests", LOGOUT])),
@@ -47,14 +47,15 @@ export const Error = ({ requestError, needLogin }) => {
47
47
  };
48
48
 
49
49
  const Authenticate = ({ children }) => {
50
- const { loading, defaultScope, authedUser, requestError, needLogin } = useAuthenticationData();
51
- if (loading || defaultScope === null) {
50
+ const { loading, authedUser, requestError, needLogin } = useAuthenticationData();
51
+
52
+ if (loading) {
52
53
  return <Loader />;
53
54
  }
54
55
  if (!authedUser) {
55
56
  return <Error {...{ requestError, needLogin }} />;
56
57
  } else {
57
- return React.Children.only(children);
58
+ return <ApplicationModuleLoader children={children} />;
58
59
  }
59
60
  };
60
61
 
@@ -7,19 +7,36 @@ import { ERROR, LOGOUT } from "../reducers/request";
7
7
  import { GET_AUTHENTICATION_PROFILE } from "../actions/authentication";
8
8
 
9
9
  const TestComp = () => {
10
- return <div className="test"></div>;
10
+ return <div className="test" />;
11
11
  };
12
12
 
13
+ jest.mock("../utils/buildUrl", () => {
14
+ const modExport = {};
15
+ modExport.loadConfig = () => Promise.resolve({});
16
+ modExport.buildUrl = () => "URL";
17
+ return modExport;
18
+ });
19
+
13
20
  describe("Authenticate", () => {
14
21
  let state, store;
22
+
15
23
  beforeEach(() => {
16
24
  state = Immutable.fromJS({
17
25
  requests: {},
26
+ scopes: {
27
+ test1: {
28
+ id: "test1",
29
+ name: { "en-CA": "Test 1", "en-US": "Test 1" },
30
+ children: ["test2"],
31
+ },
32
+ },
18
33
  authentication: {
19
34
  name: "foo@bar.com",
20
35
  },
21
36
  settings: {
22
37
  defaultScope: "aDefaultScope",
38
+ loadedModulesScope: ["moduleA", "moduleB"],
39
+ modules: ["moduleA", "moduleB"],
23
40
  },
24
41
  });
25
42
  store = state => ({
@@ -38,7 +55,9 @@ describe("Authenticate", () => {
38
55
  </Provider>,
39
56
  "when mounted",
40
57
  "to exhaustively satisfy",
41
- <TestComp />,
58
+ <Provider store={store(state)}>
59
+ <TestComp />
60
+ </Provider>,
42
61
  ));
43
62
 
44
63
  it("shows a load indicator component if authentication is ongoing", () => {
@@ -59,12 +78,12 @@ describe("Authenticate", () => {
59
78
  );
60
79
  });
61
80
 
62
- it("shows a load indicator component if default scope is unknown", () => {
81
+ it("shows a load indicator component when application modules not ready", () => {
63
82
  state = state.setIn(["settings", "defaultScope"], null);
64
83
  return expect(
65
84
  <Provider store={store(state)}>
66
85
  <ThemeProvider theme={{}}>
67
- <Authenticate>
86
+ <Authenticate applicationModuleReady={false}>
68
87
  <TestComp />
69
88
  </Authenticate>
70
89
  </ThemeProvider>
@@ -54,7 +54,7 @@ const formatOnChange = (data, ids) => {
54
54
  const selectedItems = data.filter(dataItem => ids.includes(dataItem.id));
55
55
 
56
56
  return {
57
- selectedItems: [...selectedItems],
57
+ left: [...selectedItems],
58
58
  };
59
59
  };
60
60
 
@@ -179,7 +179,7 @@ describe("SelectionList", () => {
179
179
  let item = mountedComponent.find(ListItem).at(0);
180
180
  item.invoke("onClick")();
181
181
 
182
- expect(onChange.args[2][0], "to equal", { selectedItems: [list[0]] });
182
+ expect(onChange.args[2][0], "to equal", { left: [list[0]] });
183
183
  });
184
184
 
185
185
  it("Calls onChange with defaultSelection", () => {
@@ -196,7 +196,7 @@ describe("SelectionList", () => {
196
196
 
197
197
  mount(component);
198
198
 
199
- expect(onChange.args[1][0], "to equal", { selectedItems: [data[1]] });
199
+ expect(onChange.args[1][0], "to equal", { left: [data[1]] });
200
200
  });
201
201
 
202
202
  it("handle scrolling event", () => {
@@ -0,0 +1,25 @@
1
+ import React from "react";
2
+ import Link from "@material-ui/core/Link";
3
+ import Icon from "../DataDisplay/Icon";
4
+ import { makeStyles } from "@material-ui/core/styles";
5
+
6
+ const useStyles = makeStyles(theme => ({
7
+ icon: {
8
+ paddingLeft: theme.spacing(1),
9
+ width: theme.spacing(1.2),
10
+ color: theme.palette.primary.main,
11
+ },
12
+ }));
13
+
14
+ const ExternalLink = ({ id, url, children }) => {
15
+ const classes = useStyles();
16
+
17
+ return (
18
+ <Link id={id} href={url} rel="noreferrer" target="_blank" underline="always">
19
+ {children}
20
+ <Icon id="open-in-new-tab" className={classes.icon} />
21
+ </Link>
22
+ );
23
+ };
24
+
25
+ export default ExternalLink;
@@ -0,0 +1,26 @@
1
+ import React from "react";
2
+ import Link from "@material-ui/core/Link";
3
+ import Icon from "../DataDisplay/Icon";
4
+ import ExternalLink from "./ExternalLink";
5
+
6
+ describe("ExternalLink", () => {
7
+ it("render ExternalLink without errors", () => {
8
+ const children = <div>a div element</div>;
9
+
10
+ expect(
11
+ <ExternalLink id="an_Id" url="https://www.npmjs.com/package/orc-shared" children={children} />,
12
+ "when mounted",
13
+ "to satisfy",
14
+ <Link
15
+ id="an_Id"
16
+ href="https://www.npmjs.com/package/orc-shared"
17
+ rel="noreferrer"
18
+ target="_blank"
19
+ underline="always"
20
+ >
21
+ {children}
22
+ <Icon id="open-in-new-tab" />
23
+ </Link>,
24
+ );
25
+ });
26
+ });
@@ -158,6 +158,11 @@ const setThemeOverrides = theme => ({
158
158
  },
159
159
  },
160
160
  },
161
+ MuiLink: {
162
+ root: {
163
+ fontSize: theme.spacing(1.3),
164
+ },
165
+ },
161
166
  MuiButton: {
162
167
  ...theme.MuiButton,
163
168
  root: {