Skip to content

Commit

Permalink
[Security Solution][Endpoint] Do not display searchbar in security-tr…
Browse files Browse the repository at this point in the history
…usted apps if there are no items (#100853) (#100877)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Esteban Beltran <academo@users.noreply.github.com>
  • Loading branch information
kibanamachine and academo authored May 28, 2021
1 parent 0f50198 commit 0dff3fe
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const SearchBar = memo<SearchBarProps>(({ defaultValue = '', onSearch, pl
const handleOnSearch = useCallback(() => onSearch(query), [query, onSearch]);

return (
<EuiFlexGroup direction="row" alignItems="center" gutterSize="l">
<EuiFlexGroup data-test-subj="searchBar" direction="row" alignItems="center" gutterSize="l">
<EuiFlexItem>
<EuiFieldSearch
defaultValue={defaultValue}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,15 @@ describe('When on the Trusted Apps Page', () => {

it('should display a Add Trusted App button', async () => {
const { getByTestId } = await renderWithListData();
const addButton = await getByTestId('trustedAppsListAddButton');
const addButton = getByTestId('trustedAppsListAddButton');
expect(addButton.textContent).toBe('Add Trusted Application');
});

it('should display the searchbar', async () => {
const renderResult = await renderWithListData();
expect(await renderResult.findByTestId('searchBar')).not.toBeNull();
});

describe('and the Grid view is being displayed', () => {
describe('and the edit trusted app button is clicked', () => {
let renderResult: ReturnType<AppContextTestRender['render']>;
Expand Down Expand Up @@ -555,7 +560,7 @@ describe('When on the Trusted Apps Page', () => {
// to test the UI behaviours while the API call is in flight
coreStart.http.post.mockImplementation(
// @ts-ignore
async (path: string, options: HttpFetchOptions) => {
async (_, options: HttpFetchOptions) => {
return new Promise((resolve, reject) => {
httpPostBody = options.body as string;
resolveHttpPost = resolve;
Expand Down Expand Up @@ -861,6 +866,14 @@ describe('When on the Trusted Apps Page', () => {

expect(await renderResult.findByTestId('trustedAppEmptyState')).not.toBeNull();
});

it('should not display the searchbar', async () => {
const renderResult = render();
await act(async () => {
await waitForAction('trustedAppsExistStateChanged');
});
expect(renderResult.queryByTestId('searchBar')).toBeNull();
});
});

describe('and the search is dispatched', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,34 +96,36 @@ export const TrustedAppsPage = memo(() => {
/>
)}

<SearchBar
defaultValue={location.filter}
onSearch={handleOnSearch}
placeholder={SEARCH_TRUSTED_APP_PLACEHOLDER}
/>
{doEntriesExist ? (
<EuiFlexGroup
direction="column"
gutterSize="none"
data-test-subj="trustedAppsListPageContent"
>
<EuiSpacer size="m" />
<EuiFlexItem grow={false}>
<ControlPanel
totalItemCount={totalItemsCount}
currentViewType={location.view_type}
onViewTypeChange={handleViewTypeChange}
/>

<>
<SearchBar
defaultValue={location.filter}
onSearch={handleOnSearch}
placeholder={SEARCH_TRUSTED_APP_PLACEHOLDER}
/>
<EuiFlexGroup
direction="column"
gutterSize="none"
data-test-subj="trustedAppsListPageContent"
>
<EuiSpacer size="m" />
</EuiFlexItem>
<EuiFlexItem>
<EuiHorizontalRule margin="none" />

{location.view_type === 'grid' && <TrustedAppsGrid />}
{location.view_type === 'list' && <TrustedAppsList />}
</EuiFlexItem>
</EuiFlexGroup>
<EuiFlexItem grow={false}>
<ControlPanel
totalItemCount={totalItemsCount}
currentViewType={location.view_type}
onViewTypeChange={handleViewTypeChange}
/>

<EuiSpacer size="m" />
</EuiFlexItem>
<EuiFlexItem>
<EuiHorizontalRule margin="none" />

{location.view_type === 'grid' && <TrustedAppsGrid />}
{location.view_type === 'list' && <TrustedAppsList />}
</EuiFlexItem>
</EuiFlexGroup>
</>
) : (
<EmptyState onAdd={handleAddButtonClick} isAddDisabled={showCreateFlyout} />
)}
Expand Down

0 comments on commit 0dff3fe

Please sign in to comment.