mattermost-mobile-upstream/app/components/block_renderer/mm_blocks_context_provider.test.tsx
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

78 lines
2.6 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useContext} from 'react';
import {Text} from 'react-native';
import {Screens} from '@constants';
import {renderWithIntlAndTheme} from '@test/intl-test-helper';
import {MmBlocksLayoutWidthContext, MmBlocksRenderContext} from './context';
import {MmBlocksContextProvider} from './mm_blocks_context_provider';
function ContextConsumer() {
const renderContext = useContext(MmBlocksRenderContext);
const layoutWidth = useContext(MmBlocksLayoutWidthContext);
return (
<Text testID='context-consumer'>
{JSON.stringify({
renderContext,
layoutWidth,
})}
</Text>
);
}
describe('MmBlocksContextProvider', () => {
it('should provide default and custom context values to descendants', () => {
const imagesMetadata = {'https://example.com/a.png': {width: 100, height: 100}};
const {getByTestId} = renderWithIntlAndTheme(
<MmBlocksContextProvider
channelId='channel-id'
location={Screens.CHANNEL}
postId='post-id'
imagesMetadata={imagesMetadata}
inlineMarkdownActions={{mmBlocksActionCookie: 'cookie'}}
layoutWidth={320}
>
<ContextConsumer/>
</MmBlocksContextProvider>,
);
expect(JSON.parse(getByTestId('context-consumer').props.children)).toEqual({
renderContext: {
channelId: 'channel-id',
location: Screens.CHANNEL,
postId: 'post-id',
imagesMetadata,
inlineMarkdownActions: {mmBlocksActionCookie: 'cookie'},
},
layoutWidth: 320,
});
});
it('should default optional values when omitted', () => {
const {getByTestId} = renderWithIntlAndTheme(
<MmBlocksContextProvider
channelId='channel-id'
location={Screens.CHANNEL}
postId='post-id'
>
<ContextConsumer/>
</MmBlocksContextProvider>,
);
expect(JSON.parse(getByTestId('context-consumer').props.children)).toEqual({
renderContext: {
channelId: 'channel-id',
location: Screens.CHANNEL,
postId: 'post-id',
imagesMetadata: undefined,
inlineMarkdownActions: {},
},
layoutWidth: undefined,
});
});
});