11import * as React from 'react' ;
22import FileIcon from '../../../icons/file-icon' ;
3+ import IconPencil from '../../../icons/general/IconPencil' ;
34import PlainButton from '../../../components/plain-button' ;
5+ import Tooltip from '../../../components/tooltip' ;
46
57import { MetadataBasedItemListComponent as MetadataBasedItemList } from '../MetadataBasedItemList' ;
68
@@ -67,7 +69,7 @@ describe('features/metadata-based-view/MetadataBasedItemList', () => {
6769 ` ( 'getColumnWidth() for $desc' , ( { columnIndex, columnWidth } ) => {
6870 const availableWidth = 500 ; // width provided to AutoSizer Component
6971 const getWidth = instance . getColumnWidth ( availableWidth ) ;
70- expect ( getWidth ( { index : columnIndex } ) ) . toEqual ( columnWidth ) ;
72+ expect ( getWidth ( { index : columnIndex } ) ) . toBe ( columnWidth ) ;
7173 } ) ;
7274 } ) ;
7375
@@ -83,8 +85,28 @@ describe('features/metadata-based-view/MetadataBasedItemList', () => {
8385 ${ 2 } | ${ 2 } | ${ 'receipt' }
8486 ${ 3 } | ${ 2 } | ${ 200 }
8587 ` ( 'cellData for row: $rowIndex, column: $columnIndex' , ( { columnIndex, rowIndex, cellData } ) => {
88+ const editableColumnIndex = 3 ; // amount field is editable
89+
90+ if ( columnIndex === editableColumnIndex ) {
91+ // Set state reflecting mouse-over action for every cell in editable column
92+ instance . handleMouseEnter ( columnIndex , rowIndex ) ;
93+ }
94+
8695 const data = instance . getGridCellData ( columnIndex , rowIndex ) ;
87- expect ( data ) . toEqual ( cellData ) ;
96+ if ( columnIndex < 2 ) {
97+ // i.e. FileIcon and FileName columns
98+ expect ( data ) . toEqual ( cellData ) ;
99+ return ;
100+ }
101+
102+ const wrap = mount ( data ) ;
103+ expect ( wrap . contains ( cellData . toString ( ) ) ) . toBe ( true ) ;
104+
105+ if ( columnIndex === editableColumnIndex ) {
106+ // Expect edit icon for editable column
107+ expect ( wrap . contains ( Tooltip ) ) . toBe ( true ) ;
108+ expect ( wrap . contains ( IconPencil ) ) . toBe ( true ) ;
109+ }
88110 } ) ;
89111 } ) ;
90112
@@ -97,7 +119,7 @@ describe('features/metadata-based-view/MetadataBasedItemList', () => {
97119 ${ 3 } | ${ 'amount' }
98120 ` ( 'headerData for column $columnIndex' , ( { columnIndex, headerData } ) => {
99121 const data = instance . getGridHeaderData ( columnIndex ) ;
100- expect ( data ) . toEqual ( headerData ) ;
122+ expect ( data ) . toBe ( headerData ) ;
101123 } ) ;
102124 } ) ;
103125
@@ -113,15 +135,16 @@ describe('features/metadata-based-view/MetadataBasedItemList', () => {
113135
114136 describe ( 'handleMouseEnter()' , ( ) => {
115137 test ( 'should handle mouse over event by setting state accordingly' , ( ) => {
116- instance . handleMouseEnter ( 5 ) ;
117- expect ( instance . state . hoveredRowIndex ) . toEqual ( 5 ) ;
138+ instance . handleMouseEnter ( 5 , 8 ) ;
139+ expect ( instance . state . hoveredColumnIndex ) . toBe ( 5 ) ;
140+ expect ( instance . state . hoveredRowIndex ) . toBe ( 8 ) ;
118141 } ) ;
119142 } ) ;
120143
121144 describe ( 'handleMouseLeave()' , ( ) => {
122145 test ( 'should handle mouse leave event by setting state accordingly' , ( ) => {
123146 instance . handleMouseLeave ( ) ;
124- expect ( instance . state . hoveredRowIndex ) . toEqual ( - 1 ) ;
147+ expect ( instance . state . hoveredRowIndex ) . toBe ( - 1 ) ;
125148 } ) ;
126149 } ) ;
127150
@@ -131,19 +154,20 @@ describe('features/metadata-based-view/MetadataBasedItemList', () => {
131154 [ { columnIndex : 1 , rowIndex : 2 , key : 'key' , style : { } } , false , true ] ,
132155 ] ) ( 'should have correct class names' , ( arg , hasFileIconClass , hasFileNameClass ) => {
133156 const cell = shallow ( instance . cellRenderer ( arg ) ) ;
134- expect ( cell . hasClass ( 'bdl-MetadataBasedItemList-cell' ) ) . toEqual ( true ) ;
135- expect ( cell . hasClass ( 'bdl-MetadataBasedItemList-cell--fileIcon' ) ) . toEqual ( hasFileIconClass ) ;
136- expect ( cell . hasClass ( 'bdl-MetadataBasedItemList-cell--filename' ) ) . toEqual ( hasFileNameClass ) ;
157+ expect ( cell . hasClass ( 'bdl-MetadataBasedItemList-cell' ) ) . toBe ( true ) ;
158+ expect ( cell . hasClass ( 'bdl-MetadataBasedItemList-cell--fileIcon' ) ) . toBe ( hasFileIconClass ) ;
159+ expect ( cell . hasClass ( 'bdl-MetadataBasedItemList-cell--filename' ) ) . toBe ( hasFileNameClass ) ;
137160 } ) ;
138161
139162 test ( 'should have hovered class for adding background color on row hover' , ( ) => {
140- const hoverCellIndex = 1 ;
141- instance . handleMouseEnter ( hoverCellIndex ) ; // Hover over row
163+ const hoverRowIndex = 1 ;
164+ const hoverColumnIndex = 1 ;
165+ instance . handleMouseEnter ( hoverColumnIndex , hoverRowIndex ) ; // Hover over row
142166
143167 const cell = shallow (
144- instance . cellRenderer ( { columnIndex : 0 , rowIndex : hoverCellIndex , key : 'key' , style : { } } ) ,
168+ instance . cellRenderer ( { columnIndex : 0 , rowIndex : hoverRowIndex , key : 'key' , style : { } } ) ,
145169 ) ;
146- expect ( cell . hasClass ( 'bdl-MetadataBasedItemList-cell--hover' ) ) . toEqual ( true ) ;
170+ expect ( cell . hasClass ( 'bdl-MetadataBasedItemList-cell--hover' ) ) . toBe ( true ) ;
147171 } ) ;
148172 } ) ;
149173
0 commit comments