-
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.
Refactor search bar & filters to conditionally render with new applic…
…ation header Signed-off-by: Zhongnan Su <[email protected]>
- Loading branch information
1 parent
265a176
commit 1b0be09
Showing
9 changed files
with
636 additions
and
396 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
99 changes: 99 additions & 0 deletions
99
src/plugins/data/public/ui/filter_bar/filter_options.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,99 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React from 'react'; | ||
import { FilterOptions } from './filter_options'; | ||
import { SavedQueryAttributes } from '../../query'; | ||
import { mountWithIntl } from 'test_utils/enzyme_helpers'; | ||
import { Query } from 'src/plugins/data/common'; | ||
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public'; | ||
import { act } from 'test_utils/testing_lib_helpers'; | ||
|
||
// Mock useOpenSearchDashboards hook | ||
jest.mock('../../../../opensearch_dashboards_react/public', () => ({ | ||
useOpenSearchDashboards: jest.fn(), | ||
withOpenSearchDashboards: (Component: any) => (props: any) => <Component {...props} />, | ||
})); | ||
|
||
const mockProps = () => ({ | ||
savedQueryService: { | ||
saveQuery: jest.fn(), | ||
getAllSavedQueries: jest.fn(), | ||
findSavedQueries: jest.fn(), | ||
getSavedQuery: jest.fn(), | ||
deleteSavedQuery: jest.fn(), | ||
getSavedQueryCount: jest.fn(), | ||
}, | ||
onSave: jest.fn(), | ||
onSaveAsNew: jest.fn(), | ||
onLoad: jest.fn(), | ||
onClearSavedQuery: jest.fn(), | ||
onFiltersUpdated: jest.fn(), | ||
showSaveQuery: true, | ||
loadedSavedQuery: { | ||
id: '1', | ||
attributes: { | ||
name: 'Test Query', | ||
title: '', | ||
description: '', | ||
query: { query: '', language: 'kuery' } as Query, | ||
} as SavedQueryAttributes, | ||
}, | ||
filters: [], | ||
indexPatterns: [], | ||
useSaveQueryMenu: false, | ||
}); | ||
|
||
describe('FilterOptions', () => { | ||
beforeEach(() => { | ||
// Mocking `uiSettings.get` to return true for `useNewHeader` | ||
(useOpenSearchDashboards as jest.Mock).mockReturnValue({ | ||
services: { | ||
uiSettings: { | ||
get: jest.fn((key) => { | ||
if (key === 'home:useNewHomePage') { | ||
return true; | ||
} | ||
return false; // Return a default value for other keys | ||
}), | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('render menu panel', () => { | ||
const wrapper = mountWithIntl(<FilterOptions {...mockProps()} />); | ||
const button = wrapper.find('[data-test-subj="showFilterActions"]').at(0); | ||
|
||
button.simulate('click'); | ||
expect(wrapper.find('[data-test-subj="filter-options-menu-panel"]').exists()).toBeTruthy(); | ||
}); | ||
|
||
it("render filter options with 'Add filter' button", () => { | ||
const wrapper = mountWithIntl(<FilterOptions {...mockProps()} />); | ||
const button = wrapper.find('[data-test-subj="showFilterActions"]').at(0); | ||
button.simulate('click'); | ||
wrapper.update(); | ||
const addFilterButton = wrapper.find('[data-test-subj="addFilters"]').at(0); | ||
addFilterButton.simulate('click'); | ||
expect(wrapper.find('[data-test-subj="add-filter-panel"]').exists()).toBeTruthy(); | ||
}); | ||
|
||
it("render filter options with 'Save Query' button", () => { | ||
const wrapper = mountWithIntl(<FilterOptions {...mockProps()} />); | ||
const button = wrapper.find('[data-test-subj="showFilterActions"]').at(0); | ||
button.simulate('click'); | ||
wrapper.update(); | ||
const saveQueryButton = wrapper | ||
.find('[data-test-subj="saved-query-management-save-button"]') | ||
.at(0); | ||
saveQueryButton.simulate('click'); | ||
expect(wrapper.find('[data-test-subj="save-query-panel"]').exists()).toBeTruthy(); | ||
}); | ||
}); |
Oops, something went wrong.