From 80bed72a6c66dacde6f9f1591f7c348a0a5aeb4f Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Fri, 8 Mar 2024 09:54:39 +0800 Subject: [PATCH] fix: unit test error Signed-off-by: SuZhou-Joe --- src/core/public/http/http_service.test.ts | 33 ++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/core/public/http/http_service.test.ts b/src/core/public/http/http_service.test.ts index 5671064e4c52..c6301b26d1d1 100644 --- a/src/core/public/http/http_service.test.ts +++ b/src/core/public/http/http_service.test.ts @@ -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( () => @@ -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()', () => {