Skip to content

Commit

Permalink
Fix Test failures
Browse files Browse the repository at this point in the history
Signed-off-by: Suchit Sahoo <[email protected]>
  • Loading branch information
LDrago27 committed Sep 5, 2024
1 parent e794db9 commit 60536f1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import React from 'react';
import * as sinon from 'sinon';
import { SavedObjectFinderUi as SavedObjectFinder } from './saved_object_finder';
import { coreMock } from '../../../../core/public/mocks';
import { of } from 'rxjs';

describe('SavedObjectsFinder', () => {
const doc = {
Expand Down Expand Up @@ -79,16 +80,20 @@ describe('SavedObjectsFinder', () => {
Promise.resolve({ savedObjects: [doc] })
);
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
savedObjects={core.savedObjects}
uiSettings={core.uiSettings}
savedObjectMetaData={searchMetaData}
application={core.application}
/>
);
wrapper.instance().componentDidMount!();

await Promise.resolve();

expect(core.savedObjects.client.find).toHaveBeenCalledWith({
type: ['search'],
fields: ['title'],
Expand All @@ -106,17 +111,20 @@ describe('SavedObjectsFinder', () => {
Promise.resolve({ savedObjects: [doc] })
);
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
savedObjects={core.savedObjects}
uiSettings={core.uiSettings}
savedObjectMetaData={searchMetaData}
application={core.application}
/>
);

wrapper.instance().componentDidMount!();
await nextTick();
await Promise.resolve();
expect(
wrapper.containsMatchingElement(<EuiListGroupItem iconType="search" label="Example title" />)
).toEqual(true);
Expand All @@ -129,18 +137,21 @@ describe('SavedObjectsFinder', () => {
Promise.resolve({ savedObjects: [doc] })
);
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
savedObjects={core.savedObjects}
uiSettings={core.uiSettings}
onChoose={chooseStub}
savedObjectMetaData={searchMetaData}
application={core.application}
/>
);

wrapper.instance().componentDidMount!();
await nextTick();
await Promise.resolve();
wrapper.find(EuiListGroupItem).first().simulate('click');
expect(chooseStub.calledWith('1', 'search', `${doc.attributes.title} (Search)`, doc)).toEqual(
true
Expand All @@ -154,16 +165,20 @@ describe('SavedObjectsFinder', () => {
Promise.resolve({ savedObjects: [doc, doc2] })
);
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
savedObjects={core.savedObjects}
uiSettings={core.uiSettings}
savedObjectMetaData={searchMetaData}
application={core.application}
/>
);
wrapper.instance().componentDidMount!();
await nextTick();
await Promise.resolve();

const list = wrapper.find(EuiListGroup);
expect(list.childAt(0).key()).toBe('2');
expect(list.childAt(1).key()).toBe('1');
Expand All @@ -175,12 +190,14 @@ describe('SavedObjectsFinder', () => {
Promise.resolve({ savedObjects: [doc, doc2] })
);
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
savedObjects={core.savedObjects}
uiSettings={core.uiSettings}
savedObjectMetaData={searchMetaData}
application={core.application}
/>
);

Expand All @@ -199,6 +216,7 @@ describe('SavedObjectsFinder', () => {
Promise.resolve({ savedObjects: [doc, doc2] })
);
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
Expand All @@ -212,6 +230,7 @@ describe('SavedObjectsFinder', () => {
showSavedObject: ({ id }) => id !== '1',
},
]}
application={core.application}
/>
);

Expand All @@ -229,12 +248,14 @@ describe('SavedObjectsFinder', () => {
Promise.resolve({ savedObjects: [doc, doc2] })
);
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
savedObjects={core.savedObjects}
uiSettings={core.uiSettings}
savedObjectMetaData={searchMetaData}
application={core.application}
/>
);
wrapper.instance().componentDidMount!();
Expand All @@ -258,6 +279,7 @@ describe('SavedObjectsFinder', () => {
it('should include additional fields in search if listed in meta data', async () => {
const core = coreMock.createStart();
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');
(core.savedObjects.client.find as jest.Mock).mockResolvedValue({ savedObjects: [] });

const wrapper = shallow(
Expand All @@ -278,6 +300,7 @@ describe('SavedObjectsFinder', () => {
includeFields: ['field2', 'field3'],
},
]}
application={core.application}
/>
);
wrapper.instance().componentDidMount!();
Expand All @@ -304,12 +327,14 @@ describe('SavedObjectsFinder', () => {
Promise.resolve({ savedObjects: [doc, doc2] })
);
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
savedObjects={core.savedObjects}
uiSettings={core.uiSettings}
savedObjectMetaData={searchMetaData}
application={core.application}
/>
);

Expand All @@ -332,6 +357,7 @@ describe('SavedObjectsFinder', () => {
Promise.resolve({ savedObjects: [doc, doc2] })
);
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
Expand All @@ -349,6 +375,7 @@ describe('SavedObjectsFinder', () => {
getIconForSavedObject: () => 'visLine',
},
]}
application={core.application}
/>
);
wrapper.instance().componentDidMount!();
Expand Down Expand Up @@ -386,13 +413,15 @@ describe('SavedObjectsFinder', () => {
})
);
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
savedObjects={core.savedObjects}
uiSettings={core.uiSettings}
showFilter={false}
savedObjectMetaData={metaDataConfig}
application={core.application}
/>
);

Expand All @@ -411,13 +440,15 @@ describe('SavedObjectsFinder', () => {
})
);
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
savedObjects={core.savedObjects}
uiSettings={core.uiSettings}
showFilter={true}
savedObjectMetaData={metaDataConfig}
application={core.application}
/>
);

Expand All @@ -436,13 +467,15 @@ describe('SavedObjectsFinder', () => {
})
);
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
savedObjects={core.savedObjects}
uiSettings={core.uiSettings}
showFilter={true}
savedObjectMetaData={metaDataConfig}
application={core.application}
/>
);

Expand All @@ -464,6 +497,7 @@ describe('SavedObjectsFinder', () => {
Promise.resolve({ savedObjects: [] })
);
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');

const noItemsMessage = <span id="myNoItemsMessage" />;
const wrapper = shallow(
Expand All @@ -472,6 +506,7 @@ describe('SavedObjectsFinder', () => {
uiSettings={core.uiSettings}
noItemsMessage={noItemsMessage}
savedObjectMetaData={searchMetaData}
application={core.application}
/>
);
wrapper.instance().componentDidMount!();
Expand All @@ -495,13 +530,15 @@ describe('SavedObjectsFinder', () => {
Promise.resolve({ savedObjects: longItemList })
);
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
savedObjects={core.savedObjects}
uiSettings={core.uiSettings}
initialPageSize={15}
savedObjectMetaData={searchMetaData}
application={core.application}
/>
);

Expand All @@ -517,13 +554,15 @@ describe('SavedObjectsFinder', () => {
Promise.resolve({ savedObjects: longItemList })
);
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
savedObjects={core.savedObjects}
uiSettings={core.uiSettings}
initialPageSize={15}
savedObjectMetaData={searchMetaData}
application={core.application}
/>
);

Expand All @@ -539,13 +578,15 @@ describe('SavedObjectsFinder', () => {
Promise.resolve({ savedObjects: longItemList })
);
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
savedObjects={core.savedObjects}
uiSettings={core.uiSettings}
initialPageSize={15}
savedObjectMetaData={searchMetaData}
application={core.application}
/>
);

Expand All @@ -561,13 +602,15 @@ describe('SavedObjectsFinder', () => {
Promise.resolve({ savedObjects: longItemList })
);
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
savedObjects={core.savedObjects}
uiSettings={core.uiSettings}
fixedPageSize={33}
savedObjectMetaData={searchMetaData}
application={core.application}
/>
);

Expand All @@ -583,13 +626,15 @@ describe('SavedObjectsFinder', () => {
Promise.resolve({ savedObjects: longItemList })
);
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
savedObjects={core.savedObjects}
uiSettings={core.uiSettings}
fixedPageSize={33}
savedObjectMetaData={searchMetaData}
application={core.application}
/>
);

Expand All @@ -604,12 +649,14 @@ describe('SavedObjectsFinder', () => {
it('should display a spinner during initial loading', () => {
const core = coreMock.createStart();
(core.savedObjects.client.find as jest.Mock).mockResolvedValue({ savedObjects: [] });
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
savedObjects={core.savedObjects}
uiSettings={core.uiSettings}
savedObjectMetaData={searchMetaData}
application={core.application}
/>
);

Expand All @@ -621,6 +668,7 @@ describe('SavedObjectsFinder', () => {
((core.savedObjects.client.find as any) as jest.SpyInstance).mockImplementation(() =>
Promise.resolve({ savedObjects: [doc] })
);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
Expand All @@ -633,6 +681,7 @@ describe('SavedObjectsFinder', () => {
getIconForSavedObject: () => 'search',
},
]}
application={core.application}
/>
);

Expand All @@ -646,12 +695,14 @@ describe('SavedObjectsFinder', () => {
((core.savedObjects.client.find as any) as jest.SpyInstance).mockImplementation(() =>
Promise.resolve({ savedObjects: [doc] })
);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
savedObjects={core.savedObjects}
uiSettings={core.uiSettings}
savedObjectMetaData={searchMetaData}
application={core.application}
/>
);

Expand All @@ -674,6 +725,7 @@ describe('SavedObjectsFinder', () => {
Promise.resolve({ savedObjects: [doc, doc2] })
);
core.uiSettings.get.mockImplementation(() => 10);
core.application.currentAppId$ = of('data-explorer');

const wrapper = shallow(
<SavedObjectFinder
Expand All @@ -691,6 +743,7 @@ describe('SavedObjectsFinder', () => {
getIconForSavedObject: () => 'visLine',
},
]}
application={core.application}
>
<button id="testChildButton">Dummy text</button>
</SavedObjectFinder>
Expand Down
Loading

0 comments on commit 60536f1

Please sign in to comment.