mirror of
https://github.com/hanzoai/Detox.git
synced 2026-09-24 16:55:12 +00:00
fix(ios): respect atIndex in getAttributes (#4912)
The `attributes` property on `Element` was ignoring `self.index`, causing `element(...).atIndex(N).getAttributes()` to return all matching elements instead of the one at the specified index. This aligns the `attributes` property with the existing `view` property, which already correctly handles `self.index`. Fixes #4633 Co-authored-by: mark.dev <[email protected]>
This commit is contained in:
committed by
GitHub
co-authored by
mark.dev
parent
1158066bdb
commit
924d0f2271
@@ -313,14 +313,19 @@ class Element : NSObject {
|
||||
@objc
|
||||
var attributes: [String : Any] {
|
||||
let views = self.views
|
||||
|
||||
if views.count == 1 {
|
||||
|
||||
if let index = index {
|
||||
guard index < views.count else {
|
||||
dtx_fatalError("Index \(index) beyond bounds \(views.count > 0 ? "[0 .. \(views.count - 1)] " : " ")for "\(self.description)"", viewDescription: failDebugAttributes)
|
||||
}
|
||||
return views[index].dtx_attributes
|
||||
} else if views.count == 1 {
|
||||
return views.first!.dtx_attributes
|
||||
} else {
|
||||
let elements = views.map {
|
||||
return $0.dtx_attributes
|
||||
}
|
||||
|
||||
|
||||
return ["elements": elements]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,6 +220,28 @@ describe('Attributes', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('of multiple views with atIndex', () => {
|
||||
it(':ios: @legacy should return attributes of a single element when using atIndex', async () => {
|
||||
const result = await element(by.type('RCTView').withAncestor(by.id('attrScrollView'))).atIndex(0).getAttributes();
|
||||
|
||||
expect(result).not.toHaveProperty('elements');
|
||||
expect(result).toMatchObject({
|
||||
enabled: true,
|
||||
visible: true,
|
||||
});
|
||||
});
|
||||
|
||||
it(':ios: @new-arch should return attributes of a single element when using atIndex', async () => {
|
||||
const result = await element(by.type('RCTViewComponentView')).atIndex(0).getAttributes();
|
||||
|
||||
expect(result).not.toHaveProperty('elements');
|
||||
expect(result).toMatchObject({
|
||||
enabled: true,
|
||||
visible: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('of multiple views', () => {
|
||||
it(':ios: @legacy should return an object with .elements array', async () => {
|
||||
await useMatcher(by.type('RCTView').withAncestor(by.id('attrScrollView')));
|
||||
|
||||
Reference in New Issue
Block a user