feat: added field "title" and switched to it to free up caption for its normal use

This commit is contained in:
2026-02-15 09:09:48 +01:00
parent 4f71ac25bc
commit b5795867a8
20 changed files with 886 additions and 42 deletions

View File

@@ -52,7 +52,7 @@ const insertedPosts: Array<{
const insertedMedia: Array<{
id: string;
linkedPostIds: string[];
caption?: string;
title?: string;
}> = [];
const createdTags: string[] = [];
@@ -167,7 +167,7 @@ const mockMediaEngine = {
id: `media-${Math.random().toString(36).substr(2, 9)}`,
filename: path.basename(sourcePath),
originalName: metadata?.originalName || path.basename(sourcePath),
caption: metadata?.caption,
title: metadata?.title,
linkedPostIds: metadata?.linkedPostIds || [],
};
insertedMedia.push(result);
@@ -1044,9 +1044,9 @@ describe('ImportExecutionEngine E2E Tests', () => {
expect(result.media.imported).toBe(1);
// Should be imported with caption from WXR title
// Should be imported with title from WXR title
expect(insertedMedia.length).toBe(1);
expect(insertedMedia[0].caption).toBe('standalone-logo');
expect(insertedMedia[0].title).toBe('standalone-logo');
// No linked posts (standalone)
expect(insertedMedia[0].linkedPostIds.length).toBe(0);

View File

@@ -1016,7 +1016,7 @@ describe('ImportExecutionEngine', () => {
);
});
it('should set caption from WXR title', async () => {
it('should set title from WXR title', async () => {
const wxrMedia = createMockWxrMedia({ title: 'Beautiful Sunset' });
const report = createMockAnalysisReport({
media: {
@@ -1035,7 +1035,7 @@ describe('ImportExecutionEngine', () => {
expect(mockMediaEngine.importMedia).toHaveBeenCalledWith(
expect.any(String),
expect.objectContaining({
caption: 'Beautiful Sunset',
title: 'Beautiful Sunset',
})
);
});

View File

@@ -535,11 +535,19 @@ describe('MediaEngine', () => {
});
});
describe('Alt Text and Caption', () => {
describe('Title, Alt Text and Caption', () => {
beforeEach(() => {
mockFiles.set('/source/image.jpg', Buffer.from('image-data'));
});
it('should store title for display in lists and search', async () => {
const media = await mediaEngine.importMedia('/source/image.jpg', {
title: 'Mountain Sunrise Photo',
});
expect(media.title).toBe('Mountain Sunrise Photo');
});
it('should store alt text for accessibility', async () => {
const media = await mediaEngine.importMedia('/source/image.jpg', {
alt: 'A scenic mountain view',
@@ -556,9 +564,10 @@ describe('MediaEngine', () => {
expect(media.caption).toBe('Photo taken at Mt. Rainier, 2024');
});
it('should handle media without alt or caption', async () => {
it('should handle media without title, alt or caption', async () => {
const media = await mediaEngine.importMedia('/source/image.jpg');
expect(media.title).toBeUndefined();
expect(media.alt).toBeUndefined();
expect(media.caption).toBeUndefined();
});
@@ -847,10 +856,36 @@ linkedPostIds: ["post-a", "post-b", "post-c"]`;
return chain;
});
const result = await mediaEngine.updateMedia('non-existent-id', { caption: 'New caption' });
const result = await mediaEngine.updateMedia('non-existent-id', { title: 'New title' });
expect(result).toBeNull();
});
it('should update media title', async () => {
vi.mocked(mockLocalDb.select).mockImplementation(() => {
const chain = createSelectChain();
chain.where = vi.fn().mockReturnValue({
...chain,
get: vi.fn().mockResolvedValue({
id: 'media-id',
projectId: 'default',
originalName: 'test.jpg',
mimeType: 'image/jpeg',
size: 1024,
filePath: '/mock/media/test.jpg',
title: 'Old title',
createdAt: new Date(),
updatedAt: new Date(),
}),
});
return chain;
});
const result = await mediaEngine.updateMedia('media-id', { title: 'New title' });
expect(result).not.toBeNull();
expect(result?.title).toBe('New title');
});
it('should update media caption', async () => {
vi.mocked(mockLocalDb.select).mockImplementation(() => {
const chain = createSelectChain();

View File

@@ -64,6 +64,7 @@ export function createMockMedia(overrides?: Partial<MediaData>): MediaData {
size: 1024 * 100, // 100KB
width: 800,
height: 600,
title: 'Test Image Title',
alt: 'Test image',
caption: 'A test image caption',
createdAt: now,