|
| 1 | +import { h } from '@stencil/core'; |
| 2 | +import { render } from '@wdio/browser-runner/stencil'; |
| 3 | +import { $, browser, expect } from '@wdio/globals'; |
| 4 | + |
| 5 | +import { setupIFrameTest } from '../util.js'; |
| 6 | + |
| 7 | +describe('scoped-slot-connectedcallback', function () { |
| 8 | + describe('lazy load (dist output)', () => { |
| 9 | + beforeEach(() => { |
| 10 | + render({ |
| 11 | + components: [], |
| 12 | + template: () => <scoped-slot-connectedcallback-parent />, |
| 13 | + }); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should have slotted content available in connectedCallback', async () => { |
| 17 | + await $('scoped-slot-connectedcallback-child').waitForExist(); |
| 18 | + |
| 19 | + const child = await $('scoped-slot-connectedcallback-child'); |
| 20 | + const connectedAttr = await child.getAttribute('data-connected-slot-available'); |
| 21 | + const willLoadAttr = await child.getAttribute('data-willload-slot-available'); |
| 22 | + |
| 23 | + // Both connectedCallback and componentWillLoad should have access to slotted content |
| 24 | + expect(connectedAttr).toBe('true'); |
| 25 | + expect(willLoadAttr).toBe('true'); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should render slotted content correctly', async () => { |
| 29 | + await $('scoped-slot-connectedcallback-child').waitForExist(); |
| 30 | + |
| 31 | + const slottedContent = await $('#slotted-content'); |
| 32 | + await expect(slottedContent).toBeExisting(); |
| 33 | + await expect(slottedContent).toHaveText('Slotted Content'); |
| 34 | + |
| 35 | + const wrapper = await $('.wrapper'); |
| 36 | + const text = await wrapper.getText(); |
| 37 | + expect(text).toContain('Before slot'); |
| 38 | + expect(text).toContain('Slotted Content'); |
| 39 | + expect(text).toContain('After slot'); |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + describe('dist-custom-elements output', () => { |
| 44 | + let doc: Document; |
| 45 | + |
| 46 | + beforeEach(async () => { |
| 47 | + await setupIFrameTest('/scoped-slot-connectedcallback/custom-element.html', 'custom-elements-iframe'); |
| 48 | + const frameEle: HTMLIFrameElement = document.querySelector('iframe#custom-elements-iframe'); |
| 49 | + doc = frameEle.contentDocument; |
| 50 | + |
| 51 | + // Render the component inside the iframe |
| 52 | + const parent = doc.createElement('scoped-slot-connectedcallback-parent'); |
| 53 | + doc.body.appendChild(parent); |
| 54 | + |
| 55 | + // Wait for component to be ready |
| 56 | + await browser.waitUntil(() => Boolean(doc.querySelector('scoped-slot-connectedcallback-child'))); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should have slotted content available in connectedCallback', async () => { |
| 60 | + const child = doc.querySelector('scoped-slot-connectedcallback-child'); |
| 61 | + const connectedAttr = child.getAttribute('data-connected-slot-available'); |
| 62 | + const willLoadAttr = child.getAttribute('data-willload-slot-available'); |
| 63 | + |
| 64 | + // Both connectedCallback and componentWillLoad should have access to slotted content |
| 65 | + expect(connectedAttr).toBe('true'); |
| 66 | + expect(willLoadAttr).toBe('true'); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should render slotted content correctly', async () => { |
| 70 | + const slottedContent = doc.querySelector('#slotted-content'); |
| 71 | + expect(slottedContent).toBeTruthy(); |
| 72 | + expect(slottedContent.textContent).toBe('Slotted Content'); |
| 73 | + |
| 74 | + const wrapper = doc.querySelector('.wrapper'); |
| 75 | + const text = wrapper.textContent; |
| 76 | + expect(text).toContain('Before slot'); |
| 77 | + expect(text).toContain('Slotted Content'); |
| 78 | + expect(text).toContain('After slot'); |
| 79 | + }); |
| 80 | + }); |
| 81 | +}); |
0 commit comments