-
Notifications
You must be signed in to change notification settings - Fork 891
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 new look with a…
…pplication header (#7687) (#7719) * Refactor search bar & filters to conditionally render with new application header * add more test coverage * address comments * Changeset file for PR #7687 created/updated --------- (cherry picked from commit 97ddd8a) Signed-off-by: Zhongnan Su <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
32c8ccf
commit b3078c4
Showing
10 changed files
with
731 additions
and
400 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
refactor: | ||
- Refactor search bar & filters to conditionally render new look with application header ([#7687](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7687)) |
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
188 changes: 188 additions & 0 deletions
188
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,188 @@ | ||
/* | ||
* 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'; | ||
|
||
// 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().mockResolvedValue({ total: 0, queries: [] }), | ||
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: [ | ||
{ | ||
meta: { | ||
alias: null, | ||
disabled: false, | ||
negate: false, | ||
}, | ||
}, | ||
], | ||
indexPatterns: [], | ||
useSaveQueryMenu: false, | ||
}); | ||
|
||
describe('Filter options menu', () => { | ||
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; | ||
}), | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
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); | ||
expect(saveQueryButton.exists()).toBeTruthy(); | ||
saveQueryButton.simulate('click'); | ||
expect(wrapper.find('[data-test-subj="save-query-panel"]').exists()).toBeTruthy(); | ||
}); | ||
|
||
it('should call onFiltersUpdated when enable all filters button is clicked', () => { | ||
const props = mockProps(); | ||
const wrapper = mountWithIntl(<FilterOptions {...props} />); | ||
const button = wrapper.find('[data-test-subj="showFilterActions"]').at(0); | ||
button.simulate('click'); | ||
wrapper.update(); | ||
const enableAllFiltersButton = wrapper.find('[data-test-subj="enableAllFilters"]').at(0); | ||
enableAllFiltersButton.simulate('click'); | ||
expect(props.onFiltersUpdated).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call onFiltersUpdated when disable all filters button is clicked', () => { | ||
const props = mockProps(); | ||
const wrapper = mountWithIntl(<FilterOptions {...props} />); | ||
const button = wrapper.find('[data-test-subj="showFilterActions"]').at(0); | ||
button.simulate('click'); | ||
wrapper.update(); | ||
const disableAllFiltersButton = wrapper.find('[data-test-subj="disableAllFilters"]').at(0); | ||
disableAllFiltersButton.simulate('click'); | ||
expect(props.onFiltersUpdated).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call onFiltersUpdated when pin all filters button is clicked', () => { | ||
const props = mockProps(); | ||
const wrapper = mountWithIntl(<FilterOptions {...props} />); | ||
const button = wrapper.find('[data-test-subj="showFilterActions"]').at(0); | ||
button.simulate('click'); | ||
wrapper.update(); | ||
const pinAllFiltersButton = wrapper.find('[data-test-subj="pinAllFilters"]').at(0); | ||
pinAllFiltersButton.simulate('click'); | ||
expect(props.onFiltersUpdated).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call onFiltersUpdated when unpin all filters button is clicked', () => { | ||
const props = mockProps(); | ||
const wrapper = mountWithIntl(<FilterOptions {...props} />); | ||
const button = wrapper.find('[data-test-subj="showFilterActions"]').at(0); | ||
button.simulate('click'); | ||
wrapper.update(); | ||
const unpinAllFiltersButton = wrapper.find('[data-test-subj="unpinAllFilters"]').at(0); | ||
unpinAllFiltersButton.simulate('click'); | ||
expect(props.onFiltersUpdated).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call onFiltersUpdated when Invert all filters button is clicked', () => { | ||
const props = mockProps(); | ||
const wrapper = mountWithIntl(<FilterOptions {...props} />); | ||
const button = wrapper.find('[data-test-subj="showFilterActions"]').at(0); | ||
button.simulate('click'); | ||
wrapper.update(); | ||
const invertAllFiltersButton = wrapper | ||
.find('[data-test-subj="invertInclusionAllFilters"]') | ||
.at(0); | ||
invertAllFiltersButton.simulate('click'); | ||
expect(props.onFiltersUpdated).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call onFiltersUpdated when Invert enabled/disabled filters button is clicked', () => { | ||
const props = mockProps(); | ||
const wrapper = mountWithIntl(<FilterOptions {...props} />); | ||
const button = wrapper.find('[data-test-subj="showFilterActions"]').at(0); | ||
button.simulate('click'); | ||
wrapper.update(); | ||
const invertEnabledDisabledFiltersButton = wrapper | ||
.find('[data-test-subj="invertEnableDisableAllFilters"]') | ||
.at(0); | ||
invertEnabledDisabledFiltersButton.simulate('click'); | ||
expect(props.onFiltersUpdated).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should call onFiltersUpdated when remove all filters button is clicked', () => { | ||
const props = mockProps(); | ||
const wrapper = mountWithIntl(<FilterOptions {...props} />); | ||
const button = wrapper.find('[data-test-subj="showFilterActions"]').at(0); | ||
button.simulate('click'); | ||
wrapper.update(); | ||
const removeAllFiltersButton = wrapper.find('[data-test-subj="removeAllFilters"]').at(0); | ||
removeAllFiltersButton.simulate('click'); | ||
expect(props.onFiltersUpdated).toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.