Skip to content

Commit

Permalink
DO NOT MERGE: branch depends on #4457.
Browse files Browse the repository at this point in the history
  • Loading branch information
asafkorem committed May 21, 2024
1 parent fc24e11 commit d0e5e50
Show file tree
Hide file tree
Showing 62 changed files with 2,584 additions and 398 deletions.
79 changes: 78 additions & 1 deletion detox/detox.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ declare global {

readonly web: WebFacade;

readonly system: SystemFacade;

readonly DetoxConstants: {
userNotificationTriggers: {
push: 'push';
Expand Down Expand Up @@ -1038,6 +1040,12 @@ declare global {
* Collection of web matchers
*/
readonly web: ByWebFacade;

/**
* Collection of system-level matchers
* @note System APIs are still in experimental phase and are subject to changes in the near future.
*/
readonly system: BySystemFacade;
}

interface ByWebFacade {
Expand Down Expand Up @@ -1106,6 +1114,24 @@ declare global {
tag(tagName: string): WebMatcher;
}

interface BySystemFacade {
/**
* Find an element on the System-level by its label
* @note System APIs are still in experimental phase and are subject to changes in the near future.
* @example
* system.element(by.system.text('Allow'))
*/
label(text: string): SystemMatcher;

/**
* Find an element on the System-level by its type
* @note System APIs are still in experimental phase and are subject to changes in the near future.
* @example
* system.element(by.system.type('button'))
*/
type(type: string): SystemMatcher;
}

interface NativeMatcher {
/**
* Find an element satisfying all the matchers
Expand All @@ -1127,13 +1153,19 @@ declare global {
}

interface WebMatcher {
__web__: any; // prevent type coersion
__web__: any; // prevent type coercion
}

interface SystemMatcher {
__system__: any; // prevent type coercion
}

interface ExpectFacade {
(element: NativeElement): Expect;

(webElement: WebElement): WebExpect;

(systemElement: SystemElement): SystemExpect;
}

interface WebViewElement {
Expand Down Expand Up @@ -1164,6 +1196,35 @@ declare global {
(matcher?: NativeMatcher): WebViewElement;
}

interface SystemFacade {
/**
* Find an element on the System-level using a system matcher.
* @param systemMatcher a system matcher for the system element.
* @note System APIs are still in experimental phase and are subject to changes in the near future.
* @example
* system.element(by.system.label('Allow'))
*/
element(systemMatcher: SystemMatcher): IndexableSystemElement;
}

interface IndexableSystemElement extends SystemElement {
/**
* Choose from multiple elements matching the same matcher using index
* @note System APIs are still in experimental phase and are subject to changes in the near future.
* @example await system.element(by.system.type('button')).atIndex(1).tap();
*/
atIndex(index: number): SystemElement;
}

interface SystemElement {
/**
* Simulate a tap on the element.
* @note System APIs are still in experimental phase and are subject to changes in the near future.
* @example await system.element(by.system.label('Allow')).tap();
*/
tap(): Promise<void>;
}

interface Expect<R = Promise<void>> {

/**
Expand Down Expand Up @@ -1531,6 +1592,22 @@ declare global {
toExist(): R;
}

interface SystemExpect<R = Promise<void>> {
/**
* Negate the expectation.
* @note System APIs are still in experimental phase and are subject to changes in the near future.
* @example await expect(system.element(by.system.text('Allow'))).not.toExist();
*/
not: this;

/**
* Expect the view to exist in the system-level.
* @note System APIs are still in experimental phase and are subject to changes in the near future.
* @example await expect(system.element(by.system.text('Allow'))).toExist();
*/
toExist(): R;
}

interface IndexableWebElement extends WebElement {
/**
* Choose from multiple elements matching the same matcher using index.
Expand Down
2 changes: 2 additions & 0 deletions detox/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ declare global {
const expect: Detox.DetoxExportWrapper['expect'];
const by: Detox.DetoxExportWrapper['by'];
const web: Detox.DetoxExportWrapper['web'];
const system: Detox.DetoxExportWrapper['system'];

namespace NodeJS {
interface Global {
Expand All @@ -18,6 +19,7 @@ declare global {
expect: Detox.DetoxExportWrapper['expect'];
by: Detox.DetoxExportWrapper['by'];
web: Detox.DetoxExportWrapper['web'];
system: Detox.DetoxExportWrapper['system'];
}
}
}
Loading

0 comments on commit d0e5e50

Please sign in to comment.