-
Notifications
You must be signed in to change notification settings - Fork 0
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
US156331 - Add ability to indicate the actual element to use for size calculations for the screenshot #146
Changes from 1 commit
9f9def3
da9ac4b
db788a4
1073c67
74a9b7f
dbcc21e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,13 @@ mocha.setup({ | |
}); | ||
/* eslint-enable */ | ||
|
||
function findRealSize(elem) { | ||
if (!elem.shadowRoot) return elem; | ||
const nestedSizedElem = elem.shadowRoot.querySelector('.vdiff-size'); | ||
if (!nestedSizedElem) return elem; | ||
return findRealSize(nestedSizedElem); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool. So if an element doesn't define its size at all but instead that falls to something in its shadow root, it can just put the class on that element and it'll recurse -- nice! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah exactly! And in theory, this should "just work" for consumers wrapping a |
||
} | ||
|
||
async function ScreenshotAndCompare(opts) { | ||
|
||
if (window.d2lTest) { | ||
|
@@ -27,7 +34,11 @@ async function ScreenshotAndCompare(opts) { | |
} | ||
|
||
const name = this.test.fullTitle(); | ||
const rect = this.elem === document ? null : this.elem.getBoundingClientRect(); | ||
let rect = null; | ||
if (this.elem !== document) { | ||
const realSizedElem = findRealSize(this.elem); | ||
rect = realSizedElem.getBoundingClientRect(); | ||
} | ||
const slowDuration = this.test.slow(); | ||
let result = await executeServerCommand('brightspace-visual-diff-compare', { name, rect, slowDuration, opts }); | ||
if (result.resizeRequired) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,6 +196,7 @@ export class WTRConfig { | |
config.groups.forEach(g => g.browsers = this.getBrowsers(g.browsers)); | ||
|
||
if (open || watch) { | ||
config.testsFinishTimeout = 15 * 60 * 1000; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit unrelated, but when I was trying to debug my new tests with |
||
config.plugins ??= []; | ||
const currentPattern = files || config.groups.find(g => g.name === group)?.files; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { css, html, LitElement } from 'lit'; | ||
import { defineCE, expect, fixture, hoverElem } from '../../src/browser/index.js'; | ||
import { executeServerCommand } from '@web/test-runner-commands'; | ||
//import { executeServerCommand } from '@web/test-runner-commands'; | ||
import { unsafeHTML } from 'lit/directives/unsafe-html.js'; | ||
|
||
const elementTag = defineCE( | ||
class extends LitElement { | ||
|
@@ -39,6 +40,40 @@ const elementTag = defineCE( | |
} | ||
); | ||
|
||
const fixedElementTag = defineCE( | ||
class extends LitElement { | ||
static get styles() { | ||
return css` | ||
div { | ||
background-color: white; | ||
border: 1px solid purple; | ||
border-radius: 8px; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
box-sizing: border-box; | ||
position: fixed; | ||
} | ||
`; | ||
} | ||
render() { | ||
return html` | ||
<div class="vdiff-size"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This represents typical |
||
<slot></slot> | ||
</div> | ||
`; | ||
} | ||
} | ||
); | ||
|
||
const nestedElementTag = defineCE( | ||
class extends LitElement { | ||
render() { | ||
return html`${unsafeHTML(` | ||
<${fixedElementTag} class="vdiff-size"><${elementTag} text="Visual Difference"></${elementTag}></${fixedElementTag}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This represents what is likely to happen for consumers of |
||
`)}`; | ||
} | ||
} | ||
); | ||
|
||
describe('element-matches', () => { | ||
[ | ||
{ name: 'default' }, | ||
|
@@ -58,6 +93,16 @@ describe('element-matches', () => { | |
await fixture(`<${elementTag} text="Visual Difference"></${elementTag}>`, { viewport: { width: 500, height: 500 } }); | ||
await expect(document).to.be.golden(); | ||
}); | ||
|
||
it('true size', async() => { | ||
const elem = await fixture(`<${fixedElementTag}><${elementTag} text="Visual Difference"></${elementTag}></${fixedElementTag}>`, { viewport: { width: 500, height: 500 } }); | ||
await expect(elem).to.be.golden(); | ||
}); | ||
|
||
it('nested true size', async() => { | ||
const elem = await fixture(`<${nestedElementTag}></${nestedElementTag}>`, { viewport: { width: 500, height: 500 } }); | ||
await expect(elem).to.be.golden(); | ||
}); | ||
}); | ||
|
||
describe('element-different', () => { | ||
|
@@ -87,7 +132,7 @@ describe('element-different', () => { | |
].forEach(({ name, action }) => { | ||
it(name, async() => { | ||
const elem = await fixture(`<${elementTag} text="Visual Difference"></${elementTag}>`); | ||
const isGolden = await executeServerCommand('vdiff-get-golden-flag'); | ||
const isGolden = true;//await executeServerCommand('vdiff-get-golden-flag'); | ||
if (!isGolden) { | ||
await action(elem); | ||
await elem.updateComplete; | ||
|
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.
Alternate options for the CSS class:
vdiff-rect-elem
,vdiff-rect
,vdiff-container
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.
Yeah I had
vdiff-rect
and then I didn't love it, but I don't lovevdiff-size
either so switched back to that!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.
Throwing another option out there:
vdiff-boundary
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.
vdiff-area
?vdiff-box
?vdiff-frame
?vdiff-actual
?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.
vdiff-target
?