mattermost-mobile-upstream/app/components/block_renderer/utils/image.test.ts
Daniel Espino García 84ea188366
Mattermost Blocks (#9764)
* Mattermost Blocks

* Move block renderer to its own components folder

* Sync translation layer

* UX fixes

* Refactor button to use the button component

* Code review

* Fix CI

* Add animations to collapse blocks

* Add unit tests

* Add e2e tests and related fixes

* Address coderabbit comments

* Address UX comments

* Address feedback

* Address coderabbit comments

* Fix snapshots

* Sync with webapp translation

* Add node limit to button markdown node

* Address feedback

* i18n-extract

* Fix test

* Move image utils to the utils folder

* Remove unneeded style

* Revert build script change

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
2026-06-29 18:42:16 +02:00

56 lines
1.7 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {
computeMmBlocksImageLayout,
refineMmBlocksImageLayoutFromIntrinsic,
resolveMmImageCaps,
} from './image';
describe('image', () => {
it('should resolve caps from block size', () => {
expect(resolveMmImageCaps({type: 'image', url: 'https://x', size: 'small'})).toEqual({
maxWidth: 204,
maxHeight: 120,
});
});
it('should size from metadata within caps', () => {
const layout = computeMmBlocksImageLayout(
{maxWidth: 120, maxHeight: 120},
400,
{width: 800, height: 600},
400,
);
expect(layout.width).toBeLessThanOrEqual(120);
expect(layout.height).toBeLessThanOrEqual(120);
expect(layout.galleryWidth).toBe(800);
expect(layout.galleryHeight).toBe(600);
});
it('should use cap box when metadata is missing', () => {
const layout = computeMmBlocksImageLayout(
{maxWidth: 200, maxHeight: 150},
400,
undefined,
400,
);
expect(layout.width).toBe(200);
expect(layout.height).toBe(150);
});
it('should refine layout from intrinsic dimensions', () => {
const layout = refineMmBlocksImageLayoutFromIntrinsic(
800,
400,
{maxWidth: 200, maxHeight: 150},
400,
400,
);
expect(layout.width).toBeLessThanOrEqual(200);
expect(layout.height).toBeLessThanOrEqual(150);
expect(layout.galleryWidth).toBe(800);
expect(layout.galleryHeight).toBe(400);
});
});