|
| 1 | +import { render } from '@testing-library/react'; |
| 2 | +import { Island } from './Island'; |
| 3 | + |
| 4 | +describe('IslandContext tracks nesting of islands', () => { |
| 5 | + test('Single island', () => { |
| 6 | + const { container } = render( |
| 7 | + <Island priority="feature" defer={{ until: 'visible' }}> |
| 8 | + <span>🏝️</span> |
| 9 | + </Island>, |
| 10 | + ); |
| 11 | + const islands = container.querySelectorAll('gu-island'); |
| 12 | + expect(islands.length).toBe(1); |
| 13 | + }); |
| 14 | + |
| 15 | + test('Nested island', () => { |
| 16 | + const { container } = render( |
| 17 | + <Island priority="feature" defer={{ until: 'visible' }}> |
| 18 | + <div> |
| 19 | + <Island priority="feature" defer={{ until: 'visible' }}> |
| 20 | + <span>🏝️</span> |
| 21 | + </Island> |
| 22 | + </div> |
| 23 | + </Island>, |
| 24 | + ); |
| 25 | + const islands = container.querySelectorAll('gu-island'); |
| 26 | + expect(islands.length).toBe(1); |
| 27 | + }); |
| 28 | + |
| 29 | + test('Multiple nested islands', () => { |
| 30 | + const { container } = render( |
| 31 | + <Island priority="critical"> |
| 32 | + <div> |
| 33 | + <Island priority="critical"> |
| 34 | + <div> |
| 35 | + <Island priority="critical"> |
| 36 | + <span>🏝️</span> |
| 37 | + </Island> |
| 38 | + <Island priority="critical"> |
| 39 | + <span>🏝️</span> |
| 40 | + </Island> |
| 41 | + </div> |
| 42 | + </Island> |
| 43 | + </div> |
| 44 | + </Island>, |
| 45 | + ); |
| 46 | + const islands = container.querySelectorAll('gu-island'); |
| 47 | + expect(islands.length).toBe(1); |
| 48 | + }); |
| 49 | + |
| 50 | + test('Child island props are included in parent island props', () => { |
| 51 | + const { container } = render( |
| 52 | + <Island priority="feature" defer={{ until: 'visible' }}> |
| 53 | + <div> |
| 54 | + <Island priority="feature" defer={{ until: 'visible' }}> |
| 55 | + <span className="archipelago">🏝️</span> |
| 56 | + </Island> |
| 57 | + </div> |
| 58 | + </Island>, |
| 59 | + ); |
| 60 | + const island = container.querySelector('gu-island'); |
| 61 | + expect(island).toHaveAttribute( |
| 62 | + 'props', |
| 63 | + expect.stringContaining( |
| 64 | + '"props":{"className":"archipelago","children":"🏝️"}', |
| 65 | + ), |
| 66 | + ); |
| 67 | + }); |
| 68 | +}); |
0 commit comments