Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Types):Fixed the types of whileElement to be aligned with the documentation … #4485

Merged
merged 5 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions detox/detox.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1279,12 +1279,31 @@ declare global {
* Performs the action repeatedly on the element until an expectation is met
* @example await waitFor(element(by.text('Item #5'))).toBeVisible().whileElement(by.id('itemsList')).scroll(50, 'down');
*/
whileElement(by: NativeMatcher): NativeElement & WaitFor;
whileElement(by: NativeMatcher): NativeElementWaitableActions & WaitFor;

// TODO: not sure about & WaitFor - check if we can chain whileElement multiple times
}

interface NativeElementActions {
interface NativeElementWaitableActions {

/**
* Scrolls a given amount of pixels in the provided direction, starting from the provided start positions.
* @param pixels - independent device pixels
* @param direction - left/right/up/down
* @param startPositionX - the X starting scroll position, in percentage; valid input: `[0.0, 1.0]`, `NaN`; default: `NaN`—choose the best value automatically
* @param startPositionY - the Y starting scroll position, in percentage; valid input: `[0.0, 1.0]`, `NaN`; default: `NaN`—choose the best value automatically
* @example await element(by.id('scrollView')).scroll(100, 'down', NaN, 0.85);
* @example await element(by.id('scrollView')).scroll(100, 'up');
*/
scroll(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an extra test to:

https://github.com/wix/Detox/blob/feat/refine_whileElement_api/detox/test/types/detox-global-tests.ts#L93

Invoke the waitFor(...).scroll(pixels, direction, startX, startY, in addition to (pixels, directions).

Besides, you can add one more test like // @ts-expect-error to ensure that waitFor(...) does not have tap or some other common method.

pixels: number,
direction: Direction,
startPositionX?: number,
startPositionY?: number
): Promise<void>;
}

interface NativeElementActions extends NativeElementWaitableActions{
/**
* Simulate tap on an element
* @param point relative coordinates to the matched element (the element size could changes on different devices or even when changing the device font size)
Expand Down Expand Up @@ -1352,22 +1371,6 @@ declare global {
*/
tapReturnKey(): Promise<void>;

/**
* Scrolls a given amount of pixels in the provided direction, starting from the provided start positions.
* @param pixels - independent device pixels
* @param direction - left/right/up/down
* @param startPositionX - the X starting scroll position, in percentage; valid input: `[0.0, 1.0]`, `NaN`; default: `NaN`—choose the best value automatically
* @param startPositionY - the Y starting scroll position, in percentage; valid input: `[0.0, 1.0]`, `NaN`; default: `NaN`—choose the best value automatically
* @example await element(by.id('scrollView')).scroll(100, 'down', NaN, 0.85);
* @example await element(by.id('scrollView')).scroll(100, 'up');
*/
scroll(
pixels: number,
direction: Direction,
startPositionX?: number,
startPositionY?: number
): Promise<void>;

/**
* Scroll to index.
* @example await element(by.id('scrollView')).scrollToIndex(10);
Expand Down
8 changes: 8 additions & 0 deletions detox/test/types/detox-global-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ describe("Test", () => {
.whileElement(by.id("ScrollView630"))
.scroll(50, "down");

await waitFor(element(by.text("Text5")))
.toBeVisible()
.whileElement(by.id("ScrollView630"))
.scroll(50, "down", 0.5, 0.5);

// @ts-expect-error
await waitFor(element(by.text("Text5"))).toBeVisible().whileElement(by.id("ScrollView630")).tap();

await web.element(by.web.id("btnSave")).tap();
await web.element(by.web.id("btnSave")).runScript('(el) => el.click()');
const scriptResult = await web.element(by.web.id("btnSave")).runScript(function (el: any, text: string) {
Expand Down
Loading