11import { expect } from 'chai'
22import MultipleElementsFound , {
33 computeDepths ,
4+ computeParents ,
45 formatTree ,
56 isAncestorXPath ,
67 splitXPath ,
@@ -48,21 +49,26 @@ describe('MultipleElementsFound tree formatting', () => {
4849 { index : 2 , xpath : '//html/body/div[1]/div[1]' , html : '<div class="item">' } ,
4950 { index : 3 , xpath : '//html/body/div[1]/div[2]' , html : '<div class="item">' } ,
5051 ]
52+ expect ( computeParents ( entries ) ) . to . deep . equal ( [ - 1 , 0 , 0 ] )
5153 expect ( computeDepths ( entries ) ) . to . deep . equal ( [ 0 , 1 , 1 ] )
52- const items = formatTree ( entries , [ 0 , 1 , 1 ] )
54+ const items = formatTree ( entries , [ 0 , 1 , 1 ] , [ - 1 , 0 , 0 ] )
5355 expect ( items [ 0 ] ) . to . equal ( ' 1. > //html/body/div[1]\n <div class="item">' )
54- expect ( items [ 1 ] ) . to . equal ( ' 2. > //html/body/div[1]/div[1]\n <div class="item">' )
55- expect ( items [ 2 ] ) . to . equal ( ' 3. > //html/body/div[1]/div[2]\n <div class="item">' )
56+ expect ( items [ 1 ] ) . to . equal ( ' 2. (inside 1.) > //html/body/div[1]/div[1]\n <div class="item">' )
57+ expect ( items [ 2 ] ) . to . equal ( ' 3. (inside 1.) > //html/body/div[1]/div[2]\n <div class="item">' )
5658 } )
5759
58- it ( 'supports deeper nesting and returns to root level ' , ( ) => {
60+ it ( 'marks the immediate parent for deeper nesting ' , ( ) => {
5961 const entries = [
6062 { index : 1 , xpath : '//html/body/div[1]' , html : '<div>' } ,
6163 { index : 2 , xpath : '//html/body/div[1]/ul' , html : '<ul>' } ,
6264 { index : 3 , xpath : '//html/body/div[1]/ul/li' , html : '<li>' } ,
6365 { index : 4 , xpath : '//html/body/div[2]' , html : '<div>' } ,
6466 ]
67+ expect ( computeParents ( entries ) ) . to . deep . equal ( [ - 1 , 0 , 1 , - 1 ] )
6568 expect ( computeDepths ( entries ) ) . to . deep . equal ( [ 0 , 1 , 2 , 0 ] )
69+ const items = formatTree ( entries , [ 0 , 1 , 2 , 0 ] , [ - 1 , 0 , 1 , - 1 ] )
70+ expect ( items [ 2 ] ) . to . include ( '3. (inside 2.) >' )
71+ expect ( items [ 3 ] ) . to . equal ( ' 4. > //html/body/div[2]\n <div>' )
6672 } )
6773
6874 it ( 'renders failed lookups as roots and keeps global numbering' , async ( ) => {
@@ -74,7 +80,7 @@ describe('MultipleElementsFound tree formatting', () => {
7480 await err . fetchDetails ( )
7581 expect ( err . message ) . to . include ( ' 1. > //html/body/div[1]' )
7682 expect ( err . message ) . to . include ( ' 2. [Unable to get element info: detached]' )
77- expect ( err . message ) . to . include ( ' 3. > //html/body/div[1]/div[1]' )
83+ expect ( err . message ) . to . include ( ' 3. (inside 1.) > //html/body/div[1]/div[1]' )
7884 } )
7985
8086 it ( 'renders nested fetchDetails output with indentation' , async ( ) => {
@@ -86,8 +92,8 @@ describe('MultipleElementsFound tree formatting', () => {
8692 await err . fetchDetails ( )
8793 const lines = err . message . split ( '\n' )
8894 expect ( lines [ 1 ] ) . to . equal ( ' 1. > //html/body/div[1]' )
89- expect ( lines [ 3 ] ) . to . equal ( ' 2. > //html/body/div[1]/div[1]' )
90- expect ( lines [ 5 ] ) . to . equal ( ' 3. > //html/body/div[1]/div[2]' )
95+ expect ( lines [ 3 ] ) . to . equal ( ' 2. (inside 1.) > //html/body/div[1]/div[1]' )
96+ expect ( lines [ 5 ] ) . to . equal ( ' 3. (inside 1.) > //html/body/div[1]/div[2]' )
9197 expect ( err . message ) . to . include ( 'Use a more specific locator' )
9298 } )
9399} )
0 commit comments