11import { describe , test , expect } from '@jest/globals' ;
2- import { generateAllElementLocators , ElementWithLocators } from '../locators/generate-all-locators.js' ;
2+ import {
3+ generateAllElementLocators ,
4+ ElementWithLocators ,
5+ } from '../locators/generate-all-locators.js' ;
36
47describe ( 'generateAllElementLocators' , ( ) => {
58 // Sample XML for testing
@@ -31,11 +34,11 @@ describe('generateAllElementLocators', () => {
3134 test ( 'should return an array when given valid XML' , ( ) => {
3235 // Call the function with the sample XML
3336 const result = generateAllElementLocators ( sampleXML , true , 'uiautomator2' ) ;
34-
37+
3538 // Basic validation of the result
3639 expect ( Array . isArray ( result ) ) . toBe ( true ) ;
3740 expect ( result . length ) . toBeGreaterThan ( 0 ) ;
38-
41+
3942 // Verify the structure of the returned elements
4043 if ( result . length > 0 ) {
4144 const element = result [ 0 ] ;
@@ -52,8 +55,12 @@ describe('generateAllElementLocators', () => {
5255
5356 test ( 'should return an empty array when given invalid XML' , ( ) => {
5457 // Call the function with invalid XML (just a root element with no content)
55- const result = generateAllElementLocators ( '<hierarchy></hierarchy>' , true , 'uiautomator2' ) ;
56-
58+ const result = generateAllElementLocators (
59+ '<hierarchy></hierarchy>' ,
60+ true ,
61+ 'uiautomator2'
62+ ) ;
63+
5764 // Verify the result is an empty array or at least doesn't throw an error
5865 expect ( Array . isArray ( result ) ) . toBe ( true ) ;
5966 expect ( result . length ) . toBe ( 0 ) ;
@@ -64,11 +71,13 @@ describe('generateAllElementLocators', () => {
6471 const result = generateAllElementLocators ( sampleXML , true , 'uiautomator2' , {
6572 includeTagNames : [ 'android.widget.Button' ] ,
6673 } ) ;
67-
74+
6875 // If the filter works, either the result will be empty (if no buttons found)
6976 // or all elements will be buttons
7077 if ( result . length > 0 ) {
71- expect ( result . every ( element => element . tagName . includes ( 'Button' ) ) ) . toBe ( true ) ;
78+ expect ( result . every ( element => element . tagName . includes ( 'Button' ) ) ) . toBe (
79+ true
80+ ) ;
7281 }
7382 } ) ;
7483
@@ -77,17 +86,19 @@ describe('generateAllElementLocators', () => {
7786 const result = generateAllElementLocators ( sampleXML , true , 'uiautomator2' , {
7887 excludeTagNames : [ 'android.widget.Button' ] ,
7988 } ) ;
80-
89+
8190 // Verify no Button elements are included
82- expect ( result . every ( element => ! element . tagName . includes ( 'Button' ) ) ) . toBe ( true ) ;
91+ expect ( result . every ( element => ! element . tagName . includes ( 'Button' ) ) ) . toBe (
92+ true
93+ ) ;
8394 } ) ;
8495
8596 test ( 'should apply minAttributeCount filter correctly' , ( ) => {
8697 // Call the function with minAttributeCount filter
8798 const result = generateAllElementLocators ( sampleXML , true , 'uiautomator2' , {
8899 minAttributeCount : 3 ,
89100 } ) ;
90-
101+
91102 // All elements should have at least 3 attributes
92103 if ( result . length > 0 ) {
93104 // We can't directly check the attributes count since we only have the processed elements
@@ -103,18 +114,28 @@ describe('generateAllElementLocators', () => {
103114 const result = generateAllElementLocators ( sampleXML , true , 'uiautomator2' , {
104115 fetchableOnly : true ,
105116 } ) ;
106-
117+
107118 // Verify the result contains only interactable elements
108119 if ( result . length > 0 ) {
109120 const interactableTags = [
110- 'EditText' , 'Button' , 'ImageButton' , 'CheckBox' , 'RadioButton' ,
111- 'Switch' , 'ToggleButton' , 'TextView'
121+ 'EditText' ,
122+ 'Button' ,
123+ 'ImageButton' ,
124+ 'CheckBox' ,
125+ 'RadioButton' ,
126+ 'Switch' ,
127+ 'ToggleButton' ,
128+ 'TextView' ,
112129 ] ;
113-
114- expect ( result . every ( element => {
115- return interactableTags . some ( tag => element . tagName . includes ( tag ) ) ||
116- element . clickable === true ;
117- } ) ) . toBe ( true ) ;
130+
131+ expect (
132+ result . every ( element => {
133+ return (
134+ interactableTags . some ( tag => element . tagName . includes ( tag ) ) ||
135+ element . clickable === true
136+ ) ;
137+ } )
138+ ) . toBe ( true ) ;
118139 }
119140 } ) ;
120141
@@ -123,18 +144,26 @@ describe('generateAllElementLocators', () => {
123144 const result = generateAllElementLocators ( sampleIOSXML , true , 'xcuitest' , {
124145 fetchableOnly : true ,
125146 } ) ;
126-
147+
127148 // Verify the result contains only interactable iOS elements
128149 if ( result . length > 0 ) {
129150 const interactableTags = [
130- 'XCUIElementTypeTextField' , 'XCUIElementTypeSecureTextField' , 'XCUIElementTypeButton' ,
131- 'XCUIElementTypeImage' , 'XCUIElementTypeSwitch' , 'XCUIElementTypeStaticText' ,
132- 'XCUIElementTypeTextView' , 'XCUIElementTypeCell' , 'XCUIElementTypeLink'
151+ 'XCUIElementTypeTextField' ,
152+ 'XCUIElementTypeSecureTextField' ,
153+ 'XCUIElementTypeButton' ,
154+ 'XCUIElementTypeImage' ,
155+ 'XCUIElementTypeSwitch' ,
156+ 'XCUIElementTypeStaticText' ,
157+ 'XCUIElementTypeTextView' ,
158+ 'XCUIElementTypeCell' ,
159+ 'XCUIElementTypeLink' ,
133160 ] ;
134-
135- expect ( result . every ( element => {
136- return interactableTags . some ( tag => element . tagName . includes ( tag ) ) ;
137- } ) ) . toBe ( true ) ;
161+
162+ expect (
163+ result . every ( element => {
164+ return interactableTags . some ( tag => element . tagName . includes ( tag ) ) ;
165+ } )
166+ ) . toBe ( true ) ;
138167 }
139168 } ) ;
140169
@@ -143,7 +172,7 @@ describe('generateAllElementLocators', () => {
143172 const result = generateAllElementLocators ( sampleXML , true , 'uiautomator2' , {
144173 clickableOnly : true ,
145174 } ) ;
146-
175+
147176 // Verify all elements are clickable
148177 expect ( result . every ( element => element . clickable === true ) ) . toBe ( true ) ;
149178 } ) ;
0 commit comments