interactors icon indicating copy to clipboard operation
interactors copied to clipboard

Should Checkbox `checked` filter also exclude any indeterminate checkboxes

Open wKich opened this issue 3 years ago • 2 comments

Checkbox has two different flags checked and indeterminate both can be in two states

  • checked=false and indeterminate=false image

  • checked=true and indeterminate=false image

  • checked=false and indeterminate=true image

  • checked=true and indeterminate=true image

As you can see the indeterminate has higher priority for UI view. And it doesn't matter if a checkbox has checked or not when indeterminate is true. User sees only a checkbox in an indeterminate state.

For now, Checkbox interactor doesn't check the indeterminate state for the checked filter. And if user has the checkbox in forth case the Checkbox({ checked: true }).exists() doesn't throw an exception. But for a real user, who works in a browser, the view will be different, he sees only a checkbox in an indeterminate state.

Should we change Checkbox interactor's checked filter API?

There are possible variants:

  • 👀 checked: (element) => element.checked && !element.indeterminate
  • 👍 checked: (element) => element.indeterminate ? 'indeterminate' : element.checked

wKich avatar Apr 21 '21 07:04 wKich

I'm generally in favor of the idea that the filter should be not just a reflection of the DOM values, but of what the user sees. It feels like option (2) is the right API.

My biggest question though is will this introduce awkwardness into tests written in TypeScript because the type is now essentially boolean | 'indeterminate' which is not something you see every day. The only thing I can really see it being weird is that you would no longer be able to use it with boolean matchers. But does such a thing exist?

cowboyd avatar Apr 21 '21 08:04 cowboyd

We can add a special enum for that. But it requires to do a few of changes to matchers and output formaters

wKich avatar Apr 21 '21 08:04 wKich