Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] [workspace] update search bar layout and align workspace selector #8687

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/8649.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Finetune search bar and workspace selector style ([#8649](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8649))
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@

.navGroupEnabledNavTopWrapper {
padding: 0 $euiSizeS;
padding-left: $euiSize;
padding-left: $euiSizeS;

.navGroupEnabledHomeIcon {
margin-left: $euiSizeS;
}
}

.searchBar-wrapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ export const CollapsibleNavTop = ({
<EuiFlexGroup responsive={false} justifyContent="spaceBetween">
{!shouldShrinkNavigation ? (
<EuiFlexItem grow={false}>
<EuiButtonEmpty flush="both" {...homeLinkProps} onClick={onIconClick}>
<EuiButtonEmpty
flush="both"
{...homeLinkProps}
onClick={onIconClick}
className="navGroupEnabledHomeIcon"
>
<EuiIcon
type={homeIcon}
size="xl"
Expand Down
66 changes: 42 additions & 24 deletions src/core/public/chrome/ui/header/header_search_bar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('<HeaderSearchBarIcon />', () => {
},
];

it('render HeaderSearchBarIcon correctly without search results', () => {
it('render HeaderSearchBarIcon correctly without search results', async () => {
const { getByTestId, queryByText } = render(
<HeaderSearchBarIcon globalSearchCommands={globalSearchCommands} />
);
Expand All @@ -34,22 +34,22 @@ describe('<HeaderSearchBarIcon />', () => {

fireEvent.click(searchIcon);

expect(getByTestId('search-input')).toBeVisible();
expect(getByTestId('global-search-input')).toBeVisible();

act(() => {
fireEvent.change(getByTestId('search-input'), {
fireEvent.change(getByTestId('global-search-input'), {
target: { value: 'index' },
});
});

expect(searchFn).toHaveBeenCalled();

waitFor(() => {
await waitFor(() => {
expect(queryByText('No results found.')).toBeInTheDocument();
});
});

it('render HeaderSearchBarIcon correctly with search results', () => {
it('render HeaderSearchBarIcon correctly with search results', async () => {
const { getByTestId, queryByText } = render(
<HeaderSearchBarIcon globalSearchCommands={globalSearchCommands} />
);
Expand All @@ -58,18 +58,18 @@ describe('<HeaderSearchBarIcon />', () => {

fireEvent.click(searchIcon);

expect(getByTestId('search-input')).toBeVisible();
expect(getByTestId('global-search-input')).toBeVisible();

searchFn.mockResolvedValue([<EuiText>index page</EuiText>]);
act(() => {
fireEvent.change(getByTestId('search-input'), {
fireEvent.change(getByTestId('global-search-input'), {
target: { value: 'index' },
});
});

expect(searchFn).toHaveBeenCalled();

waitFor(() => {
await waitFor(() => {
expect(queryByText('index page')).toBeInTheDocument();
});
});
Expand Down Expand Up @@ -109,97 +109,115 @@ describe('<HeaderSearchBar />', () => {
expect(searchPanel).toBeVisible();
});

it('render HeaderSearchBar with search result', () => {
it('render HeaderSearchBar with search input', async () => {
const { queryByTestId, getByTestId } = render(
<HeaderSearchBar globalSearchCommands={globalSearchCommands} />
);
const searchPanel = queryByTestId('search-result-panel');
expect(searchPanel).toBeNull();

// focus on search input
const searchInput = getByTestId('global-search-input');
expect(searchInput).toBeVisible();
searchInput.focus();

await waitFor(() => {
expect(queryByTestId('search-result-panel')).toBeVisible();
expect(queryByTestId('global-search-input')).toBeVisible();
});
});

it('render HeaderSearchBar with search result', async () => {
const { getByTestId, queryByText } = render(
<HeaderSearchBar globalSearchCommands={globalSearchCommands} panel />
);
const searchPanel = getByTestId('search-result-panel');
expect(searchPanel).toBeVisible();

expect(getByTestId('search-input')).toBeVisible();
expect(getByTestId('global-search-input')).toBeVisible();

searchFn.mockResolvedValue([<EuiText>index page</EuiText>]);
searchFnBar.mockResolvedValue([<EuiText>index polices</EuiText>]);
act(() => {
fireEvent.change(getByTestId('search-input'), {
fireEvent.change(getByTestId('global-search-input'), {
target: { value: 'index' },
});
});

expect(searchFn).toHaveBeenCalled();

// merge page results together
waitFor(() => {
await waitFor(() => {
expect(queryByText('index page')).toBeInTheDocument();
expect(queryByText('index polices')).toBeInTheDocument();
});
});

it('render HeaderSearchBar with reject search result', () => {
it('render HeaderSearchBar with reject search result', async () => {
const { getByTestId, queryByText } = render(
<HeaderSearchBar globalSearchCommands={globalSearchCommands} panel />
);
const searchPanel = getByTestId('search-result-panel');
expect(searchPanel).toBeVisible();

expect(getByTestId('search-input')).toBeVisible();
expect(getByTestId('global-search-input')).toBeVisible();

searchFn.mockResolvedValue([<EuiText>index page</EuiText>]);
searchFnBar.mockRejectedValue(new Error('Async search error'));

act(() => {
fireEvent.change(getByTestId('search-input'), {
fireEvent.change(getByTestId('global-search-input'), {
target: { value: 'index' },
});
});

expect(searchFn).toHaveBeenCalled();

// ignore reject and show pages for success search≠
waitFor(() => {
await waitFor(() => {
expect(queryByText('index page')).toBeInTheDocument();
});
});

it('render HeaderSearchBar with all reject search result', () => {
it('render HeaderSearchBar with all reject search result', async () => {
const { getByTestId, queryByText } = render(
<HeaderSearchBar globalSearchCommands={globalSearchCommands} panel />
);
const searchPanel = getByTestId('search-result-panel');
expect(searchPanel).toBeVisible();

expect(getByTestId('search-input')).toBeVisible();
expect(getByTestId('global-search-input')).toBeVisible();

searchFnBar.mockRejectedValue(new Error('Async search error'));
searchFn.mockRejectedValue(new Error('Async search error'));

act(() => {
fireEvent.change(getByTestId('search-input'), {
fireEvent.change(getByTestId('global-search-input'), {
target: { value: 'index' },
});
});

expect(searchFn).toHaveBeenCalled();

// show no result for all reject search
waitFor(() => {
await waitFor(() => {
expect(queryByText('No results found.')).toBeInTheDocument();
});
});

it('render HeaderSearchBar with search saved objects', () => {
it('render HeaderSearchBar with search saved objects', async () => {
const { getByTestId, queryByText } = render(
<HeaderSearchBar globalSearchCommands={globalSearchCommands} panel />
);
const searchPanel = getByTestId('search-result-panel');
expect(searchPanel).toBeVisible();

expect(getByTestId('search-input')).toBeVisible();
expect(getByTestId('global-search-input')).toBeVisible();

searchFnBaz.mockResolvedValue([<div>saved objects</div>]);

act(() => {
fireEvent.change(getByTestId('search-input'), {
fireEvent.change(getByTestId('global-search-input'), {
target: { value: '@index' },
});
});
Expand All @@ -213,7 +231,7 @@ describe('<HeaderSearchBar />', () => {
}
});

waitFor(() => {
await waitFor(() => {
expect(queryByText('saved objects')).toBeInTheDocument();
});
});
Expand Down
Loading
Loading