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

Component-Specific CSS Selector Tests #1574

Merged
merged 48 commits into from
Nov 10, 2022

Conversation

mxriverlynn
Copy link
Contributor

@mxriverlynn mxriverlynn commented Nov 3, 2022

Description

This PR adds component-specific CSS selector tests to PVC. It looks at the css created for a specific component, and compares it to the CSS selectors that are produced by the various lookbook previews for the component. selectors that are not found in the immediate previews (not counting preview params) will fail the component-specific selector CI test and list the components that need additional previews.

some custom selectors are not applicable to this test and can be ignored by modifying the IGNORED_SELECTORS const in test/css/component_specific_selectors_test.rb. these often include selectors based on state, such as :hover or a specific aria tag.

Current Failures

This PR contains a few known failures in the CI step for testing selectors. This is caused by existing components with many selectors that either need to be ignored or for which previews need to be built. Because of the current volatility in these selectors and failures, the CI step for testing selectors is left as optional. This should allow the PR to land as-is, and let future PRs add the needed ignores and previews.

These components are currently known to be failing:

  • Primer::Alpha::ActionList
  • Primer::Beta::BlankSlate
  • Primer::Beta::Button
  • Primer::Beta::Label

Once these components are passing successfully, it's recommended the CI step for testing custom selectors be marked as required.

PR Task List:

  • adds tests that ensure all selectors defined in a component's CSS are used in previews
  • allow component-specific selector ignores, not just global patterns
  • group component options in lookbook previews, to ensure preview coverage of options
  • setup component-specific css selector tests as a separate, optional CI step

Component Preview Groups

There was a need to add many new previews that only differ by one param. Rather than exploding the list of items in the left hand navigation, preview groups are being added to the components where it makes sense.

For example, this is the new preview for Primer::Alpha::SegmentedControl, looking at the "Full Width" group:
image
The full list of components that have grouped previews, added in this PR:

  • Primer::Alpha::Banner
  • Primer::Alpha::SegmentedControl
  • Primer::Beta::Counter
  • Primer::Beta::ProgressBar

Integration

Does this change require any updates to code in production?

no. this primarily applies to CI builds of PVC while incidentally improving lookbook previews for some components

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Added/updated previews

Run Component-Specific Selector tests

bundle exec rake test:component_css

Example Output from Failed Run:

❯ bundle exec rake test:component_css
Run options: --seed 13793

# Running:

...........................................................F

Failure:
ComponentSpecificSelectorsTest#test_all_selectors_are_previewed_for_primer_beta_blankslate [/Users/riverlynn/dev/primer/view_components/test/css/component_specific_selectors_test.rb:47]:
PVC Preview Class 'Primer::Beta::BlankslatePreview' does not render a preview for these selectors:

.blankslate code
.blankslate-capped
.blankslate-spacious
.blankslate-narrow
.blankslate-large img
.blankslate-large h3
.blankslate-large p
.blankslate-clean-background

Selectors without a preview may be ignored by updating 'IGNORED_SELECTORS' in /Users/riverlynn/dev/primer/view_components/test/css/component_specific_selectors_test.rb


rails test /Users/riverlynn/dev/primer/view_components/test/css/component_specific_selectors_test.rb:29

.........F

Failure:
ComponentSpecificSelectorsTest#test_all_selectors_are_previewed_for_primer_beta_label [/Users/riverlynn/dev/primer/view_components/test/css/component_specific_selectors_test.rb:47]:
PVC Preview Class 'Primer::Beta::LabelPreview' does not render a preview for these selectors:

.labels
.label
.Label--large
[ ... ]
.Label--done
.Label--sponsors

Selectors without a preview may be ignored by updating 'IGNORED_SELECTORS' in /Users/riverlynn/dev/primer/view_components/test/css/component_specific_selectors_test.rb


rails test /Users/riverlynn/dev/primer/view_components/test/css/component_specific_selectors_test.rb:29

....F

Failure:
ComponentSpecificSelectorsTest#test_all_selectors_are_previewed_for_primer_beta_button [/Users/riverlynn/dev/primer/view_components/test/css/component_specific_selectors_test.rb:47]:
PVC Preview Class 'Primer::Beta::ButtonPreview' does not render a preview for these selectors:


  .Button[aria-disabled='true']
.Button-content--alignStart
.Button--small
.Button--small .Button-label
[ ... ]
.Button--iconOnly.Button--large

Selectors without a preview may be ignored by updating 'IGNORED_SELECTORS' in /Users/riverlynn/dev/primer/view_components/test/css/component_specific_selectors_test.rb


rails test /Users/riverlynn/dev/primer/view_components/test/css/component_specific_selectors_test.rb:29

...F

Failure:
ComponentSpecificSelectorsTest#test_all_selectors_are_previewed_for_primer_alpha_actionlist [/Users/riverlynn/dev/primer/view_components/test/css/component_specific_selectors_test.rb:47]:
PVC Preview Class 'Primer::Alpha::ActionListPreview' does not render a preview for these selectors:

.ActionListWrap--inset
.ActionListItem[hidden] + .ActionList-sectionDivider
.ActionListItem.ActionListItem--hasSubItem > .ActionListContent
.ActionListItem[aria-checked='true'] .ActionListItem-multiSelectCheckmark
.ActionListItem-action--trailing
[ ... ]
.ActionListItem-action
.ActionListItem--subItem > .ActionListContent > .ActionListItem-label
.ActionList-sectionDivider--filled

Selectors without a preview may be ignored by updating 'IGNORED_SELECTORS' in /Users/riverlynn/dev/primer/view_components/test/css/component_specific_selectors_test.rb


rails test /Users/riverlynn/dev/primer/view_components/test/css/component_specific_selectors_test.rb:29

...........

Finished in 6.671226s, 13.4908 runs/s, 5.9959 assertions/s.
90 runs, 40 assertions, 4 failures, 0 errors, 0 skips

@changeset-bot
Copy link

changeset-bot bot commented Nov 3, 2022

🦋 Changeset detected

Latest commit: fa62e91

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

This PR includes changesets to release 1 package
Name Type
@primer/view-components 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

@mxriverlynn mxriverlynn temporarily deployed to review-pr-1574 November 3, 2022 14:45 Inactive
@mxriverlynn mxriverlynn temporarily deployed to github-pages November 3, 2022 14:49 Inactive
@mxriverlynn mxriverlynn temporarily deployed to review-pr-1574 November 3, 2022 15:33 Inactive
@mxriverlynn mxriverlynn temporarily deployed to github-pages November 3, 2022 15:38 Inactive
@mxriverlynn mxriverlynn temporarily deployed to review-pr-1574 November 3, 2022 15:52 Inactive
@mxriverlynn mxriverlynn temporarily deployed to github-pages November 3, 2022 15:56 Inactive
@mxriverlynn mxriverlynn temporarily deployed to review-pr-1574 November 3, 2022 15:59 Inactive
@mxriverlynn mxriverlynn temporarily deployed to github-pages November 3, 2022 16:03 Inactive
@mxriverlynn mxriverlynn temporarily deployed to review-pr-1574 November 3, 2022 16:12 Inactive
@mxriverlynn mxriverlynn temporarily deployed to github-pages November 3, 2022 16:16 Inactive
@jonrohan
Copy link
Member

jonrohan commented Nov 3, 2022

adds tests that ensure the CSS selectors used by a component are valid

Let's do this one in a separate PR

@jonrohan jonrohan added the skip changeset Pull requests that don't change the library output label Nov 3, 2022
cancel-in-progress: true

jobs:
selectors:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move this to the test.yml file?

.github/workflows/test_css.yml Outdated Show resolved Hide resolved
name: Component-specific selectors
runs-on: ubuntu-latest
strategy:
fail-fast: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure the fail-fast is doing anything here outside of the matrix context

@github-actions
Copy link
Contributor

github-actions bot commented Nov 10, 2022

⚠️ Visual differences found

Our visual comparison tests found UI differences. Please review the differences by viewing the files changed tab to ensure that the changes were intentional.

Review visual differences

…or-tests' into mxriverlynn/component-css-selector-tests
@mxriverlynn mxriverlynn temporarily deployed to review-pr-1574 November 10, 2022 18:55 Inactive
Copy link
Member

@jonrohan jonrohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@mxriverlynn mxriverlynn temporarily deployed to github-pages November 10, 2022 19:00 Inactive
Comment on lines -56 to -58
/* &:focus {
@mixin focusOutline;
} */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this commented out, PCSS copies it as a literal comment with no parsing into the final css output. this was causing test/components/component_css_test.rb to fail in the test suite, because that test looks for the presence of any & regardless of context

Copy link
Member

@jonrohan jonrohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ship it :shipit:

@jonrohan jonrohan merged commit b3e351d into main Nov 10, 2022
@jonrohan jonrohan deleted the mxriverlynn/component-css-selector-tests branch November 10, 2022 21:07
@primer-css primer-css mentioned this pull request Nov 10, 2022
@simurai simurai mentioned this pull request Nov 14, 2022
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css Pull requests that update CSS code skip changeset Pull requests that don't change the library output
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants