diff --git a/src/blocks/ImageBlock/ImageBlock.test.ts b/src/blocks/ImageBlock/ImageBlock.test.ts index 1f128c98..6d9031b5 100644 --- a/src/blocks/ImageBlock/ImageBlock.test.ts +++ b/src/blocks/ImageBlock/ImageBlock.test.ts @@ -11,7 +11,6 @@ describe('ImageBlock', () => { image: { url: 'https://example.com/test.jpg', alt: 'A test image', - title: 'A test image', height: 150, width: 150 } @@ -53,7 +52,7 @@ describe('ImageBlock', () => { image: { url: 'https://example.com/test.jpg', alt: 'A test image', - title: 'A test image', + title: 'See the test image', height: 150, width: 150 } @@ -62,7 +61,7 @@ describe('ImageBlock', () => { }); expect(fragment.querySelector('figcaption')).toBeTruthy(); - expect(fragment.querySelector('figcaption')?.textContent).toBe('A test image'); + expect(fragment.querySelector('figcaption')?.textContent).toBe('See the test image'); }); test('does not render figcaption when no title is provided', async () => { diff --git a/src/blocks/PagePartialBlock/PagePartialBlock.test.ts b/src/blocks/PagePartialBlock/PagePartialBlock.test.ts index f4e681cd..21f73d6f 100644 --- a/src/blocks/PagePartialBlock/PagePartialBlock.test.ts +++ b/src/blocks/PagePartialBlock/PagePartialBlock.test.ts @@ -47,6 +47,7 @@ describe('PagePartialBlock', () => { expect(fragment.querySelector('h2')).toBeFalsy(); expect(fragment.querySelector('p')).toBeTruthy(); + expect(fragment.querySelector('p')?.textContent).toBe('This is a test'); }); test('renders a stack layout with a title when layout is "stack-titled"', async () => { @@ -92,7 +93,9 @@ describe('PagePartialBlock', () => { }); expect(fragment.querySelector('h2')).toBeTruthy(); + expect(fragment.querySelector('h2')?.textContent).toBe('Partial A'); expect(fragment.querySelector('p')).toBeTruthy(); + expect(fragment.querySelector('p')?.textContent).toBe('This is a test'); }); test('renders a closed accordion layout when layout is "accordion-closed"', async () => { diff --git a/src/blocks/TableBlock/TableBlock.test.ts b/src/blocks/TableBlock/TableBlock.test.ts index f5a8fc89..af876ab8 100644 --- a/src/blocks/TableBlock/TableBlock.test.ts +++ b/src/blocks/TableBlock/TableBlock.test.ts @@ -2,20 +2,24 @@ import { renderToFragment } from '@lib/renderer'; import { describe, expect, test } from 'vitest'; import TableBlock, { type Props } from './TableBlock.astro'; +const block = { + _modelApiKey: 'table_block', + id: '123', + title: 'Table Block', + table: { + columns: ['test_1', 'test_2'], + data: [ + { test_1: 'Test 1', test_2: 'Test 2' } + ] + }, +}; + describe('TableBlock', () => { test('renders a table with both header row and header column', async () => { const fragment = await renderToFragment(TableBlock, { props: { block: { - _modelApiKey: 'table_block', - id: '123', - title: 'Table Block', - table: { - columns: ['test_1', 'test_2'], - data: [ - { test_1: 'Test 1', test_2: 'Test 2' } - ] - }, + ...block, hasHeaderRow: true, hasHeaderColumn: true } @@ -33,15 +37,7 @@ describe('TableBlock', () => { const fragment = await renderToFragment(TableBlock, { props: { block: { - _modelApiKey: 'table_block', - id: '123', - title: 'Table Block', - table: { - columns: ['test_1', 'test_2'], - data: [ - { test_1: 'Test 1', test_2: 'Test 2' } - ] - }, + ...block, hasHeaderRow: true, hasHeaderColumn: false } @@ -59,15 +55,7 @@ describe('TableBlock', () => { const fragment = await renderToFragment(TableBlock, { props: { block: { - _modelApiKey: 'table_block', - id: '123', - title: 'Table Block', - table: { - columns: ['test_1', 'test_2'], - data: [ - { test_1: 'Test 1', test_2: 'Test 2' } - ] - }, + ...block, hasHeaderRow: false, hasHeaderColumn: true } @@ -85,15 +73,7 @@ describe('TableBlock', () => { const fragment = await renderToFragment(TableBlock, { props: { block: { - _modelApiKey: 'table_block', - id: '123', - title: 'Table Block', - table: { - columns: ['test_1', 'test_2'], - data: [ - { test_1: 'Test 1', test_2: 'Test 2' } - ] - }, + ...block, hasHeaderRow: false, hasHeaderColumn: false } diff --git a/src/blocks/TextBlock/TextBlock.test.ts b/src/blocks/TextBlock/TextBlock.test.ts index 688ad062..2fcf05b5 100644 --- a/src/blocks/TextBlock/TextBlock.test.ts +++ b/src/blocks/TextBlock/TextBlock.test.ts @@ -2,8 +2,8 @@ import { renderToFragment } from '@lib/renderer'; import { describe, expect, test } from 'vitest'; import TextBlock, { type Props } from './TextBlock.astro'; -describe('TextBlock', () => { - test('renders a heading and paragraph with the correct text content', async () => { +describe('TextBlock Component', () => { + test('transforms a heading level 1 into heading level 2', async () => { const fragment = await renderToFragment(TextBlock, { props: { block: { @@ -22,7 +22,7 @@ describe('TextBlock', () => { children: [ { type: 'span', - value: 'This is a test' + value: 'This is a test heading' } ] }, @@ -31,7 +31,7 @@ describe('TextBlock', () => { children: [ { type: 'span', - value: 'This is a test' + value: 'This is a test paragraph' }, ] } @@ -43,7 +43,51 @@ describe('TextBlock', () => { } }); - expect(fragment.querySelector('h2')?.textContent).toBe('This is a test'); - expect(fragment.querySelector('p')?.textContent).toBe('This is a test'); + expect(fragment.querySelector('h2')?.textContent).toBe('This is a test heading'); + expect(fragment.querySelector('p')?.textContent).toBe('This is a test paragraph'); + }); + + test('renders a heading level 3 and a paragraph with the correct text content', async () => { + const fragment = await renderToFragment(TextBlock, { + props: { + block: { + __typename: 'TextBlockRecord', + text: { + blocks: [], + links: [], + value: { + schema: 'dast', + document: { + type: 'root', + children: [ + { + type: 'heading', + level: 3, + children: [ + { + type: 'span', + value: 'This is a test heading' + } + ] + }, + { + type: 'paragraph', + children: [ + { + type: 'span', + value: 'This is a test paragraph' + }, + ] + } + ] + } + } + } + } + } + }); + + expect(fragment.querySelector('h3')?.textContent).toBe('This is a test heading'); + expect(fragment.querySelector('p')?.textContent).toBe('This is a test paragraph'); }); }); diff --git a/src/components/Breadcrumbs/Breadcrumbs.astro b/src/components/Breadcrumbs/Breadcrumbs.astro index 895c8079..9ac1e283 100644 --- a/src/components/Breadcrumbs/Breadcrumbs.astro +++ b/src/components/Breadcrumbs/Breadcrumbs.astro @@ -18,12 +18,12 @@ const schema = { { '@type': 'ListItem', name: t('breadcrumbs_home'), - item: new URL(`/${ locale }/`, Astro.site || 'http://localhost:5173/'), + item: new URL(`/${ locale }/`, Astro.site), }, ... items.map(item => ({ '@type': 'ListItem', name: item.text, - item: new URL(item.href || '', Astro.site || 'http://localhost:5173/'), + item: new URL(item.href || '', Astro.site), })) ].map((item, index) => ({ ...item, diff --git a/src/components/Breadcrumbs/Breadcrumbs.test.ts b/src/components/Breadcrumbs/Breadcrumbs.test.ts deleted file mode 100644 index 78595022..00000000 --- a/src/components/Breadcrumbs/Breadcrumbs.test.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { renderToFragment } from '@lib/renderer'; -import { describe, expect, test } from 'vitest'; -import type { Breadcrumb } from './index'; -import Breadcrumbs from './Breadcrumbs.astro'; - -const fragment = await renderToFragment<{ items: Breadcrumb[] }>(Breadcrumbs, { - props: { - items: [ - { text: 'Home' } - ] - } -}); - -describe('Breadcrumbs', () => { - test('Component is rendered', () => { - expect(fragment).toBeTruthy(); - }); - - // Add more tests here -}); diff --git a/vitest.config.ts b/vitest.config.ts index 35097c07..ae8731e2 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -4,6 +4,7 @@ import { getViteConfig } from 'astro/config'; export default getViteConfig({ test: { // Vitest configuration options + teardownTimeout: 1000, reporters: process.env.GITHUB_ACTIONS ? ['dot', 'github-actions'] : ['dot'], } });