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

US156331 - Add ability to indicate the actual element to use for size calculations for the screenshot #146

Merged
merged 6 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/browser/vdiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ mocha.setup({
});
/* eslint-enable */

function findTarget(elem) {
if (!elem.shadowRoot) return elem;
const nestedTarget = elem.shadowRoot.querySelector('.vdiff-target');
if (!nestedTarget) return elem;
return findTarget(nestedTarget);
}

async function ScreenshotAndCompare(opts) {

if (window.d2lTest) {
Expand All @@ -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 target = findTarget(this.elem);
rect = target.getBoundingClientRect();
}
const slowDuration = this.test.slow();
let result = await executeServerCommand('brightspace-visual-diff-compare', { name, rect, slowDuration, opts });
if (result.resizeRequired) {
Expand Down
1 change: 1 addition & 0 deletions src/server/wtr-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 --open, I only had two minutes before the whole thing force-closed. This ups that timeout to 15 minutes in open or watch mode.

config.plugins ??= [];
const currentPattern = files || config.groups.find(g => g.name === group)?.files;

Expand Down
45 changes: 45 additions & 0 deletions test/browser/element.vdiff.js
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 { unsafeHTML } from 'lit/directives/unsafe-html.js';

const elementTag = defineCE(
class extends LitElement {
Expand Down Expand Up @@ -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-target">
<slot></slot>
</div>
`;
}
}
);

const nestedElementTag = defineCE(
class extends LitElement {
render() {
return html`${unsafeHTML(`
<${fixedElementTag} class="vdiff-target"><${elementTag} text="Visual Difference"></${elementTag}></${fixedElementTag}>
`)}`;
}
}
);

describe('element-matches', () => {
[
{ name: 'default' },
Expand All @@ -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', () => {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.