Skip to content

Commit

Permalink
Fixed tests and added serverless check for spaces app
Browse files Browse the repository at this point in the history
  • Loading branch information
SiddharthMantri committed Aug 28, 2023
1 parent 56a3fd0 commit ec9e5d3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
30 changes: 25 additions & 5 deletions x-pack/plugins/spaces/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ import { SpacesPlugin } from './plugin';

describe('Spaces plugin', () => {
describe('#setup', () => {
it('should register the spaces API and the space selector app', () => {
it('should register the spaces API and the space selector app when buildFlavor is traditional', () => {
const coreSetup = coreMock.createSetup();
const mockInitializerContext = coreMock.createPluginInitializerContext();

const plugin = new SpacesPlugin(coreMock.createPluginInitializerContext());
// @ts-expect-error buildFlavor marked as readonly
mockInitializerContext.env.packageInfo.buildFlavor = 'traditional';

const plugin = new SpacesPlugin(mockInitializerContext);
plugin.setup(coreSetup, {});

expect(coreSetup.application.register).toHaveBeenCalledWith(
Expand All @@ -33,6 +37,22 @@ describe('Spaces plugin', () => {
);
});

it('should not register the spaces API and the space selector app when buildFlavor is serverless', () => {
const coreSetup = coreMock.createSetup();

const plugin = new SpacesPlugin(coreMock.createPluginInitializerContext());
plugin.setup(coreSetup, {});

expect(coreSetup.application.register).not.toHaveBeenCalledWith(
expect.objectContaining({
id: 'space_selector',
chromeless: true,
appRoute: '/spaces/space_selector',
mount: expect.any(Function),
})
);
});

it('should register the management and feature catalogue sections when the management and home plugins are both available when buildFlavor is traditional', () => {
const coreSetup = coreMock.createSetup();
const home = homePluginMock.createSetupContract();
Expand Down Expand Up @@ -68,7 +88,7 @@ describe('Spaces plugin', () => {
);
});

it('should not register the management and feature catalogue sections when the management and home plugins are both available when buildFlavor is serverless', () => {
it('should not register spaces in the management plugin or the feature catalog when the management and home plugins are both available when buildFlavor is serverless', () => {
const coreSetup = coreMock.createSetup();
const home = homePluginMock.createSetupContract();

Expand Down Expand Up @@ -100,7 +120,7 @@ describe('Spaces plugin', () => {
});

describe('#start', () => {
it('should register the spaces nav control when build flavor is traditional', () => {
it('should register the spaces nav control when buildFlavor is traditional', () => {
const coreSetup = coreMock.createSetup();
const coreStart = coreMock.createStart();

Expand All @@ -117,7 +137,7 @@ describe('Spaces plugin', () => {
expect(coreStart.chrome.navControls.registerLeft).toHaveBeenCalled();
});

it('should not register the spaces nav control when build flavor is serverless', () => {
it('should not register the spaces nav control when buildFlavor is serverless', () => {
const coreSetup = coreMock.createSetup();
const coreStart = coreMock.createStart();

Expand Down
12 changes: 7 additions & 5 deletions x-pack/plugins/spaces/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ export class SpacesPlugin implements Plugin<SpacesPluginSetup, SpacesPluginStart
});
}

spaceSelectorApp.create({
getStartServices: core.getStartServices,
application: core.application,
spacesManager: this.spacesManager,
});
if (!this.isServerless) {
spaceSelectorApp.create({
getStartServices: core.getStartServices,
application: core.application,
spacesManager: this.spacesManager,
});
}

return {};
}
Expand Down

0 comments on commit ec9e5d3

Please sign in to comment.