|
| 1 | +import { module, test } from 'qunit'; |
| 2 | +import { setupRenderingTest } from 'ember-qunit'; |
| 3 | +import { render, settled } from '@ember/test-helpers'; |
| 4 | +import { hbs } from 'ember-cli-htmlbars'; |
| 5 | +import { YieldWrapperExample } from 'test-app/react/yield-wrapper-example'; |
| 6 | + |
| 7 | +module('Integration | Component | yield-wrapper', function (hooks) { |
| 8 | + setupRenderingTest(hooks); |
| 9 | + |
| 10 | + hooks.beforeEach(function () { |
| 11 | + this.setProperties({ |
| 12 | + YieldWrapperExample, |
| 13 | + }); |
| 14 | + }); |
| 15 | + |
| 16 | + test('it correctly handles yielded content through React bridge', async function (assert) { |
| 17 | + // Create test nodes that would be yielded from an Ember component |
| 18 | + const textNode = document.createTextNode('Hello World'); |
| 19 | + const divNode = document.createElement('div'); |
| 20 | + divNode.textContent = 'Test Div'; |
| 21 | + divNode.setAttribute('data-test-id', 'test-div'); |
| 22 | + |
| 23 | + const nodes = [textNode, divNode]; |
| 24 | + |
| 25 | + // Render using ReactBridge to simulate real usage |
| 26 | + this.set('nodes', nodes); |
| 27 | + await render(hbs` |
| 28 | + <ReactBridge |
| 29 | + @reactComponent={{this.YieldWrapperExample}} |
| 30 | + @props={{hash nodes=this.nodes}} |
| 31 | + /> |
| 32 | + `); |
| 33 | + |
| 34 | + // Initially, there should be a span element |
| 35 | + assert.dom('span').exists('Wrapper span should exist initially'); |
| 36 | + |
| 37 | + // Wait for the next tick to allow the useEffect to run |
| 38 | + await settled(); |
| 39 | + |
| 40 | + // The span should be replaced with our nodes |
| 41 | + assert.dom('span').doesNotExist('Wrapper span should be removed'); |
| 42 | + assert.dom().hasText('Hello World', 'Text node should be rendered'); |
| 43 | + assert |
| 44 | + .dom('[data-test-id="test-div"]') |
| 45 | + .hasText('Test Div', 'Div node should be rendered'); |
| 46 | + }); |
| 47 | + |
| 48 | + test('it handles empty nodes array through React bridge', async function (assert) { |
| 49 | + this.set('nodes', []); |
| 50 | + await render(hbs` |
| 51 | + <ReactBridge |
| 52 | + @reactComponent={{this.YieldWrapperExample}} |
| 53 | + @props={{hash nodes=this.nodes}} |
| 54 | + /> |
| 55 | + `); |
| 56 | + |
| 57 | + await settled(); |
| 58 | + |
| 59 | + assert.dom('span').doesNotExist('Wrapper span should be removed'); |
| 60 | + assert.dom().hasText('', 'Container should be empty'); |
| 61 | + }); |
| 62 | + |
| 63 | + test('it handles nested elements through React bridge', async function (assert) { |
| 64 | + const parentDiv = document.createElement('div'); |
| 65 | + parentDiv.setAttribute('data-test-id', 'parent'); |
| 66 | + const childSpan = document.createElement('span'); |
| 67 | + childSpan.textContent = 'Nested Content'; |
| 68 | + childSpan.setAttribute('data-test-id', 'child'); |
| 69 | + parentDiv.appendChild(childSpan); |
| 70 | + |
| 71 | + const nodes = [parentDiv]; |
| 72 | + |
| 73 | + this.set('nodes', nodes); |
| 74 | + await render(hbs` |
| 75 | + <ReactBridge |
| 76 | + @reactComponent={{this.YieldWrapperExample}} |
| 77 | + @props={{hash nodes=this.nodes}} |
| 78 | + /> |
| 79 | + `); |
| 80 | + |
| 81 | + await settled(); |
| 82 | + |
| 83 | + assert.dom('span').doesNotExist('Wrapper span should be removed'); |
| 84 | + assert |
| 85 | + .dom('[data-test-id="parent"] [data-test-id="child"]') |
| 86 | + .hasText('Nested Content', 'Nested content should be rendered'); |
| 87 | + }); |
| 88 | +}); |
0 commit comments