Skip to content

Commit

Permalink
[Graph] Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jughosta committed Jun 24, 2022
1 parent 29837d4 commit d7eff5e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
4 changes: 3 additions & 1 deletion x-pack/plugins/graph/public/components/search_bar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ describe('search_bar', () => {
const defaultProps = {
isLoading: false,
indexPatternProvider: {
get: jest.fn(() => Promise.resolve({ fields: [] } as unknown as DataView)),
get: jest.fn(() =>
Promise.resolve({ fields: [], getName: () => 'Test Name' } as unknown as DataView)
),
},
confirmWipeWorkspace: (callback: () => void) => {
callback();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import { useWorkspaceLoader, UseWorkspaceLoaderProps } from './use_workspace_loader';
import { coreMock } from '@kbn/core/public/mocks';
import { spacesPluginMock } from '@kbn/spaces-plugin/public/mocks';
import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
import { createMockGraphStore } from '../state_management/mocks';
import { Workspace } from '../types';
import { SavedObjectsClientCommon } from '@kbn/data-views-plugin/public';
import { renderHook, act, RenderHookOptions } from '@testing-library/react-hooks';
import type { SavedObjectsClientContract } from '@kbn/core/public';

jest.mock('react-router-dom', () => {
const useLocation = () => ({
Expand Down Expand Up @@ -40,13 +42,14 @@ const mockSavedObjectsClient = {
} as unknown as SavedObjectsClientCommon;

describe('use_workspace_loader', () => {
const defaultProps = {
const defaultProps: UseWorkspaceLoaderProps = {
workspaceRef: { current: {} as Workspace },
store: createMockGraphStore({}).store,
savedObjectsClient: mockSavedObjectsClient,
savedObjectsClient: mockSavedObjectsClient as unknown as SavedObjectsClientContract,
coreStart: coreMock.createStart(),
spaces: spacesPluginMock.createStartContract(),
} as unknown as UseWorkspaceLoaderProps;
data: dataPluginMock.createStartContract(),
};

it('should not redirect if outcome is exactMatch', async () => {
await act(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { useEffect, useState } from 'react';
import { useHistory, useLocation, useParams } from 'react-router-dom';
import { SavedObjectsClientContract } from '@kbn/core/public';
import type { SavedObjectsClientContract } from '@kbn/core/public';
import type { SavedObjectsResolveResponse } from '@kbn/core/public';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { i18n } from '@kbn/i18n';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* 2.0.
*/

import { GraphWorkspaceSavedObject, IndexPatternSavedObject, Workspace } from '../../types';
import { GraphWorkspaceSavedObject, Workspace } from '../../types';
import { migrateLegacyIndexPatternRef, savedWorkspaceToAppState, mapFields } from './deserialize';
import { createWorkspace } from '../workspace/graph_client_workspace';
import { outlinkEncoders } from '../../helpers/outlink_encoders';
import type { DataView } from '@kbn/data-views-plugin/public';
import type { DataView, DataViewListItem } from '@kbn/data-views-plugin/public';

describe('deserialize', () => {
let savedWorkspace: GraphWorkspaceSavedObject;
Expand Down Expand Up @@ -214,8 +214,8 @@ describe('deserialize', () => {
it('should migrate legacy index pattern ref', () => {
const workspacePayload = { ...savedWorkspace, legacyIndexPatternRef: 'Testpattern' };
const success = migrateLegacyIndexPatternRef(workspacePayload, [
{ id: '678', attributes: { title: 'Testpattern' } } as IndexPatternSavedObject,
{ id: '123', attributes: { title: 'otherpattern' } } as IndexPatternSavedObject,
{ id: '678', title: 'Testpattern' } as DataViewListItem,
{ id: '123', title: 'otherpattern' } as DataViewListItem,
]);
expect(success).toEqual({ success: true });
expect(workspacePayload.legacyIndexPatternRef).toBeUndefined();
Expand All @@ -225,7 +225,7 @@ describe('deserialize', () => {
it('should return false if migration fails', () => {
const workspacePayload = { ...savedWorkspace, legacyIndexPatternRef: 'Testpattern' };
const success = migrateLegacyIndexPatternRef(workspacePayload, [
{ id: '123', attributes: { title: 'otherpattern' } } as IndexPatternSavedObject,
{ id: '123', title: 'otherpattern' } as DataViewListItem,
]);
expect(success).toEqual({ success: false, missingIndexPattern: 'Testpattern' });
});
Expand Down

0 comments on commit d7eff5e

Please sign in to comment.