Skip to content

Commit

Permalink
Fix types and documentation for scrollTo() alignment options (#2703)
Browse files Browse the repository at this point in the history
* Fix types and documentation for scrollTo() alignment options

Signed-off-by: Bart van Oort <bart@vanoort.is>

* Bump package version to 1.3.10

Signed-off-by: Bart van Oort <bart@vanoort.is>

---------

Signed-off-by: Bart van Oort <bart@vanoort.is>
  • Loading branch information
bvobart authored May 14, 2023
1 parent d831a72 commit 532c62c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
11 changes: 5 additions & 6 deletions lib/taiko.js
Original file line number Diff line number Diff line change
Expand Up @@ -1246,24 +1246,23 @@ async function mouseAction(selector, action, coordinates, options = {}) {
/**
* Scrolls the page to the given element.
* The alignment parameters can be overridden, see below.
* Tthe possible values reference are available at the https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView.
*
* A reference of the possible values for the alignment parameters is available at https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView.
*
* @example
* await scrollTo('Get Started')
* @example
* await scrollTo(link('Get Started'))
* @example
* await scrollTo('Get Started',{ alignments: { block: 'center', inline: 'center' }})
* await scrollTo('Get Started', { blockAlignment: 'center', inlineAlignment: 'center' })
*
* @param {selector|string} selector - A selector of an element to scroll to.
* @param {Object} options
* @param {boolean} [options.waitForNavigation=true] - Wait for navigation after the goto. Default navigationTimeout is 30 seconds to override pass `{ navigationTimeout: 10000 }` in `options` parameter.
* @param {string[]} [options.waitForEvents = []] - Events available to wait for ['DOMContentLoaded', 'loadEventFired', 'networkAlmostIdle', 'networkIdle', 'firstPaint', 'firstContentfulPaint', 'firstMeaningfulPaint', 'targetNavigated']
* @param {number} [options.navigationTimeout=30000] - Navigation timeout value in milliseconds for navigation after click.
* @param {number} [options.waitForStart = 100] - time to wait for navigation to start. Accepts value in milliseconds.
* @param {string} [options.blockAlignment = 'nearest'] - Defines vertical alignment.
* @param {string} [options.inlineAligment = 'nearest'] - Defines horizontal alignment.
* @param {number} [options.waitForStart = 100] - Time to wait for navigation to start. Accepts value in milliseconds.
* @param {string} [options.blockAlignment = 'nearest'] - Defines vertical alignment. One of `start`, `center`, `end` or `nearest`.
* @param {string} [options.inlineAlignment = 'nearest'] - Defines horizontal alignment. One of `start`, `center`, `end` or `nearest`.
*
* @returns {Promise<void>}
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json.schemastore.org/package",
"name": "taiko",
"version": "1.3.9",
"version": "1.3.10",
"description": "Taiko is a Node.js library for automating Chromium based browsers",
"main": "bin/taiko.js",
"bin": {
Expand Down
7 changes: 6 additions & 1 deletion types/taiko/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export interface NavigationOptions extends BasicNavigationOptions, EventOptions
waitForStart?: number;
}

export interface ScrollOptions extends NavigationOptions {
blockAlignment?: 'start' | 'center' | 'end' | 'nearest';
inlineAlignment?: 'start' | 'center' | 'end' | 'nearest';
}

export interface ReloadOptions extends NavigationOptions {
ignoreCache?: boolean;
}
Expand Down Expand Up @@ -501,7 +506,7 @@ export function mouseAction(
options?: ForcedNavigationOptions,
): Promise<void>;
// https://docs.taiko.dev/api/scrollto
export function scrollTo(selector: SearchElement, options?: NavigationOptions): Promise<void>;
export function scrollTo(selector: SearchElement, options?: ScrollOptions): Promise<void>;
// https://docs.taiko.dev/api/scrollright
export function scrollRight(selector?: SearchElement | number, px?: number): Promise<void>;
// https://docs.taiko.dev/api/scrollleft
Expand Down

1 comment on commit 532c62c

@Makeqw
Copy link

@Makeqw Makeqw commented on 532c62c Mar 8, 2024

Choose a reason for hiding this comment

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

/**

  • Scrolls the page to the given element.
  • The alignment parameters can be overridden, see below.
  • The possible values reference is available at https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView.
  • @example
  • await scrollTo('Get Started')
  • @example
  • await scrollTo(link('Get Started'))
  • @example
  • await scrollTo('Get Started', { blockAlignment: 'center', inlineAlignment: 'center' })
  • @param {selector|string} selector - A selector of an element to scroll to.
  • @param {Object} options
  • @param {boolean} [options.waitForNavigation=true] - Wait for navigation after the goto. Default navigationTimeout is 30 seconds; to override, pass { navigationTimeout: 10000 } in options parameter.
  • @param {string[]} [options.waitForEvents = []] - Events available to wait for ['DOMContentLoaded', 'loadEventFired', 'networkAlmostIdle', 'networkIdle', 'firstPaint', 'firstContentfulPaint', 'firstMeaningfulPaint', 'targetNavigated']
  • @param {number} [options.navigationTimeout=30000] - Navigation timeout value in milliseconds for navigation after click.
  • @param {number} [options.waitForStart = 100] - Time to wait for navigation to start. Accepts value in milliseconds.
  • @param {string} [options.blockAlignment = 'nearest'] - Defines vertical alignment. One of start, center, end, or nearest.
  • @param {string} [options.inlineAlignment = 'nearest'] - Defines horizontal alignment. One of start, center, end, or nearest.
  • @returns {Promise}
    */

Please sign in to comment.