-
Notifications
You must be signed in to change notification settings - Fork 25
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
Spike into visual-diffs #3610
Spike into visual-diffs #3610
Conversation
@@ -0,0 +1,33 @@ | |||
import '../button-icon.js'; | |||
import { fixture, focusWithKeyboard, focusWithMouse, hoverWithMouse, html, screenshotAndCompare } from '../../../tools/web-test-runner-helpers.js'; |
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.
Imagine these being imported from @brightspace-ui/testing-helpers
.
components/icons/icon.js
Outdated
@@ -6,8 +6,9 @@ import { loadSvg } from '../../generated/icons/presetIconLoader.js'; | |||
import { RtlMixin } from '../../mixins/rtl/rtl-mixin.js'; | |||
import { runAsync } from '../../directives/run-async/run-async.js'; | |||
import { unsafeSVG } from 'lit/directives/unsafe-svg.js'; | |||
import { WaitForMeMixin } from '../../tools/web-test-runner-helpers.js'; |
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.
Example of a component that does asynchronous work (dynamically importing the icon) that we want to wait for before visual-diffing.
tools/visual-diff-plugin.js
Outdated
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 is the @web/test-runner
plugin that consumers don't need to know about and will likely be buried in @brightspace-ui/testing-helpers
.
tools/visual-diff-reporter.js
Outdated
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 doesn't do anything really, but is an example of a custom reporter. This is where we'd implement the generation of our HTML report files.
tools/web-test-runner-helpers.js
Outdated
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.
Most if not all of this will live in @brightspace-ui/testing-helpers
.
tools/web-test-runner-helpers.js
Outdated
return await document.fonts.ready; | ||
} | ||
|
||
export const WaitForMeMixin = dedupeMixin(superclass => class extends superclass { |
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 will likely be defined in @brightspace-ui/core
.
web-test-runner.config.js
Outdated
@@ -20,8 +38,47 @@ export default { | |||
} | |||
}) | |||
] | |||
}, |
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 think we'll want to take all of this and turn it into a shared config that consumers can just import from @brightspcae-ui/testing-helpers
.
{ category: 'normal', f: html`<d2l-button-icon icon="tier1:gear" text="Icon Button"></d2l-button-icon>` }, | ||
{ category: 'translucent', f: html`<d2l-button-icon icon="tier1:gear" text="Icon Button" translucent></d2l-button-icon>`, theme: 'translucent' }, | ||
{ category: 'dark', f: html`<d2l-button-icon icon="tier1:gear" text="Icon Button" theme="dark"></d2l-button-icon>`, theme: 'dark' }, | ||
{ category: 'custom', f: html`<d2l-button-icon icon="tier1:gear" text="Icon Button" style="--d2l-button-icon-min-height: 1.5rem; --d2l-button-icon-min-width: 1.5rem; --d2l-button-icon-border-radius: 4px; --d2l-button-icon-focus-box-shadow: 0 0 0 1px #ffffff, 0 0 0 3px #006fbf; --d2l-button-icon-fill-color: var(--d2l-color-celestine); --d2l-button-icon-fill-color-hover: var(--d2l-color-celestine-minus-1);"></d2l-button-icon>` } |
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.
Would it be possible to pass in a css
template literal to fixture
that would automatically get added and removed from the page? 🤔 Could clean this kind of thing up a bit
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.
Maybe? We have to be careful because we still want the root of the fixture to be the button, so we couldn't drop a <style>
element in as a sibling. But maybe we could do a constructible stylesheet and apply it to the <body>
. Worth experimenting for sure, I'll add it to the Confluence doc.
Rerunning the jobs here to test the new |
8a4dbc1
to
e382877
Compare
tools/web-test-runner-helpers.js
Outdated
|
||
export const screenshotAndCompare = async(elem, name, opts) => { | ||
|
||
const rect = elem.getBoundingClientRect(); |
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.
We currently do some fancy logic to handle getting the proper rect
for dropdowns (and filter, etc.): https://github.com/BrightspaceUI/core/blob/main/components/dropdown/test/dropdown-helper.js#L28-L44
Do we see that being added here, or providing users a way to override? Or should they create a "large enough" wrapper element?
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.
Making a wrapper element that is "large enough" is the simplest, although adjusting the hard-coded dimensions any time the contents change is a bit of an annoyance. It can provide some degree of buffer when contents change that would normally leave us without a diff due to the size changing, though my understanding is that we're going to improve that aspect. I tend to like being able to override with something more automatic like this.
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.
Having said that, the consumer could always have some script that resizes the wrapper before the screenshot.
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.
What if they could do something like this in fixture
:
const elem = await fixture(html`<d2l-my-elem>...</d2l-my-elem>`, {
margin: {
blockEnd: 200,
inlineStart: 50,
inlineEnd: 75
}
});
Then we'd reserve 200px
at the bottom, 50px
to the left and 75px
to the right in the form of padding on the body (we default to 30px
today). Alternately we could just put a huge amount of padding on the body -- like 500px
-- but then the viewport size would need to change.
So that would reserve the space initially as it renders. Then when they take the screenshot maybe it can reuse that value when it captures the rectangle? screenshotAndCompare
already supports a single-value "margin" option (defaults to 10px
all around).
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 think that would work if the consumer hard-codes it.
Seems like that wouldn't work if the consumer wants to avoid hard-coding - if they wanted to measure the opener + the content to figure out the size needed (like the helper Stacey linked), it needs to have access to the element, but it won't exist yet. 🐔 & 🥚 ... 😄 . It would need a way to adjust margin after it's been rendered. Or, for the rare cases where a consumer might want this, they just include a wrapper div in their fixture and they set the dimensions of it based on measurement just before doing the screenshot.
ad3e74b
to
f50ecf0
Compare
549294c
to
c3feed2
Compare
c3feed2
to
49d7790
Compare
Thanks for the PR! 🎉 We've deployed an automatic preview for this PR - you can see your changes here:
|
@dlockhart Should be good to close now! |
This isn't intended to ever merge, but goes alongside this spike results document to show how things could look in practice.
Ultimately, a lot of this will get broken out into a new
@brightspace-ui/testing-helpers
library.