@@ -5,6 +5,7 @@ import { MyApp } from '../src/my-app';
55import { createFixture } from '@aurelia/testing';
66
77describe('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