-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit test for search use case overview page
Signed-off-by: Hailong Cui <[email protected]>
- Loading branch information
1 parent
81a179d
commit 51ca3b1
Showing
7 changed files
with
237 additions
and
8 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
78 changes: 78 additions & 0 deletions
78
src/plugins/home/public/application/components/usecase_overview/search_use_case_app.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,78 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { coreMock } from '../../../../../../core/public/mocks'; | ||
import { OpenSearchDashboardsContextProvider } from '../../../../../opensearch_dashboards_react/public'; | ||
import { contentManagementPluginMocks } from '../../../../../content_management/public/mocks'; | ||
import { SearchUseCaseOverviewApp } from './search_use_case_app'; | ||
import { ContentManagementPluginStart } from '../../../../../content_management/public'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
import { WorkspaceObject } from 'opensearch-dashboards/public'; | ||
|
||
describe('<SearchUseCaseOverviewApp />', () => { | ||
const renderPageMock = jest.fn(); | ||
renderPageMock.mockReturnValue('dummy page'); | ||
const mock = { | ||
...contentManagementPluginMocks.createStartContract(), | ||
renderPage: renderPageMock, | ||
}; | ||
const coreStartMocks = coreMock.createStart(); | ||
|
||
function renderSearchUseCaseOverviewApp( | ||
contentManagement: ContentManagementPluginStart, | ||
services = { ...coreStartMocks } | ||
) { | ||
return ( | ||
<OpenSearchDashboardsContextProvider services={services}> | ||
<SearchUseCaseOverviewApp contentManagement={contentManagement} /> | ||
</OpenSearchDashboardsContextProvider> | ||
); | ||
} | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('render for workspace disabled case', () => { | ||
const { container } = render(renderSearchUseCaseOverviewApp(mock, coreStartMocks)); | ||
|
||
expect(container).toMatchInlineSnapshot(` | ||
<div> | ||
dummy page | ||
</div> | ||
`); | ||
|
||
expect(coreStartMocks.chrome.setBreadcrumbs).toHaveBeenCalledWith([ | ||
{ text: 'Search overview' }, | ||
]); | ||
expect(mock.renderPage).toBeCalledWith('search_overview'); | ||
}); | ||
|
||
it('render for workspace enabled case', () => { | ||
const coreStartMocksWithWorkspace = { | ||
...coreStartMocks, | ||
workspaces: { | ||
...coreStartMocks.workspaces, | ||
currentWorkspace$: new BehaviorSubject({ | ||
id: 'foo', | ||
name: 'foo ws', | ||
}), | ||
}, | ||
}; | ||
|
||
const { container } = render(renderSearchUseCaseOverviewApp(mock, coreStartMocksWithWorkspace)); | ||
|
||
expect(container).toMatchInlineSnapshot(` | ||
<div> | ||
dummy page | ||
</div> | ||
`); | ||
|
||
expect(coreStartMocks.chrome.setBreadcrumbs).toHaveBeenCalledWith([{ text: 'foo ws' }]); | ||
expect(mock.renderPage).toBeCalledWith('search_overview'); | ||
}); | ||
}); |
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
115 changes: 115 additions & 0 deletions
115
...lugins/home/public/application/components/usecase_overview/search_use_case_setup.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,115 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { coreMock } from '../../../../../../core/public/mocks'; | ||
import { contentManagementPluginMocks } from '../../../../../content_management/public/mocks'; | ||
import { registerContentToSearchUseCasePage, setupSearchUseCase } from './search_use_case_setup'; | ||
|
||
describe('Search use case setup', () => { | ||
const coreStart = coreMock.createStart(); | ||
const registerContentProviderMock = jest.fn(); | ||
const registerPageMock = jest.fn(); | ||
|
||
const contentManagementSetupMock = { | ||
...contentManagementPluginMocks.createSetupContract(), | ||
registerPage: registerPageMock, | ||
}; | ||
|
||
const contentManagementStartMock = { | ||
...contentManagementPluginMocks.createStartContract(), | ||
registerContentProvider: registerContentProviderMock, | ||
}; | ||
|
||
it('setupSearchUseCase', () => { | ||
setupSearchUseCase(contentManagementSetupMock); | ||
expect(registerPageMock).toHaveBeenCalledTimes(1); | ||
|
||
const call = registerPageMock.mock.calls[0]; | ||
expect(call[0]).toMatchInlineSnapshot(` | ||
Object { | ||
"id": "search_overview", | ||
"sections": Array [ | ||
Object { | ||
"id": "get_started", | ||
"kind": "card", | ||
"order": 1000, | ||
"title": "Set up search", | ||
}, | ||
Object { | ||
"columns": 2, | ||
"grid": true, | ||
"id": "different_search_types", | ||
"kind": "card", | ||
"order": 2000, | ||
"title": "Try out different search techniques", | ||
}, | ||
Object { | ||
"columns": 2, | ||
"grid": true, | ||
"id": "config_evaluate_search", | ||
"kind": "card", | ||
"order": 3000, | ||
"title": "Configure and evaluate search", | ||
}, | ||
], | ||
"title": "Overview", | ||
} | ||
`); | ||
}); | ||
|
||
it('registerContentToSearchUseCasePage', () => { | ||
registerContentToSearchUseCasePage(contentManagementStartMock, coreStart); | ||
|
||
const call = registerContentProviderMock.mock.calls[0]; | ||
expect(call[0].getTargetArea()).toEqual('search_overview/get_started'); | ||
expect(call[0].getContent()).toMatchInlineSnapshot(` | ||
Object { | ||
"cardProps": Object { | ||
"selectable": Object { | ||
"children": <EuiI18n | ||
default="Documentation" | ||
token="home.searchOverview.setup.accessSearch.footer" | ||
/>, | ||
"isSelected": false, | ||
"onClick": [Function], | ||
}, | ||
}, | ||
"description": "You can run a search using REST API or language client. For experimentation, you can also run queries interactively.", | ||
"id": "access_search_functionality", | ||
"kind": "card", | ||
"order": 10, | ||
"title": "Access search functionality", | ||
} | ||
`); | ||
|
||
// search type section | ||
const searchTypesCall = registerContentProviderMock.mock.calls[2]; | ||
expect(searchTypesCall[0].getTargetArea()).toEqual('search_overview/different_search_types'); | ||
expect(searchTypesCall[0].getContent()).toMatchInlineSnapshot(` | ||
Object { | ||
"cardProps": Object { | ||
"children": <div | ||
className="euiCard__footer" | ||
> | ||
<EuiLink | ||
external={true} | ||
href="https://opensearch.org/docs/latest/query-dsl/full-text/query-string/" | ||
target="_blank" | ||
> | ||
View Documentation | ||
</EuiLink> | ||
</div>, | ||
"layout": "horizontal", | ||
}, | ||
"description": "Lexical or keyword search matches documents based on exact words or phrases. Search the text using human-friendly query string query syntax or create complex, customizable queries using Query DSL—the OpenSearch query language.", | ||
"getIcon": [Function], | ||
"id": "text_search", | ||
"kind": "card", | ||
"order": 10, | ||
"title": "Text search", | ||
} | ||
`); | ||
}); | ||
}); |
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