Skip to content

Commit 80bed72

Browse files
committed
fix: unit test error
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
1 parent 2e388a5 commit 80bed72

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/core/public/http/http_service.test.ts

+32-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('#setup()', () => {
8383
expect(setupResult.basePath.get()).toEqual('');
8484
});
8585

86-
it('setup basePath with workspaceId provided in window.location.href', () => {
86+
it('setup basePath with workspaceId provided in window.location.href and workspace feature enabled', () => {
8787
const windowSpy = jest.spyOn(window, 'window', 'get');
8888
windowSpy.mockImplementation(
8989
() =>
@@ -94,12 +94,43 @@ describe('#setup()', () => {
9494
} as any)
9595
);
9696
const injectedMetadata = injectedMetadataServiceMock.createSetupContract();
97+
injectedMetadata.getPlugins.mockReturnValueOnce([
98+
{
99+
id: 'workspace',
100+
plugin: {
101+
id: 'workspace',
102+
configPath: '',
103+
requiredPlugins: [],
104+
optionalPlugins: [],
105+
requiredEnginePlugins: {},
106+
requiredBundles: [],
107+
},
108+
},
109+
]);
97110
const fatalErrors = fatalErrorsServiceMock.createSetupContract();
98111
const httpService = new HttpService();
99112
const setupResult = httpService.setup({ fatalErrors, injectedMetadata });
100113
expect(setupResult.basePath.get()).toEqual('/w/workspaceId');
101114
windowSpy.mockRestore();
102115
});
116+
117+
it('setup basePath with workspaceId provided in window.location.href but workspace feature disabled', () => {
118+
const windowSpy = jest.spyOn(window, 'window', 'get');
119+
windowSpy.mockImplementation(
120+
() =>
121+
({
122+
location: {
123+
href: 'http://localhost/w/workspaceId/app',
124+
},
125+
} as any)
126+
);
127+
const injectedMetadata = injectedMetadataServiceMock.createSetupContract();
128+
const fatalErrors = fatalErrorsServiceMock.createSetupContract();
129+
const httpService = new HttpService();
130+
const setupResult = httpService.setup({ fatalErrors, injectedMetadata });
131+
expect(setupResult.basePath.get()).toEqual('');
132+
windowSpy.mockRestore();
133+
});
103134
});
104135

105136
describe('#stop()', () => {

0 commit comments

Comments
 (0)