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

Add filter delegation #90

Merged
merged 1 commit into from
Oct 21, 2021
Merged

Add filter delegation #90

merged 1 commit into from
Oct 21, 2021

Conversation

jnicklas
Copy link
Collaborator

@jnicklas jnicklas commented Oct 1, 2021

A problem we've had with writing interactors is that filters do not compose in any meaningful way. Often we want to have a filter depend on another interactor to create better encapsulation. With filter delegation, building on filter methods introduced in #89, we can elegantly compose interactor filters.

An example:

const Calendar = HTML.extend<HTMLElement>("calendar")
  .selector("div.calendar")

const Datepicker = HTML.extend<HTMLDivElement>("datepicker")
  .selector("div.datepicker")
  .filters({
    open: Calendar().exists(),
    month: Calendar().find(Header()).text(),
  })
  .actions({
    toggle: async interactor => {
      await interactor.find(TextField({ placeholder: "YYYY-MM-DD" })).click();
    }
  });

In the future we may want to add support for delegated locators as well, but this is not included as part of this PR.

Depends on #89

@changeset-bot
Copy link

changeset-bot bot commented Oct 1, 2021

🦋 Changeset detected

Latest commit: e95ab99

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@interactors/html Minor
@interactors/material-ui Patch
@interactors/with-cypress Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link

netlify bot commented Oct 1, 2021

✔️ Deploy Preview for interactors canceled.

🔨 Explore the source changes: e95ab99

🔍 Inspect the deploy log: https://app.netlify.com/sites/interactors/deploys/616ff78b1e9808000734e7dc

@jnicklas jnicklas requested a review from cowboyd October 19, 2021 15:04
@jnicklas jnicklas marked this pull request as ready for review October 19, 2021 15:04
A filter can be delegated to another interactor, in this way we don't
have to endlessly repeat fitler definitions, and we can compose
interactor filters with each other.
@taras
Copy link
Member

taras commented Oct 19, 2021

  .filters({
    open: Calendar().exists(),
    month: Calendar().find(Header()).text(),
  })

This looks mind-blowingly good.

@cowboyd
Copy link
Member

cowboyd commented Oct 20, 2021

How do we handle "portals" "wormholes" or other techniques to render "pseudo-children" where visually and in the component tree, the child is associated with the parent, but in the DOM, it is in a completely separate tree?

In these cases, we want to break context and escape to the top of the page.

@jnicklas
Copy link
Collaborator Author

How do we handle "portals" "wormholes" or other techniques to render "pseudo-children" where visually and in the component tree, the child is associated with the parent, but in the DOM, it is in a completely separate tree?

In these cases, we want to break context and escape to the top of the page.

You can use the Page interactor for this, since it provides a wormhole:

  .filters({
     contextMenu: Page.find(ContextMenu())
  })

@jnicklas jnicklas merged commit 711f993 into main Oct 21, 2021
@jnicklas jnicklas deleted the filter-delegation branch October 21, 2021 15:50
This was referenced Oct 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants