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>
67 lines
2.1 KiB
TypeScript
67 lines
2.1 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React from 'react';
|
|
|
|
import Markdown from '@components/markdown';
|
|
import {Preferences, Screens} from '@constants';
|
|
import {renderWithIntlAndTheme} from '@test/intl-test-helper';
|
|
|
|
import {MmBlocksContextProvider} from './mm_blocks_context_provider';
|
|
import {TextBlock} from './text_block';
|
|
|
|
jest.mock('@components/markdown', () => ({
|
|
__esModule: true,
|
|
default: jest.fn(),
|
|
}));
|
|
|
|
describe('TextBlock', () => {
|
|
const theme = Preferences.THEMES.denim;
|
|
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
jest.mocked(Markdown).mockImplementation(({value}: {value: string}) => (
|
|
React.createElement('Text', {testID: 'markdown'}, value)
|
|
));
|
|
});
|
|
|
|
function renderTextBlock(block: MmTextBlock) {
|
|
return renderWithIntlAndTheme(
|
|
<MmBlocksContextProvider
|
|
channelId='channel-id'
|
|
location={Screens.CHANNEL}
|
|
postId='post-id'
|
|
inlineMarkdownActions={{mmBlocksActionCookie: 'cookie', integrationFormat: 'attachment'}}
|
|
>
|
|
<TextBlock
|
|
block={block}
|
|
theme={theme}
|
|
/>
|
|
</MmBlocksContextProvider>,
|
|
);
|
|
}
|
|
|
|
it('should return null when text is empty', () => {
|
|
const {toJSON} = renderTextBlock({type: 'text', text: ''});
|
|
expect(toJSON()).toBeNull();
|
|
expect(jest.mocked(Markdown)).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should render markdown with render context and interaction flags', () => {
|
|
renderTextBlock({type: 'text', text: 'Hello **world**'});
|
|
|
|
expect(jest.mocked(Markdown)).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
value: 'Hello **world**',
|
|
channelId: 'channel-id',
|
|
postId: 'post-id',
|
|
location: Screens.CHANNEL,
|
|
allowInlineActions: true,
|
|
mmBlocksActionCookie: 'cookie',
|
|
integrationFormat: 'attachment',
|
|
}),
|
|
undefined,
|
|
);
|
|
});
|
|
});
|