|
1 | 1 | import AnchorFm from '$lib/components/anchor-fm.svelte' |
2 | 2 | import { cleanup, render } from '@testing-library/svelte' |
3 | | -import { afterEach, describe, expect, it, vi } from 'vitest' |
| 3 | +import { afterEach, describe, expect, it } from 'vitest' |
4 | 4 |
|
5 | | -globalThis.IntersectionObserver = vi.fn(() => ({ |
6 | | - observe: () => null, |
7 | | - unobserve: () => null, |
8 | | - disconnect: () => null, |
9 | | -})) as unknown as typeof globalThis.IntersectionObserver |
| 5 | +let episodeUrl = |
| 6 | + 'purrfect-dev/embed/episodes/1-31---Delivering-Digital-Content-with-GraphCMS-e14g55c/a-a650v9a' |
10 | 7 |
|
11 | 8 | describe('AnchorFm', () => { |
12 | | - afterEach(() => cleanup()) |
| 9 | + afterEach(() => cleanup()) |
13 | 10 |
|
14 | | - it('mounts', async () => { |
15 | | - const { container } = render(AnchorFm) |
16 | | - expect(container).toBeTruthy() |
17 | | - }) |
| 11 | + it('mounts with episode url', async () => { |
| 12 | + const { container } = render(AnchorFm, { |
| 13 | + episodeUrl, |
| 14 | + disable_observer: true, |
| 15 | + }) |
| 16 | + expect(container).toBeTruthy() |
| 17 | + }) |
18 | 18 |
|
19 | | - it.skip('has episode url', async () => { |
20 | | - const { container } = render(AnchorFm, { |
21 | | - episodeUrl: |
22 | | - 'purrfect-dev/embed/episodes/1-31---Delivering-Digital-Content-with-GraphCMS-e14g55c/a-a650v9a', |
23 | | - }) |
| 19 | + it('renders iframe with episode url', async () => { |
| 20 | + const { getByTestId } = render(AnchorFm, { |
| 21 | + episodeUrl, |
| 22 | + disable_observer: true, |
| 23 | + }) |
| 24 | + const iframe = getByTestId('anchor-fm-episode') |
| 25 | + const expectedSrc = `https://anchor.fm/${episodeUrl}` |
| 26 | + expect(iframe.getAttribute('src')).toBe(expectedSrc) |
| 27 | + }) |
24 | 28 |
|
25 | | - expect(container.querySelectorAll('h2')).toBe( |
26 | | - '1.31 - Delivering Digital Content with GraphCMS' |
27 | | - ) |
28 | | - }) |
| 29 | + it('sets iframe dimensions based on props', async () => { |
| 30 | + const height = '200' |
| 31 | + const width = '75' |
| 32 | + const { getByTestId } = render(AnchorFm, { |
| 33 | + episodeUrl, |
| 34 | + height, |
| 35 | + width, |
| 36 | + disable_observer: true, |
| 37 | + }) |
| 38 | + const iframe = getByTestId('anchor-fm-episode') |
| 39 | + expect(iframe.getAttribute('height')).toBe(height) |
| 40 | + expect(iframe.getAttribute('width')).toBe(`${width}`) |
| 41 | + }) |
29 | 42 | }) |
0 commit comments