Skip to content

Commit

Permalink
Fix some tests/types
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasolson committed May 17, 2023
1 parent 588a99b commit 67b335f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import React from 'react';
import { EuiButton, EuiEmptyPrompt, EuiLoadingSpinner } from '@elastic/eui';
import { mountWithIntl } from '@kbn/test-jest-helpers';
import * as useUiSettingHook from '@kbn/kibana-react-plugin/public/ui_settings/use_ui_setting';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { CodeEditor, KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import type { DataView } from '@kbn/data-views-plugin/public';
import * as hooks from '../../hooks/use_es_doc_search';
import { useEsDocSearch } from '@kbn/unified-doc-viewer-plugin/public';
import { buildDataTableRecord } from '@kbn/discover-plugin/public/utils/build_data_record';
import { JsonCodeEditorCommon } from '../..';
import { ElasticRequestState, JsonCodeEditorCommon } from '../..';
import { DocViewerSource } from './source';

const hooks = { useEsDocSearch };

const mockDataView = {
getComputedFields: () => [],
} as never;
Expand All @@ -40,15 +42,16 @@ const services = {
describe('Source Viewer component', () => {
test('renders loading state', () => {
jest.spyOn(hooks, 'useEsDocSearch').mockImplementation(() => [0, null, () => {}]);

const comp = mountWithIntl(
<KibanaContextProvider services={services}>
<DocViewerSource
id={'1'}
index={'index1'}
dataView={mockDataView}
CodeEditor={CodeEditor}
width={123}
hasLineNumbers={true}
useDocExplorer={false}
requestState={ElasticRequestState.Loading}
hit={null}
onRefresh={() => {}}
/>
</KibanaContextProvider>
);
Expand All @@ -58,15 +61,16 @@ describe('Source Viewer component', () => {

test('renders error state', () => {
jest.spyOn(hooks, 'useEsDocSearch').mockImplementation(() => [3, null, () => {}]);

const comp = mountWithIntl(
<KibanaContextProvider services={services}>
<DocViewerSource
id={'1'}
index={'index1'}
dataView={mockDataView}
CodeEditor={CodeEditor}
width={123}
hasLineNumbers={true}
useDocExplorer={false}
requestState={ElasticRequestState.Error}
hit={null}
onRefresh={() => {}}
/>
</KibanaContextProvider>
);
Expand Down Expand Up @@ -101,11 +105,13 @@ describe('Source Viewer component', () => {
const comp = mountWithIntl(
<KibanaContextProvider services={services}>
<DocViewerSource
id={'1'}
index={'index1'}
dataView={mockDataView}
CodeEditor={CodeEditor}
width={123}
hasLineNumbers={true}
useDocExplorer={false}
requestState={ElasticRequestState.Found}
hit={mockHit}
onRefresh={() => {}}
/>
</KibanaContextProvider>
);
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import { Doc, DocProps } from './doc';
import { SEARCH_FIELDS_FROM_SOURCE as mockSearchFieldsFromSource } from '../../../../common';
import { dataViewMock } from '../../../__mocks__/data_view';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import {
DocViewsRegistry,
setDocViewsRegistry,
} from '@kbn/unified-doc-viewer-plugin/public/services';

const mockSearchApi = jest.fn();

Expand Down Expand Up @@ -102,6 +106,8 @@ async function mountDoc(update = false) {
}

describe('Test of <Doc /> of Discover', () => {
setDocViewsRegistry(new DocViewsRegistry());

test('renders loading msg', async () => {
const comp = await mountDoc();
expect(findTestSubject(comp, 'doc-msg-loading').length).toBe(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ describe('Discover grid cell rendering', function () {
</EuiFlexItem>
<EuiFlexItem>
<JsonCodeEditor
CodeEditor={[Function]}
height={200}
json={
Object {
Expand Down Expand Up @@ -514,6 +515,7 @@ describe('Discover grid cell rendering', function () {
</EuiFlexItem>
<EuiFlexItem>
<JsonCodeEditor
CodeEditor={[Function]}
height={200}
json={
Object {
Expand Down Expand Up @@ -678,6 +680,7 @@ describe('Discover grid cell rendering', function () {
</EuiFlexItem>
<EuiFlexItem>
<JsonCodeEditor
CodeEditor={[Function]}
height={200}
json={
Object {
Expand Down

0 comments on commit 67b335f

Please sign in to comment.