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

Spike into visual-diffs #3610

Closed
wants to merge 7 commits into from
Closed

Spike into visual-diffs #3610

wants to merge 7 commits into from

Conversation

dlockhart
Copy link
Member

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.

@@ -0,0 +1,33 @@
import '../button-icon.js';
import { fixture, focusWithKeyboard, focusWithMouse, hoverWithMouse, html, screenshotAndCompare } from '../../../tools/web-test-runner-helpers.js';
Copy link
Member Author

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.

@@ -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';
Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

return await document.fonts.ready;
}

export const WaitForMeMixin = dedupeMixin(superclass => class extends superclass {
Copy link
Member Author

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.

@@ -20,8 +38,47 @@ export default {
}
})
]
},
Copy link
Member Author

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>` }
Copy link
Contributor

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

Copy link
Member Author

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.

@svanherk
Copy link
Contributor

Rerunning the jobs here to test the new configure-aws-credentials version


export const screenshotAndCompare = async(elem, name, opts) => {

const rect = elem.getBoundingClientRect();
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member Author

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).

Copy link
Contributor

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.

@dlockhart dlockhart force-pushed the dlockhart/visual-diff-spike branch from ad3e74b to f50ecf0 Compare June 28, 2023 18:34
@bearfriend bearfriend force-pushed the dlockhart/visual-diff-spike branch 3 times, most recently from 549294c to c3feed2 Compare July 19, 2023 18:53
@BrightspaceUI BrightspaceUI deleted a comment from github-actions bot Aug 25, 2023
@github-actions
Copy link
Contributor

Thanks for the PR! 🎉

We've deployed an automatic preview for this PR - you can see your changes here:

URL https://live.d2l.dev/prs/BrightspaceUI/core/pr-3610/

Note
The build needs to finish before your changes are deployed.
Changes to the PR will automatically update the instance.

@svanherk
Copy link
Contributor

svanherk commented Oct 6, 2023

@dlockhart Should be good to close now!

@dlockhart dlockhart closed this Oct 6, 2023
@dlockhart dlockhart deleted the dlockhart/visual-diff-spike branch October 6, 2023 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants