mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-04 20:17:09 +00:00
feat(spec): type AttrSelector with known attribute names
Replace AttrSelector = Record<string, string> with KnownAttrSelectors plus a string|boolean index signature, so authors get autocomplete and type-checking on testTag / focused / clickable / etc. while raw driver attributes still type-check via the fallback. Boolean state attributes accept native booleans; goja stringifies them at the marshal boundary. AccessibilityElement.attrs becomes RawAttrs (typed string-valued shape of the same canonical names) so element.attrs.testTag autocompletes.
This commit is contained in:
1 parent
407b4a0648
commit
8309fb1886
2 files changed
+55
-2
No files matched your search
@@ -3,15 +3,18 @@ export type {
|
|||||||
AccessibilityTree,
|
AccessibilityTree,
|
||||||
Action,
|
Action,
|
||||||
ActionGenerator,
|
ActionGenerator,
|
||||||
|
AttrSelector,
|
||||||
EventuallyFormula,
|
EventuallyFormula,
|
||||||
ExceptionRecord,
|
ExceptionRecord,
|
||||||
Extracted,
|
Extracted,
|
||||||
Formula,
|
Formula,
|
||||||
InputTextAction,
|
InputTextAction,
|
||||||
Key,
|
Key,
|
||||||
|
KnownAttrSelectors,
|
||||||
LogEntry,
|
LogEntry,
|
||||||
Point,
|
Point,
|
||||||
PressKeyAction,
|
PressKeyAction,
|
||||||
|
RawAttrs,
|
||||||
Sampler,
|
Sampler,
|
||||||
SelectorPath,
|
SelectorPath,
|
||||||
Snapshots,
|
Snapshots,
|
||||||
|
|||||||
+52
-2
@@ -1,8 +1,58 @@
|
|||||||
export type Snapshots = Record<string, unknown>;
|
export type Snapshots = Record<string, unknown>;
|
||||||
export type AttrSelector = Record<string, string>;
|
|
||||||
|
/**
|
||||||
|
* Attribute names with known canonical types. Cross-platform aliases (e.g.
|
||||||
|
* `testTag` -> resource-id / accessibilityIdentifier) are listed so authors
|
||||||
|
* get autocomplete on whichever name they prefer.
|
||||||
|
*
|
||||||
|
* Boolean state attributes accept a native boolean; the runtime stringifies
|
||||||
|
* to "true"/"false" before matching.
|
||||||
|
*/
|
||||||
|
export interface KnownAttrSelectors {
|
||||||
|
testTag?: string;
|
||||||
|
identifier?: string;
|
||||||
|
accessibilityIdentifier?: string;
|
||||||
|
"resource-id"?: string;
|
||||||
|
|
||||||
|
"content-desc"?: string;
|
||||||
|
accessibilityText?: string;
|
||||||
|
accessibilityLabel?: string;
|
||||||
|
label?: string;
|
||||||
|
|
||||||
|
text?: string;
|
||||||
|
class?: string;
|
||||||
|
elementType?: string;
|
||||||
|
package?: string;
|
||||||
|
placeholderValue?: string;
|
||||||
|
hintText?: string;
|
||||||
|
|
||||||
|
clickable?: boolean;
|
||||||
|
enabled?: boolean;
|
||||||
|
focused?: boolean;
|
||||||
|
checked?: boolean;
|
||||||
|
selected?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Object-form selector for `find` / `findAll`. Known attributes are typed
|
||||||
|
* via `KnownAttrSelectors`; arbitrary string keys are still allowed for
|
||||||
|
* raw driver attributes the typed surface doesn't yet cover.
|
||||||
|
*/
|
||||||
|
export type AttrSelector = KnownAttrSelectors & {
|
||||||
|
[key: string]: string | boolean | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
export type SelectorPath = readonly AttrSelector[];
|
export type SelectorPath = readonly AttrSelector[];
|
||||||
|
|
||||||
|
/** String-valued attribute names with known canonical keys. */
|
||||||
|
export type RawAttrs = {
|
||||||
|
[K in keyof KnownAttrSelectors]?: KnownAttrSelectors[K] extends boolean | undefined
|
||||||
|
? "true" | "false"
|
||||||
|
: string;
|
||||||
|
} & {
|
||||||
|
[key: string]: string | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
export interface AccessibilityElement {
|
export interface AccessibilityElement {
|
||||||
id?: string;
|
id?: string;
|
||||||
text?: string;
|
text?: string;
|
||||||
@@ -16,7 +66,7 @@ export interface AccessibilityElement {
|
|||||||
bounds?: { left: number; top: number; right: number; bottom: number };
|
bounds?: { left: number; top: number; right: number; bottom: number };
|
||||||
x?: number;
|
x?: number;
|
||||||
y?: number;
|
y?: number;
|
||||||
attrs?: Record<string, string>;
|
attrs?: RawAttrs;
|
||||||
find(selector: string | AttrSelector | SelectorPath): AccessibilityElement | undefined;
|
find(selector: string | AttrSelector | SelectorPath): AccessibilityElement | undefined;
|
||||||
findAll(selector: string | AttrSelector | SelectorPath): AccessibilityElement[];
|
findAll(selector: string | AttrSelector | SelectorPath): AccessibilityElement[];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user