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

Unit Testing Components #641

Closed
BE-Webdesign opened this issue May 3, 2017 · 6 comments
Closed

Unit Testing Components #641

BE-Webdesign opened this issue May 3, 2017 · 6 comments
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.

Comments

@BE-Webdesign
Copy link
Contributor

BE-Webdesign commented May 3, 2017

Would unit testing components be of value to the project? It doesn't appear that anyone is pursuing testing too much, maybe that would be a good place for me to be productive? Negatives is it will slow down our CI build and as things change it will slow down PRs, but we could do the component testing separately and eventually streamline it into the CI, so we don't have those kind of project flow problems, until things are more stable.

If you add tests to a component please check the matching box off and edit the list item to feature a # link to the Pull Request that added the initial tests.

Here is a list of components to be tested:

Generic Components:

Editor Components:

  • autosave-monitor
  • block-drop-zone
  • block-inspector
  • block-list
  • block-mover ( Add tests for the BlockMover Component. #980 )
  • block-settings-menu
  • block-switcher ( Add tests for the BlockSwitcher component. #990 )
  • block-toolbar
  • default-block-appender
  • document-outline
  • editor-history
  • editor-notices
  • error-boundary
  • inserter
  • meta-boxes
  • navigable-toolbar
  • page-attributes
  • post-author
  • post-comments
  • post-excerpt
  • post-featured-image
  • post-format
  • post-last-revision
  • post-pending-status
  • post-permalink
  • post-pingbacks
  • post-preview-button
  • post-publish-button
  • post-publish-dropdown
  • post-publish-with-dropdown
  • post-saved-state
  • post-schedule
  • post-sticky
  • post-taxonomies
  • post-text-editor
  • post-title
  • post-trash
  • post-visibility
  • provider
  • table-of-contents
  • unsaved-changes-warning
  • warning
  • word-count
  • writing-flow

Block Components

  • alignment-toolbar
  • autocompleters
  • block-alignment-toolbar
  • block-controls
  • block-description
  • block-edit
  • block-icon
  • color-palette
  • contrast-checker
  • Editable ( 😱 )
  • inspector-controls
    • base-control
    • checkbox-control
    • radio-control
    • range-control
    • select-control
    • text-control
    • textarea-control
    • toggle-control
  • library:
    • audio
    • button
    • categories
    • code
    • cover-image
    • embed
    • freeform
    • gallery
    • heading
    • html
    • image
    • latest-posts
    • list
    • more
    • paragraph
    • preformatted
    • pullquote
    • quote
    • reusable-block
    • separator
    • shortcode
    • table
    • text-columns
    • verse
    • video
  • media-upload-button
  • url-input
@BE-Webdesign BE-Webdesign added the [Type] Question Questions about the design or development of the editor. label May 3, 2017
@nylen
Copy link
Member

nylen commented May 4, 2017

It doesn't appear that anyone is pursuing testing too much

I'd still like to see a rule that we don't merge new code until it has tests. Generally I'm of the opinion that the more automated testing, the better. In fact I've considered changing my name to "James needs-unit-tests Nylen".

Unit-testing components (and refactoring them so that they can be more easily tested) would be extremely valuable and we would love your help with it. Build time should not be a consideration in making this decision.

Integration testing of actual flows would also be very valuable; however, these tests do slow things down quite a bit. Prior art from Calypso: https://github.com/Automattic/wp-e2e-tests

@aduth
Copy link
Member

aduth commented May 4, 2017

What did you have in mind for component testing? What sorts of behaviors should we be testing?

I'm very open toward something like Enzyme, with an emphasis on shallow render testing. I don't think there's a performance worry here (per your note on slower CI build).

We already create a fake DOM context in our test bootstrap:

https://github.com/WordPress/gutenberg/blob/master/bootstrap-test.js

@BE-Webdesign
Copy link
Contributor Author

Yeah, I was thinking of using Enzyme. https://github.com/Automattic/wp-e2e-tests is a lot to take in 😅.

What sorts of behaviors should we be testing?

I think testing rendering with default state, and basic state changes is a good place to start. Testing the editor components as well first would be good as they are not changing as frequently as the block components. That way as the block API changes we will know whether or not our components are breaking at least, (hopefully). I don't know if we will want to use the Full DOM as well to keep track of focusing.

BE-Webdesign added a commit that referenced this issue May 29, 2017
Adds basic button component tests.  Covers cases where the tag name or
other properties are conditionally rendered.  Related to progress on
#641.  This PR adds the components directory to the list of entry points
configured for tests by webpack.
BE-Webdesign added a commit that referenced this issue May 29, 2017
Adds basic rendering dashicon unit tests.  Related to #641.  The
Dashicon should not render when an icon is not provided.
BE-Webdesign added a commit that referenced this issue May 29, 2017
Adds basic FormToggle component tests. Covers cases where the tag name
or other properties are conditionally rendered. Related to progress on
#641.

This introduces Enzyme and the react-test-renderer library as dev
dependencies.

**Testing Instructions**
Run npm i && npm run test-unit ensure tests pass. Change Dashicon logic
to ensure tests fail as they should.
BE-Webdesign added a commit that referenced this issue May 29, 2017
Adds basic withFocusReturn HOCtests. Covers cases dealing with the
handling of the focus. Related to progress on #641.  Adds an extra
conditional to match if the body is focused the active elment should
become the one bound to the HOC, this is necessary as in the HTML DOM
spec it is not supposed to be possible to have `!
document.activeElement` ever be true.

Testing Instructions
Run npm i && npm run test-unit ensure tests pass. Change Dashicon logic
to ensure tests fail as they should.  Verify disposable focus returning
still works.
BE-Webdesign added a commit that referenced this issue May 29, 2017
Adds basic IconButton component tests. Related to progress on #641.

Testing Instructions
Run npm i && npm run test-unit ensure tests pass. Change Dashicon logic
to ensure tests fail as they should.
@BE-Webdesign BE-Webdesign added [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. and removed [Type] Question Questions about the design or development of the editor. labels May 29, 2017
BE-Webdesign added a commit that referenced this issue May 30, 2017
Adds basic Panel component tests. Related to progress on #641.  Covers
the Panel, PanelHeader, and PanelBody components.

Testing Instructions
Run npm i && npm run test-unit ensure tests pass. Change component logic
to ensure tests fail as they should.
BE-Webdesign added a commit that referenced this issue May 30, 2017
Adds basic withFocusReturn HOCtests. Covers cases dealing with the
handling of the focus. Related to progress on #641.  Adds an extra
conditional to match if the body is focused the active elment should
become the one bound to the HOC, this is necessary as in the HTML DOM
spec it is not supposed to be possible to have `!
document.activeElement` ever be true.

Testing Instructions
Run npm i && npm run test-unit ensure tests pass. Change Dashicon logic
to ensure tests fail as they should.  Verify disposable focus returning
still works.
BE-Webdesign added a commit that referenced this issue May 30, 2017
Adds basic IconButton component tests. Related to progress on #641.

Testing Instructions
Run npm i && npm run test-unit ensure tests pass. Change Dashicon logic
to ensure tests fail as they should.
BE-Webdesign added a commit that referenced this issue May 30, 2017
Adds basic Panel component tests. Related to progress on #641.  Covers
the Panel, PanelHeader, and PanelBody components.

Testing Instructions
Run npm i && npm run test-unit ensure tests pass. Change component logic
to ensure tests fail as they should.
BE-Webdesign added a commit that referenced this issue May 30, 2017
Adds basic Spinner component tests. Related to progress on #641.
Testing Instructions
Run npm i && npm run test-unit ensure tests pass. Change component logic
to ensure tests fail as they should.
BE-Webdesign added a commit that referenced this issue Jun 1, 2017
Adds basic Placeholder component tests. Related to progress on #641.
Adds an extra conditional to make testing easier to prevent an element
that eventually renders to null from sticking in the tree when the icon
prop is not present.

Testing Instructions
Run npm i && npm run test-unit ensure tests pass. Change component logic
to ensure tests fail as they should.
BE-Webdesign added a commit that referenced this issue Jun 1, 2017
Adds basic Toolbar component tests. Related to progress on #641.

**Testing Instructions**
Run npm i && npm run test-unit ensure tests pass. Change component logic
to ensure tests fail as they should.
BE-Webdesign added a commit that referenced this issue Jun 1, 2017
Adds tests for the BlockMover Component.  Related to progress on #641.
The tests ensure that the callbacks render properly depending on whether
the block isFirst or isLast.
BE-Webdesign added a commit that referenced this issue Jun 2, 2017
These tests are related to progress on #641. They handle all instance
methods and any conditional rendering logic.

**Testing Instructions**
Verify that registering of blocks is indeed cleaned up and that tests
pass.
BE-Webdesign added a commit that referenced this issue Jun 10, 2017
Adds tests for the BlockMover Component.  Related to progress on #641.
The tests ensure that the callbacks render properly depending on whether
the block isFirst or isLast.
BE-Webdesign added a commit that referenced this issue Jun 14, 2017
These tests are related to progress on #641. They handle all instance
methods and any conditional rendering logic.

**Testing Instructions**
Verify that registering of blocks is indeed cleaned up and that tests
pass.
@BE-Webdesign
Copy link
Contributor Author

Going to breathe some life back into this endeavor, after I touch up meta boxes.

gziolo pushed a commit that referenced this issue Nov 13, 2017
Adds tests for the BlockMover Component.  Related to progress on #641.
The tests ensure that the callbacks render properly depending on whether
the block isFirst or isLast.
@gziolo gziolo added the Good First Issue An issue that's suitable for someone looking to contribute for the first time label Nov 18, 2017
@gziolo gziolo assigned gziolo and unassigned gziolo Nov 27, 2017
@gziolo
Copy link
Member

gziolo commented Nov 27, 2017

I updated the list of all components with the actual status. I omitted edit-post which is going to be moved into its own folder soon. This list is huge. @mtias do we want to keep this issue open?

@mtias
Copy link
Member

mtias commented Nov 29, 2017

Closing for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.
Projects
None yet
Development

No branches or pull requests

5 participants