WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 5a530ad

Browse files
committed
test(shadow-dom): adds shadow dom tests
Adds e2e and unit tests for shadow dom components. The e2e tests check for shadow DOM rendering and shared styles. The unit tests verify shadow DOM elements and style application. Removes old shadow DOM template tests.
1 parent 02ab7a2 commit 5a530ad

File tree

4 files changed

+194
-186
lines changed

4 files changed

+194
-186
lines changed

__test__/shadow-dom.spec.js

Lines changed: 0 additions & 186 deletions
This file was deleted.

app-min/e2e__if_playwright/app.spec.ext__if_not_plugin

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,29 @@ test.beforeEach(async ({ page }) => {
77
test.describe('MyApp', () => {
88
test('shows message', async ({ page }) => {
99
await page.waitForSelector('my-app', { timeout: 10000 });
10+
11+
// @if shadow-dom
12+
// Check if shadow DOM is rendered
13+
const hasShadowRoot = await page.locator('my-app').evaluate(el => !!el.shadowRoot);
14+
await expect(hasShadowRoot).toBe(true);
15+
16+
// Use Playwright's piercing selector syntax to access shadow DOM content
17+
const shadowText = page.locator('my-app').locator(':scope .shared-shadow-text');
18+
await expect(shadowText).toBeVisible();
19+
20+
// Assert visibility of shared-style elements within shadow DOM
1021
const messageElement = page.locator('my-app').getByText('Hello World!');
1122
await expect(messageElement).toBeVisible();
23+
24+
// Optional: Take a screenshot to guard against visual regressions
25+
await page.screenshot({ path: 'shadow-dom-component.png' });
26+
// @endif
27+
28+
// @if !shadow-dom
29+
const messageElement = page.locator('my-app').getByText('Hello World!');
30+
await expect(messageElement).toBeVisible();
31+
// @endif
32+
1233
await expect(page.locator('my-app')).toContainText('Hello World!');
1334
await expect(page).toHaveTitle(/Aurelia/);
1435
});

app-min/test__if_not_no-unit-tests/my-app.spec.ext

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { MyApp } from '../src/my-app';
55
import { createFixture } from '@aurelia/testing';
66

77
describe('my-app', () => {
8+
// @if !shadow-dom
89
it('should render message', async () => {
910
const { assertText } = await createFixture(
1011
'<my-app></my-app>',
@@ -32,4 +33,72 @@ describe('my-app', () => {
3233
assertText('Hello World!', { compact: true });
3334
// @endif
3435
});
36+
// @endif
37+
38+
// @if shadow-dom
39+
it('should render with Shadow DOM and shared styles', async () => {
40+
const { element } = await createFixture(
41+
'<my-app></my-app>',
42+
{},
43+
[MyApp],
44+
).started;
45+
46+
// Assert that the host element has a shadow root
47+
const shadowRoot = element.shadowRoot;
48+
if (shadowRoot === null) {
49+
throw new Error('Expected shadowRoot to be present, but it was null');
50+
}
51+
52+
// Query inside the shadow root to verify the message text
53+
const messageElement = shadowRoot.querySelector('.message') ||
54+
shadowRoot.querySelector('[class*="text-"]'); // Handle TailwindCSS classes
55+
if (messageElement === null) {
56+
throw new Error('Expected to find message element in shadow root');
57+
}
58+
59+
// Verify the message contains 'Hello World!'
60+
const messageText = messageElement.textContent || '';
61+
if (!messageText.includes('Hello World!')) {
62+
throw new Error(`Expected message to contain 'Hello World!' but got: ${messageText}`);
63+
}
64+
65+
// Verify presence of shared shadow DOM style elements
66+
const sharedStyleElement = shadowRoot.querySelector('.shared-shadow-style');
67+
if (sharedStyleElement === null) {
68+
throw new Error('Expected to find .shared-shadow-style element in shadow root');
69+
}
70+
71+
const sharedTextElement = shadowRoot.querySelector('.shared-shadow-text');
72+
if (sharedTextElement === null) {
73+
throw new Error('Expected to find .shared-shadow-text element in shadow root');
74+
}
75+
76+
// Verify the shared text content
77+
const sharedTextContent = sharedTextElement.textContent || '';
78+
if (!sharedTextContent.includes('This content uses shared Shadow DOM styles!')) {
79+
throw new Error(`Expected shared text content but got: ${sharedTextContent}`);
80+
}
81+
82+
// Verify computed styles are applied (proving sharedStyles were injected)
83+
const computedStyles = window.getComputedStyle(sharedStyleElement);
84+
85+
// Check for background gradient (linear-gradient)
86+
const backgroundImage = computedStyles.backgroundImage;
87+
if (!backgroundImage.includes('linear-gradient')) {
88+
throw new Error(`Expected background gradient to be applied, but got: ${backgroundImage}`);
89+
}
90+
91+
// Check for box-shadow
92+
const boxShadow = computedStyles.boxShadow;
93+
if (boxShadow === 'none' || boxShadow === '') {
94+
throw new Error(`Expected box-shadow to be applied, but got: ${boxShadow}`);
95+
}
96+
97+
// Check for border-radius
98+
const borderRadius = computedStyles.borderRadius;
99+
if (borderRadius === '0px' || borderRadius === '') {
100+
throw new Error(`Expected border-radius to be applied, but got: ${borderRadius}`);
101+
}
102+
});
103+
// @endif
35104
});

0 commit comments

Comments
 (0)