-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set up test_helpers for inspecting pageHeaders
- primarily useful for rightSideItems, which often contain conditional logic
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
x-pack/plugins/enterprise_search/public/applications/test_helpers/get_page_header.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,43 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { Fragment } from 'react'; | ||
|
||
import { shallow, ShallowWrapper } from 'enzyme'; | ||
|
||
import { EuiPageHeaderProps } from '@elastic/eui'; | ||
|
||
/* | ||
* Given an AppSearchPageTemplate or WorkplaceSearchPageTemplate, these | ||
* helpers dive into various parts of the EuiPageHeader to make assertions | ||
* slightly less of a pain in shallow renders | ||
*/ | ||
|
||
export const getPageHeader = (wrapper: ShallowWrapper) => { | ||
const pageHeader = wrapper.prop('pageHeader') as EuiPageHeaderProps; | ||
return pageHeader || {}; | ||
}; | ||
|
||
export const getPageTitle = (wrapper: ShallowWrapper) => { | ||
return getPageHeader(wrapper).pageTitle; | ||
}; | ||
|
||
export const getPageDescription = (wrapper: ShallowWrapper) => { | ||
return getPageHeader(wrapper).description; | ||
}; | ||
|
||
export const getPageHeaderActions = (wrapper: ShallowWrapper) => { | ||
const actions = getPageHeader(wrapper).rightSideItems || []; | ||
|
||
return shallow( | ||
<div> | ||
{actions.map((action: React.ReactNode, i) => ( | ||
<Fragment key={i}>{action}</Fragment> | ||
))} | ||
</div> | ||
); | ||
}; |
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