-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moving the functionality to workspace_route
- Loading branch information
Showing
5 changed files
with
109 additions
and
35 deletions.
There are no files selected for viewing
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
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
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
75 changes: 75 additions & 0 deletions
75
x-pack/plugins/graph/public/helpers/use_workspace_loader.test.tsx
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,75 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { useWorkspaceLoader, UseWorkspaceLoaderProps } from './use_workspace_loader'; | ||
import { coreMock } from 'src/core/public/mocks'; | ||
import { spacesPluginMock } from '../../../spaces/public/mocks'; | ||
import { createMockGraphStore } from '../state_management/mocks'; | ||
import { Workspace } from '../types'; | ||
import { SavedObjectsClientCommon } from 'src/plugins/data/common'; | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
useHistory: () => ({ | ||
replace: jest.fn(), | ||
}), | ||
useLocation: () => ({ | ||
location: jest.fn(), | ||
}), | ||
useParams: () => ({ | ||
id: jest.fn(), | ||
}), | ||
})); | ||
|
||
jest.mock('React', () => ({ | ||
...jest.requireActual('React'), | ||
useEffect: jest.fn(), | ||
})); | ||
|
||
const mockSavedObjectsClient = ({ | ||
resolve: jest.fn().mockResolvedValue({ | ||
saved_object: { id: 10, _version: '7.15.0', attributes: { wsState: '{}' } }, | ||
outcome: 'aliasMatch', | ||
alias_target_id: 'aliasTargetId', | ||
}), | ||
find: jest.fn().mockResolvedValue({ title: 'test' }), | ||
} as unknown) as SavedObjectsClientCommon; | ||
|
||
async function setup(props: UseWorkspaceLoaderProps) { | ||
const returnVal = {}; | ||
function TestComponent() { | ||
Object.assign(returnVal, useWorkspaceLoader(props)); | ||
return null; | ||
} | ||
await act(async () => { | ||
const promise = Promise.resolve(); | ||
mount(<TestComponent />); | ||
await act(() => promise); | ||
}); | ||
return returnVal; | ||
} | ||
|
||
describe('use_workspace_loader', () => { | ||
const defaultProps = { | ||
workspaceRef: { current: {} as Workspace }, | ||
store: createMockGraphStore({}).store, | ||
savedObjectsClient: mockSavedObjectsClient, | ||
coreStart: coreMock.createStart(), | ||
spaces: spacesPluginMock.createStartContract(), | ||
}; | ||
|
||
it('should redirect if outcome is aliasMatch', async () => { | ||
await act(async () => { | ||
await setup((defaultProps as unknown) as UseWorkspaceLoaderProps); | ||
}); | ||
expect(defaultProps.spaces.ui.redirectLegacyUrl).toHaveBeenCalledWith( | ||
'#/workspace/aliasTargetId', | ||
'Graph' | ||
); | ||
}); | ||
}); |
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