Skip to content

Commit

Permalink
fix: unit test error
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
  • Loading branch information
SuZhou-Joe committed Mar 8, 2024
1 parent 7ce20f1 commit 22d55b4
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/core/public/http/http_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('#setup()', () => {
expect(setupResult.basePath.get()).toEqual('');
});

it('setup basePath with workspaceId provided in window.location.href', () => {
it('setup basePath with workspaceId provided in window.location.href and workspace feature enabled', () => {
const windowSpy = jest.spyOn(window, 'window', 'get');
windowSpy.mockImplementation(
() =>
Expand All @@ -94,12 +94,43 @@ describe('#setup()', () => {
} as any)
);
const injectedMetadata = injectedMetadataServiceMock.createSetupContract();
injectedMetadata.getPlugins.mockReturnValueOnce([
{
id: 'workspace',
plugin: {
id: 'workspace',
configPath: '',
requiredPlugins: [],
optionalPlugins: [],
requiredEnginePlugins: {},
requiredBundles: [],
},
},
]);
const fatalErrors = fatalErrorsServiceMock.createSetupContract();
const httpService = new HttpService();
const setupResult = httpService.setup({ fatalErrors, injectedMetadata });
expect(setupResult.basePath.get()).toEqual('/w/workspaceId');
windowSpy.mockRestore();
});

it('setup basePath with workspaceId provided in window.location.href but workspace feature disabled', () => {
const windowSpy = jest.spyOn(window, 'window', 'get');
windowSpy.mockImplementation(
() =>
({
location: {
href: 'http://localhost/w/workspaceId/app',
},
} as any)
);
const injectedMetadata = injectedMetadataServiceMock.createSetupContract();
const fatalErrors = fatalErrorsServiceMock.createSetupContract();
const httpService = new HttpService();
const setupResult = httpService.setup({ fatalErrors, injectedMetadata });
expect(setupResult.basePath.get()).toEqual('');
windowSpy.mockRestore();
});
});

describe('#stop()', () => {
Expand Down

0 comments on commit 22d55b4

Please sign in to comment.