-
Notifications
You must be signed in to change notification settings - Fork 23
[PNP-9605] Allow every component's CSS files to render on a component's preview page #5055
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
base: main
Are you sure you want to change the base?
Conversation
bc7d5c0
to
c2bd428
Compare
baec3ea
to
274e5e3
Compare
274e5e3
to
00ced7c
Compare
223e9ac
to
3181771
Compare
c6428b3
to
9154f7a
Compare
9154f7a
to
0c7e5bb
Compare
0c7e5bb
to
cd825b2
Compare
It has an empty, unused stylesheet, so we can delete it.
cd825b2
to
c239101
Compare
c239101
to
dd1307d
Compare
dd1307d
to
1f6d957
Compare
1f6d957
to
b5eea1b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
end | ||
|
||
it "has a correctly named SCSS file", not_applicable: component_name.in?(%w[contextual_breadcrumbs contextual_footer contextual_sidebar google_tag_manager_script list machine_readable_metadata meta_tags]) do | ||
it "has a correctly named SCSS file", not_applicable: component_name.in?(%w[contextual_breadcrumbs contextual_footer contextual_sidebar copy_to_clipboard google_tag_manager_script list machine_readable_metadata meta_tags]) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised we didn't do this earlier, which always makes me nervous that there's some reason we haven't thought of 😁 You might also want to remove these lines, which reference this stylesheet: https://github.com/alphagov/govuk_publishing_components/blob/main/lib/govuk_publishing_components/config.rb#L40-L41
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like there's a test for this file. That might be a Rails convention (I'm not sure) but there's a lot of things happening in here. Would it be worth raising an issue that we should add a test?
<% content_for :application_stylesheet do %> | ||
<% content_for :application_stylesheet do | ||
if @all_components | ||
if @render_component_first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just trying to get my head around this... if we don't render the component stylesheet first, is it loaded by the component? Only if we do render the component stylesheet first, does that mean it gets loaded a second time by the component further down?
visit "/component-guide/warning_text/preview" | ||
expect(page).to have_css("link[rel=stylesheet]", visible: :hidden, count: 2) | ||
expect(page).to have_css("link[rel='stylesheet'][href*='/assets/component_guide/application-']", visible: :hidden) | ||
expect(page).to have_css("link[rel='stylesheet'][href*='/assets/govuk_publishing_components/components/_warning-text-']", visible: :hidden) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably don't need to also check that the two specific stylesheets are hidden, given that this has already been checked on line 47 (same comment for the following tests).
[1]: https://github.com/alphagov/govuk_publishing_components/blob/e455358c8a031403c6b5b0670f891c922919a3ca/.github/workflows/visual-regression-tests.yml | ||
## CSS Specificty testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: I think it's specificity
.
## CSS Specificty testing | ||
It's possible that changes you make to a component can influence other components if component isolation breaks. To help prevent this, you can test a component alongside every other components CSS file to ensure there are no unexpected changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: I think the sentence is clear enough as just It's possible that changes you make to a component can influence other components.
It's possible that changes you make to a component can influence other components if component isolation breaks. To help prevent this, you can test a component alongside every other components CSS file to ensure there are no unexpected changes. | ||
You can test your component alongside every other component's CSS by adding `?all_components=true` to the `/preview` route for that component. For example, visiting `component-guide/button/preview?all_components=true` will show you the button component on a page that also contains every other component's CSS file. By default, the component you're testing's CSS will load at the end of the list, and therefore you should also test how the component looks when its CSS is loaded first. This can be achieved by adding `&render_component_first=true` onto the query string, for example `component-guide/button/preview?all_components=true&render_component_first=true`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion:
Change the component guide preview page URL as follows to test a component with other component CSS.
- `?all_components=true` e.g. https://components.publishing.service.gov.uk/component-guide/button/preview?all_components=true
- `?all_components=true&render_component_first=true` will load the current component CSS after other component CSS (defaults to loading the current component CSS last) e.g. https://components.publishing.service.gov.uk/component-guide/button/preview?all_components=true&render_component_first=true
You can test your component alongside every other component's CSS by adding `?all_components=true` to the `/preview` route for that component. For example, visiting `component-guide/button/preview?all_components=true` will show you the button component on a page that also contains every other component's CSS file. By default, the component you're testing's CSS will load at the end of the list, and therefore you should also test how the component looks when its CSS is loaded first. This can be achieved by adding `&render_component_first=true` onto the query string, for example `component-guide/button/preview?all_components=true&render_component_first=true`. | ||
|
||
We are not using these versions of the component preview on Percy in order to stay within our monthly screenshot usage limits. However you can use Percy in your PR to automatically detect any visual changes when all component's CSS are rendered at once, however the code change to achieve this should not be merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: You can use Percy in your PR to automatically detect any visual changes when all component's CSS are rendered at once, however the code change to achieve this should not be merged.
|
||
We are not using these versions of the component preview on Percy in order to stay within our monthly screenshot usage limits. However you can use Percy in your PR to automatically detect any visual changes when all component's CSS are rendered at once, however the code change to achieve this should not be merged. | ||
|
||
To do this, navigate to `spec/visual_regression_tests/all_components_spec.rb` and replace `URI("#{link[:href]}/preview?percy=true")` with the all components query params: either ` URI("#{link[:href]}/preview?percy=true&all_components=true")` or `URI("#{link[:href]}/preview?percy=true&all_components=true&render_component_first=true")`. This will set Percy to use this new page for screenshots. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems quite complicated - I worry that people won't do this. Maybe not for this PR, but maybe there's a way of configuring this state more easily - perhaps by running ./startup.sh
with a different parameter, or some other on/off switch.
What
/preview
route on a componentall_components=true
e.g. https://components-gem-pr-5055.herokuapp.com/component-guide/button/preview?all_components=true - this will render the component alongside every other component's CSS filerender_component_first=true
e.g. https://components-gem-pr-5055.herokuapp.com/component-guide/button/preview?all_components=true&render_component_first=true this will load the component first before all the other CSS filespercy=true
e.g. https://components-gem-pr-5055.herokuapp.com/component-guide/button/preview?percy=true - this just refactors some existing functionality that shortened the page title for Percy tests. The previous code used a regex string replace, which was a lot less flexible.Why
accordion
and only test theaccordion
previews, but their change could have accidentally brokenwarning_text
. That wouldn't be surfaced by our existing automatic testing, and therefore it would be on the dev to have checked ifwarning_text
styles are now influenced byaccordion
styles. We can't expect devs to go and check every single component preview when they modify one component's styles, so it would be good if we can incorporate the automatic Percy tests in the future. We can manually trigger a Percy visual diff though (as outlined here), so maybe that's something to run every so often just to check things are OK.Potential things to add
Some things I have left out that may be worth adding:
/preview
pages so that devs can easily access the specificity test pagesrender_component_first
by making the component the first item in the data structure, but it seems thatComponentDoc
objects aren't correctly setting asource
, so at render time I couldn't determine whether it was an app component or a gem component. Still, it's probably possible to do this if you think it's worth it but I may have to refactor theComponentDoc
model.Visual Changes
This PR won't result in any visual changes, but the visual changes that have been surfaced by this work are in the following PRs: #5056 and #5061