Skip to content

Commit

Permalink
Resolved some all comments and reduced the teardownTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
luukbrauckmann committed Sep 23, 2024
1 parent 5eb0f17 commit 8b3d04e
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 67 deletions.
5 changes: 2 additions & 3 deletions src/blocks/ImageBlock/ImageBlock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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 () => {
Expand Down
3 changes: 3 additions & 0 deletions src/blocks/PagePartialBlock/PagePartialBlock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
52 changes: 16 additions & 36 deletions src/blocks/TableBlock/TableBlock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Props>(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
}
Expand All @@ -33,15 +37,7 @@ describe('TableBlock', () => {
const fragment = await renderToFragment<Props>(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
}
Expand All @@ -59,15 +55,7 @@ describe('TableBlock', () => {
const fragment = await renderToFragment<Props>(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
}
Expand All @@ -85,15 +73,7 @@ describe('TableBlock', () => {
const fragment = await renderToFragment<Props>(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
}
Expand Down
56 changes: 50 additions & 6 deletions src/blocks/TextBlock/TextBlock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Props>(TextBlock, {
props: {
block: {
Expand All @@ -22,7 +22,7 @@ describe('TextBlock', () => {
children: [
{
type: 'span',
value: 'This is a test'
value: 'This is a test heading'
}
]
},
Expand All @@ -31,7 +31,7 @@ describe('TextBlock', () => {
children: [
{
type: 'span',
value: 'This is a test'
value: 'This is a test paragraph'
},
]
}
Expand All @@ -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<Props>(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');
});
});
4 changes: 2 additions & 2 deletions src/components/Breadcrumbs/Breadcrumbs.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 0 additions & 20 deletions src/components/Breadcrumbs/Breadcrumbs.test.ts

This file was deleted.

1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
}
});
Expand Down

0 comments on commit 8b3d04e

Please sign in to comment.