@@ -107,34 +107,21 @@ extension RunnerTests {
107107 let typeName = elementTypeName ( rawElementType : rawType )
108108 let enabled = privateAXBool ( rawNode [ " enabled " ] ) ?? true
109109 let visible = isVisibleInViewport ( rect , viewport )
110- let hasContent = ! label . isEmpty || ! identifier . isEmpty || ! value . isEmpty
111- let isRoot = parentIndex == nil
112-
113- // Scope selects a subtree, matching regular snapshot semantics: once a node matches,
114- // every descendant is inside scope and only the normal option filters apply to it.
115- let scope = options . scope ? . trimmingCharacters ( in : . whitespacesAndNewlines )
116- let scopeActive = ( scope ? . isEmpty == false )
117- let matchesScope : Bool
118- if scopeActive , let scope {
119- let haystack = [ label , identifier , value ] . joined ( separator : " \n " )
120- matchesScope = haystack . localizedCaseInsensitiveContains ( scope )
121- } else {
122- matchesScope = false
123- }
124- let nowInsideScope = insideMatchedScope || matchesScope
125-
126- let include : Bool
127- if isRoot {
128- include = true
129- } else if scopeActive && ! nowInsideScope {
130- include = false
131- } else if options . interactiveOnly && ! visible {
132- include = false
133- } else if options . compact {
134- include = hasContent || privateAXLikelyInteractive ( rawElementType : rawType )
135- } else {
136- include = true
137- }
110+ let compactCandidate = privateAXFlatCompactCandidate ( rawElementType : rawType )
111+ let filterDecision = flatSnapshotFilterDecision (
112+ FlatSnapshotFilterNode (
113+ isRoot : parentIndex == nil ,
114+ label : label ,
115+ identifier : identifier ,
116+ valueText : value . isEmpty ? nil : value ,
117+ visible : visible ,
118+ compactCandidate : compactCandidate
119+ ) ,
120+ options : options ,
121+ insideMatchedScope : insideMatchedScope
122+ )
123+ let include = filterDecision . include
124+ let nowInsideScope = filterDecision . insideMatchedScope
138125
139126 let currentIndex : Int ?
140127 if include {
@@ -150,7 +137,7 @@ extension RunnerTests {
150137 enabled : enabled ,
151138 focused : privateAXBool ( rawNode [ " focused " ] ) == true ? true : nil ,
152139 selected : privateAXBool ( rawNode [ " selected " ] ) == true ? true : nil ,
153- hittable : visible && enabled && privateAXLikelyInteractive ( rawElementType : rawType ) ,
140+ hittable : visible && enabled && compactCandidate ,
154141 depth : depth ,
155142 parentIndex : parentIndex ,
156143 hiddenContentAbove : nil ,
@@ -178,23 +165,12 @@ extension RunnerTests {
178165 }
179166
180167 private func elementTypeName ( rawElementType : Int ) -> String {
181- if let raw = UInt ( exactly : rawElementType ) ,
182- let type = XCUIElement . ElementType ( rawValue : raw )
183- {
168+ if let type = flatSnapshotElementType ( rawElementType : rawElementType ) {
184169 return elementTypeName ( type )
185170 }
186171 return " Element( \( rawElementType ) ) "
187172 }
188173
189- private func privateAXLikelyInteractive ( rawElementType : Int ) -> Bool {
190- guard let raw = UInt ( exactly : rawElementType ) ,
191- let type = XCUIElement . ElementType ( rawValue : raw )
192- else {
193- return false
194- }
195- return interactiveTypes . contains ( type ) || Self . scrollContainerTypes . contains ( type )
196- }
197-
198174 private func privateAXString ( _ value : Any ? ) -> String {
199175 guard let value else { return " " }
200176 if let string = value as? String {
@@ -268,4 +244,88 @@ extension RunnerTests {
268244 XCTAssertTrue ( labels . contains ( " Post body without the scope text " ) )
269245 XCTAssertFalse ( labels . contains ( " unrelated sibling " ) )
270246 }
247+
248+ func testPrivateAXCompactInteractiveFiltersLoginLikeHiddenDrawer ( ) {
249+ let tree : [ String : Any ] = [
250+ " type " : Int ( XCUIElement . ElementType . application . rawValue ) ,
251+ " label " : " Blue Sky " ,
252+ " frame " : [ " x " : 0 , " y " : 0 , " width " : 390 , " height " : 844 ] ,
253+ " children " : [
254+ [
255+ " type " : Int ( XCUIElement . ElementType . scrollView . rawValue ) ,
256+ " frame " : [ " x " : 0 , " y " : 0 , " width " : 390 , " height " : 844 ] ,
257+ " children " : [
258+ [
259+ " type " : Int ( XCUIElement . ElementType . image . rawValue ) ,
260+ " label " : " Callstack " ,
261+ " frame " : [ " x " : 145 , " y " : 104 , " width " : 100 , " height " : 100 ] ,
262+ " children " : [ ] ,
263+ ] ,
264+ [
265+ " type " : Int ( XCUIElement . ElementType . staticText . rawValue ) ,
266+ " label " : " Welcome back " ,
267+ " frame " : [ " x " : 32 , " y " : 260 , " width " : 326 , " height " : 32 ] ,
268+ " children " : [ ] ,
269+ ] ,
270+ [
271+ " type " : Int ( XCUIElement . ElementType . textField . rawValue ) ,
272+ " label " : " Email " ,
273+ " identifier " : " login.email " ,
274+ " frame " : [ " x " : 32 , " y " : 348 , " width " : 326 , " height " : 48 ] ,
275+ " children " : [ ] ,
276+ ] ,
277+ [
278+ " type " : Int ( XCUIElement . ElementType . secureTextField . rawValue ) ,
279+ " label " : " Password " ,
280+ " identifier " : " login.password " ,
281+ " frame " : [ " x " : 32 , " y " : 412 , " width " : 326 , " height " : 48 ] ,
282+ " children " : [ ] ,
283+ ] ,
284+ [
285+ " type " : Int ( XCUIElement . ElementType . button . rawValue ) ,
286+ " label " : " Sign in " ,
287+ " identifier " : " login.submit " ,
288+ " frame " : [ " x " : 32 , " y " : 492 , " width " : 326 , " height " : 52 ] ,
289+ " children " : [ ] ,
290+ ] ,
291+ [
292+ " type " : Int ( XCUIElement . ElementType . link . rawValue ) ,
293+ " label " : " Forgot password? " ,
294+ " frame " : [ " x " : 128 , " y " : 568 , " width " : 134 , " height " : 32 ] ,
295+ " children " : [ ] ,
296+ ] ,
297+ [
298+ " type " : Int ( XCUIElement . ElementType . button . rawValue ) ,
299+ " label " : " Admin settings " ,
300+ " frame " : [ " x " : - 260 , " y " : 184 , " width " : 220 , " height " : 44 ] ,
301+ " children " : [ ] ,
302+ ] ,
303+ [
304+ " type " : Int ( XCUIElement . ElementType . other . rawValue ) ,
305+ " frame " : [ " x " : 16 , " y " : 184 , " width " : 220 , " height " : 44 ] ,
306+ " children " : [ ] ,
307+ ] ,
308+ ] ,
309+ ]
310+ ] ,
311+ ]
312+ var nodes : [ SnapshotNode ] = [ ]
313+ appendPrivateAXNode (
314+ tree ,
315+ to : & nodes ,
316+ options : SnapshotOptions (
317+ interactiveOnly : true , compact : true , depth : nil , scope : nil , raw : false ) ,
318+ viewport : CGRect ( x : 0 , y : 0 , width : 390 , height : 844 ) ,
319+ depth : 0 ,
320+ parentIndex : nil ,
321+ insideMatchedScope : false
322+ )
323+
324+ let labels = nodes . compactMap { $0 . label }
325+ XCTAssertEqual (
326+ labels ,
327+ [ " Blue Sky " , " Callstack " , " Welcome back " , " Email " , " Password " , " Sign in " , " Forgot password? " ]
328+ )
329+ XCTAssertFalse ( labels . contains ( " Admin settings " ) )
330+ }
271331}
0 commit comments