mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-06 10:50:13 +00:00
* 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>
79 lines
2.6 KiB
TypeScript
79 lines
2.6 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React from 'react';
|
|
import {Text} from 'react-native';
|
|
|
|
import {Preferences, Screens} from '@constants';
|
|
import {renderWithIntlAndTheme} from '@test/intl-test-helper';
|
|
|
|
import {ImageBlock} from './image_block';
|
|
import {MmBlocksContextProvider} from './mm_blocks_context_provider';
|
|
import MmBlocksImage from './mm_blocks_image';
|
|
|
|
jest.mock('./mm_blocks_image', () => ({
|
|
__esModule: true,
|
|
default: jest.fn(),
|
|
}));
|
|
|
|
describe('ImageBlock', () => {
|
|
const theme = Preferences.THEMES.denim;
|
|
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
jest.mocked(MmBlocksImage).mockImplementation(({imageUrl, altText, caps}: {
|
|
imageUrl: string;
|
|
altText?: string;
|
|
caps: {maxWidth?: number; maxHeight?: number};
|
|
}) => (
|
|
React.createElement(Text, {testID: 'mm-blocks-image'}, `${imageUrl}|${altText ?? ''}|${caps.maxWidth ?? ''}`)
|
|
));
|
|
});
|
|
|
|
function renderImageBlock(block: MmImageBlock, imagesMetadata?: Record<string, PostImage>) {
|
|
return renderWithIntlAndTheme(
|
|
<MmBlocksContextProvider
|
|
channelId='channel-id'
|
|
location={Screens.CHANNEL}
|
|
postId='post-id'
|
|
imagesMetadata={imagesMetadata}
|
|
>
|
|
<ImageBlock
|
|
block={block}
|
|
theme={theme}
|
|
/>
|
|
</MmBlocksContextProvider>,
|
|
);
|
|
}
|
|
|
|
it('should return null when url is empty', () => {
|
|
const {queryByTestId} = renderImageBlock({type: 'image', url: ' '});
|
|
expect(queryByTestId('mm-blocks-image')).toBeNull();
|
|
});
|
|
|
|
it('should pass trimmed url, caps, and metadata to MmBlocksImage', () => {
|
|
const metadata = {width: 400, height: 300};
|
|
const {getByTestId} = renderImageBlock(
|
|
{
|
|
type: 'image',
|
|
url: ' https://example.com/photo.png ',
|
|
alt_text: 'Photo',
|
|
size: 'small',
|
|
horizontal_alignment: 'center',
|
|
},
|
|
{'https://example.com/photo.png': metadata},
|
|
);
|
|
|
|
expect(getByTestId('mm-blocks-image')).toHaveTextContent('https://example.com/photo.png|Photo|204');
|
|
expect(jest.mocked(MmBlocksImage)).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
imageUrl: 'https://example.com/photo.png',
|
|
altText: 'Photo',
|
|
imageMetadata: metadata,
|
|
theme,
|
|
}),
|
|
undefined,
|
|
);
|
|
});
|
|
});
|