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).
This commit is contained in:
2026-02-04 20:14:57 +01:00
parent e6a268bafd
commit 70e4ce8b4b
16 changed files with 2045 additions and 0 deletions

View File

@@ -0,0 +1,98 @@
import { describe, it, expect } from 'vitest';
import { QueryResult } from './query-result';
import type { ApiError } from './api/error';
describe('QueryResult', () => {
describe('initialization', () => {
it('should initialize with null data', () => {
const result = new QueryResult<string, void>();
expect(result.data.value).toBeNull();
});
it('should initialize with null error', () => {
const result = new QueryResult<string, void>();
expect(result.error.value).toBeNull();
});
it('should initialize with loading as false', () => {
const result = new QueryResult<string, void>();
expect(result.loading.value).toBe(false);
});
it('should have run property (initially undefined)', () => {
const result = new QueryResult<string, void>();
expect(result).toHaveProperty('run');
});
});
describe('reactive properties', () => {
it('should have reactive data ref', () => {
const result = new QueryResult<{ id: number }, void>();
result.data.value = { id: 1 };
expect(result.data.value).toEqual({ id: 1 });
});
it('should have reactive error ref', () => {
const result = new QueryResult<string, void>();
const error: ApiError = { message: 'Test error', success: false };
result.error.value = error;
expect(result.error.value).toEqual(error);
});
it('should have reactive loading ref', () => {
const result = new QueryResult<string, void>();
result.loading.value = true;
expect(result.loading.value).toBe(true);
});
});
describe('type safety', () => {
it('should accept generic type for data', () => {
interface TestData {
name: string;
count: number;
}
const result = new QueryResult<TestData, void>();
result.data.value = { name: 'test', count: 42 };
expect(result.data.value.name).toBe('test');
expect(result.data.value.count).toBe(42);
});
it('should accept generic type for payload', () => {
interface ResponseData {
success: boolean;
}
interface PayloadData {
input: string;
}
const result = new QueryResult<ResponseData, PayloadData>();
// PayloadT is used by the run function signature
expect(result).toHaveProperty('run');
});
});
describe('run method assignment', () => {
it('should allow run method to be assigned', async () => {
const result = new QueryResult<string, void>();
let called = false;
result.run = async () => {
called = true;
};
await result.run();
expect(called).toBe(true);
});
it('should allow run method to accept payload parameter', async () => {
const result = new QueryResult<string, { data: string }>();
let receivedPayload: { data: string } | undefined;
result.run = async (payload) => {
receivedPayload = payload;
};
await result.run({ data: 'test' });
expect(receivedPayload).toEqual({ data: 'test' });
});
});
});

129
app/types/resume.test.ts Normal file
View File

@@ -0,0 +1,129 @@
import { describe, it, expect } from 'vitest';
import { ResumeExperience, ResumeContent } from './resume';
import type { Tool } from './tool';
describe('ResumeExperience', () => {
describe('initialization', () => {
it('should initialize with empty tools array', () => {
const experience = new ResumeExperience();
expect(experience.tools).toEqual([]);
});
it('should initialize with undefined description', () => {
const experience = new ResumeExperience();
expect(experience.description).toBeUndefined();
});
});
describe('property assignment', () => {
it('should allow tools to be assigned', () => {
const experience = new ResumeExperience();
const tools: Tool[] = [{ name: 'TypeScript', link: 'https://typescriptlang.org' }, { name: 'Vue.js' }];
experience.tools = tools;
expect(experience.tools).toEqual(tools);
});
it('should allow description to be assigned', () => {
const experience = new ResumeExperience();
experience.description = 'Software developer working on web applications';
expect(experience.description).toBe('Software developer working on web applications');
});
});
describe('TimelineItem interface implementation', () => {
it('should be usable as TimelineItem', () => {
const experience = new ResumeExperience();
// TimelineItem interface from @nuxt/ui - ResumeExperience implements it
expect(experience).toHaveProperty('tools');
expect(experience).toHaveProperty('description');
});
});
});
describe('ResumeContent', () => {
describe('initialization', () => {
it('should initialize with empty experience array', () => {
const content = new ResumeContent();
expect(content.experience).toEqual([]);
});
it('should initialize with empty education array', () => {
const content = new ResumeContent();
expect(content.education).toEqual([]);
});
it('should initialize with empty otherTools array', () => {
const content = new ResumeContent();
expect(content.otherTools).toEqual([]);
});
it('should initialize with empty devops array', () => {
const content = new ResumeContent();
expect(content.devops).toEqual([]);
});
it('should initialize with empty os array', () => {
const content = new ResumeContent();
expect(content.os).toEqual([]);
});
it('should initialize with empty programmingLanguages array', () => {
const content = new ResumeContent();
expect(content.programmingLanguages).toEqual([]);
});
it('should initialize with empty frameworks array', () => {
const content = new ResumeContent();
expect(content.frameworks).toEqual([]);
});
});
describe('property assignment', () => {
it('should allow experience to be assigned', () => {
const content = new ResumeContent();
const exp = new ResumeExperience();
exp.description = 'Test job';
content.experience = [exp];
expect(content.experience.length).toBe(1);
expect(content.experience[0].description).toBe('Test job');
});
it('should allow tools arrays to be assigned', () => {
const content = new ResumeContent();
const tools: Tool[] = [{ name: 'Git', link: 'https://git-scm.com' }];
content.devops = tools;
content.os = [{ name: 'Linux' }];
content.programmingLanguages = [{ name: 'Rust', link: 'https://rust-lang.org' }];
content.frameworks = [{ name: 'Nuxt', link: 'https://nuxt.com' }];
content.otherTools = [{ name: 'Vim' }];
expect(content.devops).toEqual(tools);
expect(content.os).toEqual([{ name: 'Linux' }]);
expect(content.programmingLanguages).toEqual([{ name: 'Rust', link: 'https://rust-lang.org' }]);
expect(content.frameworks).toEqual([{ name: 'Nuxt', link: 'https://nuxt.com' }]);
expect(content.otherTools).toEqual([{ name: 'Vim' }]);
});
it('should allow education to be assigned', () => {
const content = new ResumeContent();
content.education = [{ title: 'Computer Science', description: 'Master degree' }];
expect(content.education.length).toBe(1);
});
});
describe('default values', () => {
it('should provide safe defaults when used without data', () => {
const content = new ResumeContent();
// All arrays should be empty but defined
expect(Array.isArray(content.experience)).toBe(true);
expect(Array.isArray(content.education)).toBe(true);
expect(Array.isArray(content.otherTools)).toBe(true);
expect(Array.isArray(content.devops)).toBe(true);
expect(Array.isArray(content.os)).toBe(true);
expect(Array.isArray(content.programmingLanguages)).toBe(true);
expect(Array.isArray(content.frameworks)).toBe(true);
});
});
});