Skip to content

Commit

Permalink
Navigate to import_sample_data app when navGroupEnabled (#457)
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Wang <[email protected]>
  • Loading branch information
wanglam authored Oct 21, 2024
1 parent 017e1dc commit d01d2ff
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Create index component Renders create index component 1`] = `
<CreateIndex>
<CreateIndex
application={
Object {
"navigateToApp": [MockFunction],
}
}
chrome={
Object {
"navGroup": Object {
"getNavGroupEnabled": [MockFunction] {
"calls": Array [
Array [],
],
"results": Array [
Object {
"type": "return",
"value": false,
},
],
},
},
}
}
>
<Header>
<EuiPanel
borderRadius="none"
Expand Down Expand Up @@ -105,12 +128,14 @@ exports[`Create index component Renders create index component 1`] = `
>
Learn how to index your data
</EuiLink>
, or
, or
<EuiLink
href="/app/home#/tutorial_directory"
>
add sample data
add sample data
</EuiLink>
to OpenSearch Dashboards.
</p>
}
Expand Down Expand Up @@ -209,7 +234,8 @@ exports[`Create index component Renders create index component 1`] = `
</EuiScreenReaderOnly>
</a>
</EuiLink>
, or
, or
<EuiLink
href="/app/home#/tutorial_directory"
>
Expand All @@ -218,9 +244,10 @@ exports[`Create index component Renders create index component 1`] = `
href="/app/home#/tutorial_directory"
rel="noreferrer"
>
add sample data
add sample data
</a>
</EuiLink>
to OpenSearch Dashboards.
</p>
</div>
Expand Down
31 changes: 29 additions & 2 deletions public/components/query_compare/__test__/create_index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,46 @@
import { configure, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import React from 'react';
import { waitFor } from '@testing-library/react';
import { fireEvent, render, waitFor } from '@testing-library/react';
import { CreateIndex } from '../create_index';

const coreMockStart = {
chrome: {
navGroup: {
getNavGroupEnabled: jest.fn(() => false),
},
},
application: {
navigateToApp: jest.fn(),
},
};

describe('Create index component', () => {
configure({ adapter: new Adapter() });

beforeEach(() => {
jest.clearAllMocks();
});

it('Renders create index component', async () => {
const wrapper = mount(<CreateIndex />);
const wrapper = mount(
<CreateIndex chrome={coreMockStart.chrome} application={coreMockStart.application} />
);

wrapper.update();

await waitFor(() => {
expect(wrapper).toMatchSnapshot();
});
});

it('should call application.navigateToApp', async () => {
coreMockStart.chrome.navGroup.getNavGroupEnabled.mockReturnValue(true);
const { getByText } = render(
<CreateIndex chrome={coreMockStart.chrome} application={coreMockStart.application} />
);

fireEvent.click(getByText('add sample data'));
expect(coreMockStart.application.navigateToApp).toHaveBeenLastCalledWith('import_sample_data');
});
});
24 changes: 21 additions & 3 deletions public/components/query_compare/create_index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ import React from 'react';
import { EuiPageBody, EuiEmptyPrompt, EuiLink } from '@elastic/eui';

import { Header } from '../common/header';
import { CoreStart } from '../../../../../src/core/public';

export const CreateIndex = () => {
interface CreateIndexProps {
chrome: CoreStart['chrome'];
application: CoreStart['application'];
}

export const CreateIndex = ({ chrome, application }: CreateIndexProps) => {
const navGroupEnabled = chrome.navGroup.getNavGroupEnabled();
return (
<>
<Header />
Expand All @@ -24,8 +31,19 @@ export const CreateIndex = () => {
>
Learn how to index your data
</EuiLink>
, or <EuiLink href="/app/home#/tutorial_directory">add sample data </EuiLink>to
OpenSearch Dashboards.
, or{' '}
<EuiLink
{...(navGroupEnabled
? {
onClick: () => {
application.navigateToApp('import_sample_data');
},
}
: { href: '/app/home#/tutorial_directory' })}
>
add sample data
</EuiLink>{' '}
to OpenSearch Dashboards.
</p>
}
/>
Expand Down
3 changes: 1 addition & 2 deletions public/components/query_compare/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
} from '../../../../../src/plugins/data_source_management/public/components/data_source_menu/types';
import * as pluginManifest from '../../../opensearch_dashboards.json';
import './home.scss';
import { uiSettingsService } from '../common/utils';

interface QueryExplorerProps {
parentBreadCrumbs: ChromeBreadcrumb[];
Expand Down Expand Up @@ -155,7 +154,7 @@ export const Home = ({
<>
<div className="osdOverviewWrapper">
{shouldShowCreateIndex ? (
<CreateIndex />
<CreateIndex application={application} chrome={chrome} />
) : (
<SearchResult
application={application}
Expand Down

0 comments on commit d01d2ff

Please sign in to comment.