Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@appfolio/react-gears-cypress

AppFolio-IM24MIT5.25.0TypeScript support: included

What is this?

readme

react-gears-cypress

What is this?

This is a collection of helpers for testing react-gears browser UIs with Cypress. It provides "finder" functions for finding react-gears components in the DOM, Cypress commands for interacting with compomnents, and some fuzzy text-matching functions to promote more reliable tests.

NOTE: due to historical precedent and the limitations of GitHub packages, this package is confusingly published to two different NPM scope names depending on the repository.

  • Via npmjs.com, it is @appfolio/react-gears-cypress
  • Via npm.pkg.github.com, it is @appfolio-im/react-gears-cypress

The package contents are identical for a given version; the only difference is the distribution mechanism. Clients should choose a distribution repository and use the suitable corresponding scope name. In the long run we hope to move this repository back to the @appfolio org and unify the scopes.

How do I use it?

Install the commands at startup by adding a few lines to cypress/support/commands.js:

import { commands as gears } from 'react-gears-cypress'

// Adds all commands: clear, fill, gears, select. Pass string[] to
// install just some of the commands.
gears.add();

Then, in each test where you want to interact with react-gears components:

import { BlockPanel, Datapair, Input, Select } from 'react-gears-cypress';

cy.component(BlockPanel, 'Personal Information').within(() => {
  cy.component(Datapair, 'First Name').contains('Alice')
  cy.component(Input, 'Last Name').clear().type('Liddel')
  cy.component(Select, 'Favorite Color').select('red')
})

Inputs and other components are always identified by their label/title. The intended usage is with the form-labelling component FormLabelGroup, which provides a <label> element for basically any nested component(s).

import { FormLabelGroup, Input } from '@appfolio/react-gears';

...
const TestableComponent = () => (
  <FormLabelGroup label="foo"><Input/></FormLabelGroup>
)

To deal with labels, values and other text whose whitespace varies, you can use the match helpers which return a RegExp that can be passed instead of a string for more precise or relaxed matching.

import {Datapair, match} from 'react-gears-cypress

// Matches "Name" or "Name *" but not "First Name"
cy.component(Datapair, match.exact('Name'))
// Matches "foo bar", "foo badger bar", "foo badger badger mushroom bar", etc
cy.component(Datapair, match.fuzzyFirstLast('foo', 'bar'))
// Matches "foo\nbar baz", "foo     bar\nbaz", etc
cy.component(Datapair, match.fuzzyMultiline('foo bar baz'))

Contributing

Building the repo

npm run build

Type-checking the repo

npm run type-check

And to run in --watch mode:

npm run type-check:watch

Releasing a new version

To release a new version:

1) Merge your work to master.

2) Check package.json for the previously released version X.Y.Z.

3) Run git log vX.Y.Z..HEAD to review new work from yourself and others. Decide on a new version number according to semver guidelines; for the sake of this example, let's say you decide the new version will be X.Y.W.

  • if you want a prerelease version, the preferred format is X.Y.Z-rc.0 (then rc.1, etc)

4) Run npm version X.Y.W to bump to the new version you decided on above.

  • You can also use npm version <patch|minor|major> if you just want to increment one of those components.

5) Run npm run build to produce distributables with the new version number.

6) npm publish to share your distributables with the world.

  • if publishing a prerelease version you must add --tags=beta to the npm publish command!
  • otherwise, people will accidentally upgrade to your prerelease and you will be forced to support them

7) git push and git push --tags to ensure that the npm version bump is preserved for posterity.

changelog

5.14

NOTE: this point release contains likely interface-breaking changes as compared to 5.5.x; this is made possible because the package is now distributed under a new name and channel.

  • Old: react-gears-cypress (published privately)
  • New: @appfolio/react-gears-cypress (published via npmjs.org) Future releases will be aligned with react-gears' versioning scheme, and will provide guaranteed interface compatibility within a major version.

New features:

  • Helper function commands.add() to register Cypress commands without copypasta.
  • Custom command, component, to replace find and findNegative
    • compatibility shims are provided to ease migration
  • More consistent, reliable behavior for clear and fill commands.
    • Better at dismissing unwanted popups & overlays
    • May blur the subject after typing, if it was focused, to trigger form validations
    • May focus the subject before typing
  • All commands produce log output similar to built-in Cypress commands.
  • Commands and helpers hide the log output of any Cypress commands they invoke.

Significant interface-breaking changes:

  • cannot use a RegExp for labels due to Cypress limitations; Text is now synonymous with string!
  • cy.fill always requires a value (analogous to cy.type); formerly it sometimes accidentally accepted ''.
  • Large changes to the way we deal with popups (i.e. DateInput).

Deprecations:

  • The find module has been deprecated (see components for a superior alternative)
  • The sel module has been deprecated (see components for a superior alternative)

5.5

Aligned CSS selectors with react-gears v5. No significant interface-breaking changes.

1.x

Committed to interface stability. Works with react-gears v4.

0.2

Added finders for Alert, Card, and others.

Added negative finder for Alert.

Added protocol documentation for Finders (overall).

Fixed corner cases w/inconsistent use of match by Finders.

Added test coverage for match & Finders.

0.1

Initial release of the package. Very rough!