Files
Toju/toju-app/src/app/domains/attachment/domain/logic/attachment-image.rules.spec.ts
Myx bb0ac930ad
All checks were successful
Queue Release Build / prepare (push) Successful in 20s
Deploy Web Apps / deploy (push) Successful in 9m2s
Queue Release Build / build-windows (push) Successful in 28m8s
Queue Release Build / build-linux (push) Successful in 47m26s
Queue Release Build / build-android (push) Successful in 19m52s
Queue Release Build / finalize (push) Successful in 4m42s
Improve attachment memory safety, downloads, and high-memory alert UX.
Stream large receives to disk with chunk acks to cap renderer RAM, evict
off-screen display blobs, and route exports through a disk-aware download
service. Fix the high-memory dialog (backdrop dismiss, copy, log actions),
allow diagnostics paths in the path jail, and restore persisted image
hydration after reload.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-14 00:25:22 +02:00

86 lines
2.1 KiB
TypeScript

import {
describe,
expect,
it
} from 'vitest';
import {
dedupeImageAttachmentsForDisplay,
hasImageFilename,
isAttachmentPendingInlineHydration,
isImageAttachment,
isInlineDisplayableImage,
resolvePublishAttachmentIsImage
} from './attachment-image.rules';
describe('attachment-image rules', () => {
it('detects images from mime, flag, or filename extension', () => {
expect(isImageAttachment({
id: '1',
filename: 'logo.PNG',
mime: 'application/octet-stream',
isImage: false,
available: false
})).toBe(true);
expect(hasImageFilename('photo.jpeg')).toBe(true);
expect(resolvePublishAttachmentIsImage({ name: 'photo.png', type: '' })).toBe(true);
});
it('treats file protocol urls as not inline displayable', () => {
expect(isInlineDisplayableImage({
available: true,
objectUrl: 'file:///tmp/photo.png'
})).toBe(false);
expect(isInlineDisplayableImage({
available: true,
objectUrl: 'blob:http://localhost/abc'
})).toBe(true);
});
it('detects images waiting for on-demand blob hydration', () => {
expect(isAttachmentPendingInlineHydration({
id: '1',
filename: 'photo.png',
mime: 'image/png',
isImage: true,
available: false,
savedPath: '/appdata/photo.png'
})).toBe(true);
expect(isAttachmentPendingInlineHydration({
id: '2',
filename: 'photo.png',
mime: 'image/png',
isImage: true,
available: true,
objectUrl: 'blob:http://localhost/photo',
savedPath: '/appdata/photo.png'
})).toBe(false);
});
it('dedupes image attachments by filename and prefers displayable copies', () => {
const deduped = dedupeImageAttachmentsForDisplay([
{
id: 'a',
filename: 'photo.png',
mime: 'image/png',
isImage: true,
available: false
},
{
id: 'b',
filename: 'photo.png',
mime: 'application/octet-stream',
isImage: false,
available: true,
objectUrl: 'blob:http://localhost/photo'
}
]);
expect(deduped).toHaveLength(1);
expect(deduped[0]?.id).toBe('b');
});
});