forked from EVOgeek/Vmeda.Online
		
	MOBILE-4069 behat: Allow searching text split in different elements
This commit is contained in:
		
							parent
							
								
									ebb6e393cf
								
							
						
					
					
						commit
						8f826185b6
					
				| @ -24,6 +24,8 @@ import { TestingBehatElementLocator, TestingBehatFindOptions } from './behat-run | |||||||
| @Injectable({ providedIn: 'root' }) | @Injectable({ providedIn: 'root' }) | ||||||
| export class TestingBehatDomUtilsService { | export class TestingBehatDomUtilsService { | ||||||
| 
 | 
 | ||||||
|  |     protected static readonly MULTI_ELEM_ALLOWED = ['P', 'SPAN', 'ION-LABEL']; | ||||||
|  | 
 | ||||||
|     /** |     /** | ||||||
|      * Check if an element is clickable. |      * Check if an element is clickable. | ||||||
|      * |      * | ||||||
| @ -154,6 +156,7 @@ export class TestingBehatDomUtilsService { | |||||||
|             }, |             }, | ||||||
|         ); |         ); | ||||||
| 
 | 
 | ||||||
|  |         let fallbackCandidates: ElementsWithExact[] = []; | ||||||
|         let currentNode: Node | null = null; |         let currentNode: Node | null = null; | ||||||
|         // eslint-disable-next-line no-cond-assign
 |         // eslint-disable-next-line no-cond-assign
 | ||||||
|         while (currentNode = treeWalker.nextNode()) { |         while (currentNode = treeWalker.nextNode()) { | ||||||
| @ -202,9 +205,24 @@ export class TestingBehatDomUtilsService { | |||||||
|                     elements.push(...this.findElementsBasedOnTextWithinWithExact(childNode, text, options)); |                     elements.push(...this.findElementsBasedOnTextWithinWithExact(childNode, text, options)); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  | 
 | ||||||
|  |             // Allow searching text split into different elements in some cases.
 | ||||||
|  |             if ( | ||||||
|  |                 elements.length === 0 && | ||||||
|  |                 currentNode instanceof HTMLElement && | ||||||
|  |                 TestingBehatDomUtilsService.MULTI_ELEM_ALLOWED.includes(currentNode.tagName) && | ||||||
|  |                 currentNode.innerText.includes(text) | ||||||
|  |             ) { | ||||||
|  |                 // Only keep the child elements in the candidates list.
 | ||||||
|  |                 fallbackCandidates = fallbackCandidates.filter(entry => !entry.element.contains(currentNode)); | ||||||
|  |                 fallbackCandidates.push({ | ||||||
|  |                     element: currentNode, | ||||||
|  |                     exact: currentNode.innerText.trim() == text, | ||||||
|  |                 }); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return elements; |         return elements.length > 0 ? elements : fallbackCandidates; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user