Reorganize test cases

This commit is contained in:
trevor-signal
2025-06-26 12:24:07 -04:00
committed by GitHub
parent 3a745f2b6e
commit 843f545ceb
271 changed files with 236 additions and 245 deletions

View File

@@ -0,0 +1,137 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import { VIDEO_MP4 } from '../../types/MIME';
import { fakeAttachment } from '../../test-helpers/fakeAttachment';
import { shouldUseFullSizeLinkPreviewImage } from '../../linkPreviews/shouldUseFullSizeLinkPreviewImage';
describe('shouldUseFullSizeLinkPreviewImage', () => {
const baseLinkPreview = {
title: 'Foo Bar',
domain: 'example.com',
url: 'https://example.com/foo.html',
isStickerPack: false,
isCallLink: false,
};
it('returns false if there is no image', () => {
assert.isFalse(
shouldUseFullSizeLinkPreviewImage({
...baseLinkPreview,
})
);
});
it('returns false is the preview is a sticker pack', () => {
assert.isFalse(
shouldUseFullSizeLinkPreviewImage({
...baseLinkPreview,
isStickerPack: true,
image: fakeAttachment(),
})
);
});
it("returns false if either of the image's dimensions are missing", () => {
assert.isFalse(
shouldUseFullSizeLinkPreviewImage({
...baseLinkPreview,
image: fakeAttachment({ width: undefined }),
})
);
assert.isFalse(
shouldUseFullSizeLinkPreviewImage({
...baseLinkPreview,
image: fakeAttachment({ height: undefined }),
})
);
assert.isFalse(
shouldUseFullSizeLinkPreviewImage({
...baseLinkPreview,
image: fakeAttachment({ width: undefined, height: undefined }),
})
);
});
it("returns false if either of the image's dimensions are <200px", () => {
assert.isFalse(
shouldUseFullSizeLinkPreviewImage({
...baseLinkPreview,
image: fakeAttachment({ width: 199 }),
})
);
assert.isFalse(
shouldUseFullSizeLinkPreviewImage({
...baseLinkPreview,
image: fakeAttachment({ height: 199 }),
})
);
assert.isFalse(
shouldUseFullSizeLinkPreviewImage({
...baseLinkPreview,
image: fakeAttachment({ width: 150, height: 199 }),
})
);
});
it('returns false if the image is square', () => {
assert.isFalse(
shouldUseFullSizeLinkPreviewImage({
...baseLinkPreview,
image: fakeAttachment({ width: 200, height: 200 }),
})
);
assert.isFalse(
shouldUseFullSizeLinkPreviewImage({
...baseLinkPreview,
image: fakeAttachment({ width: 500, height: 500 }),
})
);
});
it('returns false if the image is roughly square', () => {
assert.isFalse(
shouldUseFullSizeLinkPreviewImage({
...baseLinkPreview,
image: fakeAttachment({ width: 200, height: 201 }),
})
);
assert.isFalse(
shouldUseFullSizeLinkPreviewImage({
...baseLinkPreview,
image: fakeAttachment({ width: 497, height: 501 }),
})
);
});
it("returns false for large attachments that aren't images", () => {
assert.isFalse(
shouldUseFullSizeLinkPreviewImage({
...baseLinkPreview,
image: fakeAttachment({
contentType: VIDEO_MP4,
fileName: 'foo.mp4',
url: '/tmp/foo.mp4',
}),
})
);
});
it('returns true for larger images', () => {
assert.isTrue(
shouldUseFullSizeLinkPreviewImage({
...baseLinkPreview,
image: fakeAttachment({ width: 200, height: 500 }),
})
);
assert.isTrue(
shouldUseFullSizeLinkPreviewImage({
...baseLinkPreview,
image: fakeAttachment(),
})
);
});
});