Skip to content

armgit / mimik

Public Imported from GitHub
0

🎬 A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots πŸ“–

fix(guides): collapse a multi-line title on every write path

davbiof132d8f6c6a3
diff --git a/src/core/guides/__tests__/import-guide.test.ts b/src/core/guides/__tests__/import-guide.test.ts
index e14afe5..a158254 100644
--- a/src/core/guides/__tests__/import-guide.test.ts
+++ b/src/core/guides/__tests__/import-guide.test.ts
@@ -60,6 +60,11 @@ describe('importGuide', () => {
expect(loaded?.screenshots.size).toBe(1);
});
+ it('collapses a multi-line title arriving in a bundle', async () => {
+ const id = await importGuide(makeBundle({ guide: { title: 'Set up\nyour profile', createdAt: 1 } }));
+ expect((await getGuide(id))?.guide.title).toBe('Set up your profile');
+ });
+
it('mints new identifiers rather than reusing the ones in the file', async () => {
const guideId = await importGuide(makeBundle());
const loaded = await getGuide(guideId);
diff --git a/src/core/guides/__tests__/service.test.ts b/src/core/guides/__tests__/service.test.ts
index fa12e85..38f14e4 100644
--- a/src/core/guides/__tests__/service.test.ts
+++ b/src/core/guides/__tests__/service.test.ts
@@ -40,6 +40,7 @@ import {
softDeleteGuide,
toggleStar,
updateGuideDescription,
+ updateGuideTitle,
} from '../service';
import type { Guide, Screenshot, Step } from '../types';
@@ -326,6 +327,25 @@ describe('getTrashedGuides', () => {
});
});
+describe('updateGuideTitle', () => {
+ it('collapses a multi-line title into one line before storing it', async () => {
+ await seedGuide('g-title', { updatedAt: 100 });
+
+ await updateGuideTitle('g-title', 'Set up\nyour profile');
+
+ const updated = await db.guides.get('g-title');
+ expect(updated!.title).toBe('Set up your profile');
+ expect(updated!.updatedAt).toBeGreaterThan(100);
+ expect(broadcastMessages).toContainEqual({ type: 'mutated' });
+ });
+
+ it('trims surrounding whitespace', async () => {
+ await seedGuide('g-title-trim');
+ await updateGuideTitle('g-title-trim', ' Set up your profile ');
+ expect((await db.guides.get('g-title-trim'))!.title).toBe('Set up your profile');
+ });
+});
+
describe('updateGuideDescription', () => {
it('stores the description, bumps updatedAt and broadcasts mutated', async () => {
await seedGuide('g-desc', { updatedAt: 100 });
diff --git a/src/core/guides/__tests__/snapshots.test.ts b/src/core/guides/__tests__/snapshots.test.ts
index 88dddb2..1a3e7c4 100644
--- a/src/core/guides/__tests__/snapshots.test.ts
+++ b/src/core/guides/__tests__/snapshots.test.ts
@@ -260,6 +260,16 @@ describe('renameSnapshot', () => {
});
describe('revertToSnapshot', () => {
+ it('collapses a multi-line title held by a snapshot taken before titles were single-line', async () => {
+ await seedGuide('g-legacy', { stepIds: [], title: 'Set up\nyour profile' });
+ const snapshot = await createSnapshot('g-legacy');
+
+ await updateGuideTitle('g-legacy', 'Changed');
+ await revertToSnapshot(snapshot!.id);
+
+ expect((await getGuide('g-legacy'))?.guide.title).toBe('Set up your profile');
+ });
+
it('restores title, step order and step content', async () => {
await seedGuide('g1', { stepIds: ['s1', 's2'], title: 'Original' });
await db.steps.bulkAdd([
diff --git a/src/core/guides/service.ts b/src/core/guides/service.ts
index ea06964..7920b4a 100644
--- a/src/core/guides/service.ts
+++ b/src/core/guides/service.ts
@@ -4,6 +4,7 @@ import type { ScreenshotEdits } from '@/core/screenshot/types';
import type { ParsedBundle } from '@/core/transfer/parse';
import { db } from './db';
import { hashPayload } from './snapshot-hash';
+import { sanitizeGuideTitle } from './title';
import type { BlockType, CalloutVariant, DescriptionSource, Guide, Screenshot, Snapshot, Step } from './types';
export type GuideChangeEvent = { type: 'starred'; id: string; starred: boolean } | { type: 'mutated' };
@@ -72,7 +73,7 @@ export async function getTrashedGuides(): Promise<Guide[]> {
}
export async function updateGuideTitle(id: string, title: string): Promise<void> {
- await db.guides.update(id, { title, updatedAt: Date.now() });
+ await db.guides.update(id, { title: sanitizeGuideTitle(title), updatedAt: Date.now() });
notifyGuidesChanged({ type: 'mutated' });
}
@@ -165,7 +166,7 @@ export async function importGuide(bundle: ParsedBundle): Promise<string> {
const guide: Guide = {
id: guideId,
- title: manifest.guide.title,
+ title: sanitizeGuideTitle(manifest.guide.title),
...(manifest.guide.description ? { description: manifest.guide.description } : {}),
createdAt: now,
updatedAt: now,
@@ -444,7 +445,7 @@ export async function revertToSnapshot(snapshotId: string): Promise<Snapshot | n
.filter((r): r is Screenshot => r !== null);
if (merged.length > 0) await db.screenshots.bulkPut(merged);
await db.guides.update(snapshot.guideId, {
- title: snapshot.title,
+ title: sanitizeGuideTitle(snapshot.title),
stepIds: snapshot.stepIds,
updatedAt: Date.now(),
});