|
| 1 | +import { browser, expect } from '@wdio/globals'; |
| 2 | +import { setupIFrameTest } from '../../util.js'; |
| 3 | + |
| 4 | +/** |
| 5 | + * Tests for mixin slot detection. Verifies that Stencil properly walks into |
| 6 | + * mixin factory functions to detect slot elements for build conditionals. |
| 7 | + * |
| 8 | + * When the fix is working correctly, the slotted content should appear |
| 9 | + * inside the mixin-wrapper (between mixin-header and mixin-footer). |
| 10 | + * |
| 11 | + * When the fix is NOT working, the slotted content would be dumped outside |
| 12 | + * the component structure because Stencil wouldn't know there's a slot. |
| 13 | + */ |
| 14 | +describe('Mixin slot detection', () => { |
| 15 | + describe('es2022 dist output', () => { |
| 16 | + let frameContent: HTMLElement; |
| 17 | + |
| 18 | + beforeEach(async () => { |
| 19 | + frameContent = await setupIFrameTest('/extends-mixin-slot/es2022.dist.html', 'es2022-dist'); |
| 20 | + const frameEle = await browser.$('#es2022-dist'); |
| 21 | + frameEle.waitUntil(async () => !!frameContent.querySelector('.component-root'), { timeout: 5000 }); |
| 22 | + }); |
| 23 | + |
| 24 | + it('renders slotted content inside the mixin wrapper', async () => { |
| 25 | + const cmp = frameContent.querySelector('extends-mixin-slot-cmp'); |
| 26 | + expect(cmp).toBeDefined(); |
| 27 | + |
| 28 | + // The slotted content should be within the component |
| 29 | + const slottedContent = cmp!.querySelector('.slotted-content'); |
| 30 | + expect(slottedContent).toBeDefined(); |
| 31 | + expect(slottedContent!.textContent).toBe('I am slotted content'); |
| 32 | + |
| 33 | + // Verify the mixin structure is present |
| 34 | + const mixinWrapper = cmp!.querySelector('.mixin-wrapper'); |
| 35 | + expect(mixinWrapper).toBeDefined(); |
| 36 | + |
| 37 | + const header = cmp!.querySelector('.mixin-header'); |
| 38 | + expect(header).toBeDefined(); |
| 39 | + expect(header!.textContent).toBe('Mixin Content Header'); |
| 40 | + |
| 41 | + const footer = cmp!.querySelector('.mixin-footer'); |
| 42 | + expect(footer).toBeDefined(); |
| 43 | + expect(footer!.textContent).toBe('Mixin Content Footer'); |
| 44 | + }); |
| 45 | + |
| 46 | + it('slotted content should not be outside the component', async () => { |
| 47 | + // If slot detection failed, the slotted content would be dumped at body level |
| 48 | + const bodySlottedContent = frameContent.querySelector(':scope > .slotted-content'); |
| 49 | + expect(bodySlottedContent).toBeNull(); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + describe('es2022 dist-custom-elements output', () => { |
| 54 | + let frameContent: HTMLElement; |
| 55 | + |
| 56 | + beforeEach(async () => { |
| 57 | + await browser.switchToParentFrame(); |
| 58 | + frameContent = await setupIFrameTest('/extends-mixin-slot/es2022.custom-element.html', 'es2022-custom-elements'); |
| 59 | + const frameEle = await browser.$('iframe#es2022-custom-elements'); |
| 60 | + frameEle.waitUntil(async () => !!frameContent.querySelector('.component-root'), { timeout: 5000 }); |
| 61 | + }); |
| 62 | + |
| 63 | + it('renders slotted content inside the mixin wrapper', async () => { |
| 64 | + const cmp = frameContent.querySelector('extends-mixin-slot-cmp'); |
| 65 | + expect(cmp).toBeDefined(); |
| 66 | + |
| 67 | + // The slotted content should be within the component |
| 68 | + const slottedContent = cmp!.querySelector('.slotted-content'); |
| 69 | + expect(slottedContent).toBeDefined(); |
| 70 | + expect(slottedContent!.textContent).toBe('I am slotted content'); |
| 71 | + |
| 72 | + // Verify the mixin structure is present |
| 73 | + const mixinWrapper = cmp!.querySelector('.mixin-wrapper'); |
| 74 | + expect(mixinWrapper).toBeDefined(); |
| 75 | + |
| 76 | + const header = cmp!.querySelector('.mixin-header'); |
| 77 | + expect(header).toBeDefined(); |
| 78 | + expect(header!.textContent).toBe('Mixin Content Header'); |
| 79 | + |
| 80 | + const footer = cmp!.querySelector('.mixin-footer'); |
| 81 | + expect(footer).toBeDefined(); |
| 82 | + expect(footer!.textContent).toBe('Mixin Content Footer'); |
| 83 | + }); |
| 84 | + |
| 85 | + it('slotted content should not be outside the component', async () => { |
| 86 | + // If slot detection failed, the slotted content would be dumped at body level |
| 87 | + const bodySlottedContent = frameContent.querySelector(':scope > .slotted-content'); |
| 88 | + expect(bodySlottedContent).toBeNull(); |
| 89 | + }); |
| 90 | + }); |
| 91 | +}); |
0 commit comments