@@ -10,9 +10,8 @@ import { DraggableProvidedDragHandleProps } from 'react-beautiful-dnd';
1010
1111import { shallow , ShallowWrapper } from 'enzyme' ;
1212
13- import { EuiPanel } from '@elastic/eui' ;
13+ import { EuiButtonIcon , EuiPanel , EuiButtonIconColor } from '@elastic/eui' ;
1414
15- import { ReactRouterHelper } from '../../../shared/react_router_helpers/eui_components' ;
1615import { SchemaTypes } from '../../../shared/types' ;
1716
1817import { Result } from './result' ;
@@ -64,37 +63,18 @@ describe('Result', () => {
6463 ] ) ;
6564 } ) ;
6665
67- it ( 'passes showScore, resultMeta, and isMetaEngine to ResultHeader ' , ( ) => {
66+ it ( 'renders a header ' , ( ) => {
6867 const wrapper = shallow ( < Result { ...props } showScore isMetaEngine /> ) ;
69- expect ( wrapper . find ( ResultHeader ) . props ( ) ) . toEqual ( {
70- isMetaEngine : true ,
71- showScore : true ,
72- resultMeta : {
73- id : '1' ,
74- score : 100 ,
75- engine : 'my-engine' ,
76- } ,
77- } ) ;
78- } ) ;
79-
80- describe ( 'document detail link' , ( ) => {
81- it ( 'will render a link if shouldLinkToDetailPage is true' , ( ) => {
82- const wrapper = shallow ( < Result { ...props } shouldLinkToDetailPage /> ) ;
83- wrapper . find ( ReactRouterHelper ) . forEach ( ( link ) => {
84- expect ( link . prop ( 'to' ) ) . toEqual ( '/engines/my-engine/documents/1' ) ;
85- } ) ;
86- expect ( wrapper . hasClass ( 'appSearchResult--link' ) ) . toBe ( true ) ;
87- expect ( wrapper . find ( '.appSearchResult__content--link' ) . exists ( ) ) . toBe ( true ) ;
88- expect ( wrapper . find ( '.appSearchResult__actionButton--link' ) . exists ( ) ) . toBe ( true ) ;
89- } ) ;
90-
91- it ( 'will not render a link if shouldLinkToDetailPage is not set' , ( ) => {
92- const wrapper = shallow ( < Result { ...props } /> ) ;
93- expect ( wrapper . find ( ReactRouterHelper ) . exists ( ) ) . toBe ( false ) ;
94- expect ( wrapper . hasClass ( 'appSearchResult--link' ) ) . toBe ( false ) ;
95- expect ( wrapper . find ( '.appSearchResult__content--link' ) . exists ( ) ) . toBe ( false ) ;
96- expect ( wrapper . find ( '.appSearchResult__actionButton--link' ) . exists ( ) ) . toBe ( false ) ;
97- } ) ;
68+ const header = wrapper . find ( ResultHeader ) ;
69+ expect ( header . exists ( ) ) . toBe ( true ) ;
70+ expect ( header . prop ( 'isMetaEngine' ) ) . toBe ( true ) ; // passed through from props
71+ expect ( header . prop ( 'showScore' ) ) . toBe ( true ) ; // passed through from props
72+ expect ( header . prop ( 'shouldLinkToDetailPage' ) ) . toBe ( false ) ; // passed through from props
73+ expect ( header . prop ( 'resultMeta' ) ) . toEqual ( {
74+ id : '1' ,
75+ score : 100 ,
76+ engine : 'my-engine' ,
77+ } ) ; // passed through from meta in result prop
9878 } ) ;
9979
10080 describe ( 'actions' , ( ) => {
@@ -103,30 +83,53 @@ describe('Result', () => {
10383 title : 'Hide' ,
10484 onClick : jest . fn ( ) ,
10585 iconType : 'eyeClosed' ,
106- iconColor : 'danger' ,
86+ iconColor : 'danger' as EuiButtonIconColor ,
10787 } ,
10888 {
10989 title : 'Bookmark' ,
11090 onClick : jest . fn ( ) ,
11191 iconType : 'starFilled' ,
112- iconColor : 'primary' ,
92+ iconColor : undefined ,
11393 } ,
11494 ] ;
11595
116- it ( 'will render an action button for each action passed' , ( ) => {
96+ it ( 'will render an action button in the header for each action passed' , ( ) => {
11797 const wrapper = shallow ( < Result { ...props } actions = { actions } /> ) ;
118- expect ( wrapper . find ( '.appSearchResult__actionButton' ) ) . toHaveLength ( 2 ) ;
119-
120- wrapper . find ( '.appSearchResult__actionButton' ) . first ( ) . simulate ( 'click' ) ;
98+ const header = wrapper . find ( ResultHeader ) ;
99+ const renderedActions = shallow ( header . prop ( 'actions' ) as any ) ;
100+ const buttons = renderedActions . find ( EuiButtonIcon ) ;
101+ expect ( buttons ) . toHaveLength ( 2 ) ;
102+
103+ expect ( buttons . first ( ) . prop ( 'iconType' ) ) . toEqual ( 'eyeClosed' ) ;
104+ expect ( buttons . first ( ) . prop ( 'color' ) ) . toEqual ( 'danger' ) ;
105+ buttons . first ( ) . simulate ( 'click' ) ;
121106 expect ( actions [ 0 ] . onClick ) . toHaveBeenCalled ( ) ;
122107
123- wrapper . find ( '.appSearchResult__actionButton' ) . last ( ) . simulate ( 'click' ) ;
108+ expect ( buttons . last ( ) . prop ( 'iconType' ) ) . toEqual ( 'starFilled' ) ;
109+ // Note that no iconColor was passed so it was defaulted to primary
110+ expect ( buttons . last ( ) . prop ( 'color' ) ) . toEqual ( 'primary' ) ;
111+ buttons . last ( ) . simulate ( 'click' ) ;
124112 expect ( actions [ 1 ] . onClick ) . toHaveBeenCalled ( ) ;
125113 } ) ;
126114
127- it ( 'will render custom actions seamlessly next to the document detail link ' , ( ) => {
115+ it ( 'will render a document detail link as the first action if shouldLinkToDetailPage is passed ' , ( ) => {
128116 const wrapper = shallow ( < Result { ...props } actions = { actions } shouldLinkToDetailPage /> ) ;
129- expect ( wrapper . find ( '.appSearchResult__actionButton' ) ) . toHaveLength ( 3 ) ;
117+ const header = wrapper . find ( ResultHeader ) ;
118+ const renderedActions = shallow ( header . prop ( 'actions' ) as any ) ;
119+ const buttons = renderedActions . find ( EuiButtonIcon ) ;
120+
121+ // In addition to the 2 actions passed, we also have a link action
122+ expect ( buttons ) . toHaveLength ( 3 ) ;
123+
124+ expect ( buttons . first ( ) . prop ( 'data-test-subj' ) ) . toEqual ( 'DocumentDetailLink' ) ;
125+ } ) ;
126+
127+ it ( 'will not render anything if no actions are passed and shouldLinkToDetailPage is false' , ( ) => {
128+ const wrapper = shallow ( < Result { ...props } actions = { undefined } /> ) ;
129+ const header = wrapper . find ( ResultHeader ) ;
130+ const renderedActions = shallow ( header . prop ( 'actions' ) as any ) ;
131+ const buttons = renderedActions . find ( EuiButtonIcon ) ;
132+ expect ( buttons ) . toHaveLength ( 0 ) ;
130133 } ) ;
131134 } ) ;
132135
0 commit comments