Skip to content

Commit 73cc266

Browse files
committed
additional testing
1 parent 95d390e commit 73cc266

File tree

5 files changed

+143
-2
lines changed

5 files changed

+143
-2
lines changed

x-pack/plugins/security/common/licensing/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
*/
66

77
export { SecurityLicenseService, SecurityLicense } from './license_service';
8+
9+
export { SecurityLicenseFeatures } from './license_features';

x-pack/plugins/security/public/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { SecurityPlugin, SecurityPluginSetup, SecurityPluginStart } from './plug
1010
export { SecurityPluginSetup, SecurityPluginStart };
1111
export { SessionInfo } from './types';
1212
export { AuthenticatedUser } from '../common/model';
13-
export { SecurityLicense } from '../common/licensing';
13+
export { SecurityLicense, SecurityLicenseFeatures } from '../common/licensing';
1414

1515
export const plugin: PluginInitializer<SecurityPluginSetup, SecurityPluginStart> = () =>
1616
new SecurityPlugin();

x-pack/plugins/security/public/mocks.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
import { authenticationMock } from './authentication/index.mock';
88
import { createSessionTimeoutMock } from './session/session_timeout.mock';
9+
import { licenseMock } from '../common/licensing/index.mock';
910

1011
function createSetupMock() {
1112
return {
1213
authc: authenticationMock.createSetup(),
1314
sessionTimeout: createSessionTimeoutMock(),
15+
license: licenseMock.create(),
1416
};
1517
}
1618

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
jest.mock('./spaces_grid', () => ({
8+
SpacesGridPage: (props: any) => `Spaces Page: ${JSON.stringify(props)}`,
9+
}));
10+
11+
jest.mock('./edit_space', () => ({
12+
ManageSpacePage: (props: any) => {
13+
if (props.spacesManager && props.onLoadSpace) {
14+
props.spacesManager.getSpace().then((space: any) => props.onLoadSpace(space));
15+
}
16+
return `Spaces Edit Page: ${JSON.stringify(props)}`;
17+
},
18+
}));
19+
20+
import { spacesManagementApp } from './spaces_management_app';
21+
22+
import { coreMock } from '../../../../../src/core/public/mocks';
23+
import { securityMock } from '../../../security/public/mocks';
24+
import { spacesManagerMock } from '../spaces_manager/mocks';
25+
import { SecurityLicenseFeatures } from '../../../security/public';
26+
27+
async function mountApp(basePath: string, spaceId?: string) {
28+
const container = document.createElement('div');
29+
const setBreadcrumbs = jest.fn();
30+
31+
const spacesManager = spacesManagerMock.create();
32+
if (spaceId) {
33+
spacesManager.getSpace.mockResolvedValue({
34+
id: spaceId,
35+
name: `space with id ${spaceId}`,
36+
disabledFeatures: [],
37+
});
38+
}
39+
40+
const securityLicense = securityMock.createSetup().license;
41+
securityLicense.getFeatures.mockReturnValue({
42+
showLinks: true,
43+
} as SecurityLicenseFeatures);
44+
45+
const unmount = await spacesManagementApp
46+
.create({
47+
spacesManager,
48+
securityLicense,
49+
getStartServices: coreMock.createSetup().getStartServices as any,
50+
})
51+
.mount({ basePath, element: container, setBreadcrumbs });
52+
53+
return { unmount, container, setBreadcrumbs };
54+
}
55+
56+
describe('spacesManagementApp', () => {
57+
it('create() returns proper management app descriptor', () => {
58+
expect(
59+
spacesManagementApp.create({
60+
spacesManager: spacesManagerMock.create(),
61+
securityLicense: securityMock.createSetup().license,
62+
getStartServices: coreMock.createSetup().getStartServices as any,
63+
})
64+
).toMatchInlineSnapshot(`
65+
Object {
66+
"id": "spaces",
67+
"mount": [Function],
68+
"order": 10,
69+
"title": "Spaces",
70+
}
71+
`);
72+
});
73+
74+
it('mount() works for the `grid` page', async () => {
75+
const basePath = '/some-base-path/spaces';
76+
window.location.hash = basePath;
77+
78+
const { setBreadcrumbs, container, unmount } = await mountApp(basePath);
79+
80+
expect(setBreadcrumbs).toHaveBeenCalledTimes(1);
81+
expect(setBreadcrumbs).toHaveBeenCalledWith([{ href: `#${basePath}`, text: 'Spaces' }]);
82+
expect(container).toMatchInlineSnapshot(`
83+
<div>
84+
Spaces Page: {"capabilities":{"catalogue":{},"management":{},"navLinks":{}},"http":{"basePath":{"basePath":""},"anonymousPaths":{}},"notifications":{"toasts":{}},"spacesManager":{"onActiveSpaceChange$":{"_isScalar":false}},"securityEnabled":true}
85+
</div>
86+
`);
87+
88+
unmount();
89+
90+
expect(container).toMatchInlineSnapshot(`<div />`);
91+
});
92+
93+
it('mount() works for the `create space` page', async () => {
94+
const basePath = '/some-base-path/spaces';
95+
window.location.hash = `${basePath}/create`;
96+
97+
const { setBreadcrumbs, container, unmount } = await mountApp(basePath);
98+
99+
expect(setBreadcrumbs).toHaveBeenCalledTimes(1);
100+
expect(setBreadcrumbs).toHaveBeenCalledWith([
101+
{ href: `#${basePath}`, text: 'Spaces' },
102+
{ text: 'Create' },
103+
]);
104+
expect(container).toMatchInlineSnapshot(`
105+
<div>
106+
Spaces Edit Page: {"capabilities":{"catalogue":{},"management":{},"navLinks":{}},"http":{"basePath":{"basePath":""},"anonymousPaths":{}},"notifications":{"toasts":{}},"spacesManager":{"onActiveSpaceChange$":{"_isScalar":false}},"securityEnabled":true}
107+
</div>
108+
`);
109+
110+
unmount();
111+
112+
expect(container).toMatchInlineSnapshot(`<div />`);
113+
});
114+
115+
it('mount() works for the `edit space` page', async () => {
116+
const basePath = '/some-base-path/spaces';
117+
const spaceId = 'some-space';
118+
window.location.hash = `${basePath}/edit/${spaceId}`;
119+
120+
const { setBreadcrumbs, container, unmount } = await mountApp(basePath, spaceId);
121+
122+
expect(setBreadcrumbs).toHaveBeenCalledTimes(1);
123+
expect(setBreadcrumbs).toHaveBeenCalledWith([
124+
{ href: `#${basePath}`, text: 'Spaces' },
125+
{ href: `#/some-base-path/spaces/edit/${spaceId}`, text: `space with id some-space` },
126+
]);
127+
expect(container).toMatchInlineSnapshot(`
128+
<div>
129+
Spaces Edit Page: {"capabilities":{"catalogue":{},"management":{},"navLinks":{}},"http":{"basePath":{"basePath":""},"anonymousPaths":{}},"notifications":{"toasts":{}},"spacesManager":{"onActiveSpaceChange$":{"_isScalar":false}},"spaceId":"some-space","securityEnabled":true}
130+
</div>
131+
`);
132+
133+
unmount();
134+
135+
expect(container).toMatchInlineSnapshot(`<div />`);
136+
});
137+
});

x-pack/plugins/spaces/public/management/spaces_management_app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export const spacesManagementApp = Object.freeze({
113113
<Route path="/create">
114114
<CreateSpacePageWithBreadcrumbs />
115115
</Route>
116-
<Route path="/edit/:spaceId?">
116+
<Route path="/edit/:spaceId">
117117
<EditSpacePageWithBreadcrumbs />
118118
</Route>
119119
</Switch>

0 commit comments

Comments
 (0)