wix/Detox

Provide missing element visibility expectations API.

Aperta

#3049 aperta il 1 nov 2021

 (6 commenti) (1 reazione) (0 assegnatari)JavaScript (1942 fork)batch import
hacktoberfestplatform: androidplatform: iosstatus: acceptedstatus: discussiontype: enhancement ⚡️user: looking for contributors

Metriche repository

Star
 (10.558 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

The Issue

While extending the toBeVisible expectation API to receive an optional parameter of visibility threshold, in response to a feature request (see issue), another missing feature was brought up for discussion, alongside some questions regarding the current API.

  1. The current API for visibility expectation (toBeVisible(pct?: number)) receives only integers within the range [1, 100], and checks whether the element is visible at least with the given visibility threshold, because of underlying constraints (espresso matchers) and therefore cannot be used to check whether the view has any visibility (>0% visible), or whether is not visible at all.
  2. Negating the expectation with not, creates a confusing statement since it is quite nonintuitive what is the expected result (for example, not.toBeVisible(10), this expects the view to have less than 10% visibility).
  3. The current API name for the expectation does not implies that the pct argument is a threshold, and that the check includes the threshold as a valid visibility percentage (at-least N% visible, and not greater-than N% visible).
  4. The default value of the visibility threshold is 75, which is also very nonintuitive or makes any sense.

Suggested Solution

Add new APIs for visibility expectations, to allow any kind of visibility check with more descriptive names, and to deprecated the current method.

(1) toHaveVisibility(): checks whether the element is visible at all (the visibility percent is greater than 0%). (2) toHaveVisibilityGreaterThan(percent): checks whether the element visibility percent is greater than percent. (3) toHaveVisibilityGreaterThanOrEqualTo(percent): checks whether the element visibility percent is greater than or equal to percent.

Also, if we want to achieve an even higher level of readability in the tests, we can also provide aliases for the negations of (2) and (3):

(4) toHaveVisibilityLowerThan(percent): checks whether the element visibility percent is lower than percent. (5) toHaveVisibilityLowerThanOrEqualTo(percent): checks whether the element visibility percent is lower than or equal to percent.

Guida contributor