Files
framit/app/composables/useMeta.test.ts
Lucien Cartier-Tilet 70e4ce8b4b test: add comprehensive test suite for components, composables, and pages
Add 16 new test files covering:
- Composables: useBackend, useMeta, useDataJson
- Type classes: QueryResult, ResumeContent
- UI components: BadgeList, BadgeListCard
- Navbar components: LanguageSwitcher, ThemeSwitcher
- App components: AppNavbar, AppFooter
- VocalSynth components: Projects, Tools
- Pages: contact, resume, [...slug]

Tests focus on pure logic, interfaces, and component rendering where
possible, avoiding complex mocking of Nuxt auto-imported composables.

Total: 174 tests across 17 test files (including existing useApi tests).
2026-02-05 13:06:38 +01:00

102 lines
3.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, it, expect } from 'vitest';
import type { MetaImageOptions, MetaOptions } from './useMeta';
describe('useMeta', () => {
describe('MetaOptions interface', () => {
it('should accept required title and description', () => {
const options: MetaOptions = {
title: 'Test Page',
description: 'Test description',
};
expect(options.title).toBe('Test Page');
expect(options.description).toBe('Test description');
expect(options.image).toBeUndefined();
});
it('should accept optional image property', () => {
const options: MetaOptions = {
title: 'Test Page',
description: 'Test description',
image: {
url: 'https://example.com/image.jpg',
alt: 'Alt text',
},
};
expect(options.image).toBeDefined();
expect(options.image?.url).toBe('https://example.com/image.jpg');
expect(options.image?.alt).toBe('Alt text');
});
});
describe('MetaImageOptions interface', () => {
it('should require url and alt properties', () => {
const imageOptions: MetaImageOptions = {
url: 'https://example.com/image.png',
alt: 'Image description',
};
expect(imageOptions.url).toBe('https://example.com/image.png');
expect(imageOptions.alt).toBe('Image description');
});
});
describe('title suffix logic', () => {
const titleSuffix = ' Lucien Cartier-Tilet';
it('should append suffix to title', () => {
const title = 'My Page';
const fullTitle = title + titleSuffix;
expect(fullTitle).toBe('My Page Lucien Cartier-Tilet');
});
it('should handle empty title', () => {
const title = '';
const fullTitle = title + titleSuffix;
expect(fullTitle).toBe(' Lucien Cartier-Tilet');
});
});
describe('twitter card type logic', () => {
it('should use summary_large_image when image is provided', () => {
const image: MetaImageOptions = { url: 'test.jpg', alt: 'Test' };
const cardType = image ? 'summary_large_image' : 'summary';
expect(cardType).toBe('summary_large_image');
});
it('should use summary when no image is provided', () => {
const image: MetaImageOptions | undefined = undefined;
const cardType = image ? 'summary_large_image' : 'summary';
expect(cardType).toBe('summary');
});
});
describe('optional chaining for image properties', () => {
it('should return url when image is provided', () => {
const options: MetaOptions = {
title: 'Test',
description: 'Test',
image: { url: 'https://example.com/og.jpg', alt: 'OG Image' },
};
expect(options.image?.url).toBe('https://example.com/og.jpg');
expect(options.image?.alt).toBe('OG Image');
});
it('should return undefined when image is not provided', () => {
const options: MetaOptions = {
title: 'Test',
description: 'Test',
};
expect(options.image?.url).toBeUndefined();
expect(options.image?.alt).toBeUndefined();
});
});
});