forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: tygao <tygao@amazon.com>
- Loading branch information
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
src/plugins/workspace/public/components/utils/workspace.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { switchWorkspace, updateWorkspace } from './workspace'; | ||
import { formatUrlWithWorkspaceId } from '../../../../../core/public/utils'; | ||
jest.mock('../../../../../core/public/utils'); | ||
|
||
import { coreMock } from '../../../../../core/public/mocks'; | ||
|
||
const coreStartMock = coreMock.createStart(); | ||
|
||
window = Object.create(window); | ||
const defaultUrl = 'localhost://'; | ||
|
||
describe('workspace utils', () => { | ||
describe('switchWorkspace', () => { | ||
it('should redirect if newUrl is returned', () => { | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
href: defaultUrl, | ||
}, | ||
writable: true, | ||
}); | ||
// @ts-ignore | ||
formatUrlWithWorkspaceId.mockImplementation(() => 'new_url'); | ||
switchWorkspace({ application: coreStartMock.application, http: coreStartMock.http }, ''); | ||
expect(window.location.href).toEqual('new_url'); | ||
}); | ||
|
||
it('should not redirect if newUrl is not returned', () => { | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
href: defaultUrl, | ||
}, | ||
writable: true, | ||
}); | ||
// @ts-ignore | ||
formatUrlWithWorkspaceId.mockImplementation(() => ''); | ||
switchWorkspace({ application: coreStartMock.application, http: coreStartMock.http }, ''); | ||
expect(window.location.href).toEqual(defaultUrl); | ||
}); | ||
}); | ||
|
||
describe('updateWorkspace', () => { | ||
it('should redirect if newUrl is returned', () => { | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
href: defaultUrl, | ||
}, | ||
writable: true, | ||
}); | ||
// @ts-ignore | ||
formatUrlWithWorkspaceId.mockImplementation(() => 'new_url'); | ||
updateWorkspace({ application: coreStartMock.application, http: coreStartMock.http }, ''); | ||
expect(window.location.href).toEqual('new_url'); | ||
}); | ||
|
||
it('should not redirect if newUrl is not returned', () => { | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
href: defaultUrl, | ||
}, | ||
writable: true, | ||
}); | ||
// @ts-ignore | ||
formatUrlWithWorkspaceId.mockImplementation(() => ''); | ||
updateWorkspace({ application: coreStartMock.application, http: coreStartMock.http }, ''); | ||
expect(window.location.href).toEqual(defaultUrl); | ||
}); | ||
}); | ||
}); |