mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-07 19:30:14 +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>
75 lines
2.0 KiB
TypeScript
75 lines
2.0 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React from 'react';
|
|
|
|
import {renderWithIntl} from '@test/intl-test-helper';
|
|
|
|
import ExternalImage from './external_image';
|
|
|
|
jest.mock('@context/server', () => ({
|
|
...jest.requireActual('@context/server'),
|
|
useServerUrl: () => 'https://server.example.com',
|
|
}));
|
|
|
|
jest.mock('@managers/network_manager', () => ({
|
|
__esModule: true,
|
|
default: {
|
|
getClient: () => ({
|
|
getBaseRoute: () => 'https://server.example.com/api/v4',
|
|
}),
|
|
},
|
|
}));
|
|
|
|
describe('ExternalImage', () => {
|
|
const baseProps = {
|
|
children: jest.fn((src: string) => <>{src}</>),
|
|
enableSVGs: true,
|
|
hasImageProxy: false,
|
|
imageMetadata: {
|
|
format: 'png',
|
|
height: 300,
|
|
width: 200,
|
|
},
|
|
src: 'https://example.com/image.png',
|
|
};
|
|
|
|
beforeEach(() => {
|
|
jest.mocked(baseProps.children).mockClear();
|
|
});
|
|
|
|
it('should pass through src when proxy is disabled', () => {
|
|
renderWithIntl(
|
|
<ExternalImage {...baseProps}/>,
|
|
);
|
|
|
|
expect(baseProps.children).toHaveBeenCalledWith(baseProps.src);
|
|
});
|
|
|
|
it('should pass empty src for svg when svgs are disabled', () => {
|
|
renderWithIntl(
|
|
<ExternalImage
|
|
{...baseProps}
|
|
enableSVGs={false}
|
|
imageMetadata={{format: 'svg', height: 0, width: 0}}
|
|
src='https://example.com/logo.svg'
|
|
/>,
|
|
);
|
|
|
|
expect(baseProps.children).toHaveBeenCalledWith('');
|
|
});
|
|
|
|
it('should proxy src when image proxy is enabled', () => {
|
|
renderWithIntl(
|
|
<ExternalImage
|
|
{...baseProps}
|
|
hasImageProxy={true}
|
|
/>,
|
|
);
|
|
|
|
expect(baseProps.children).toHaveBeenCalledWith(
|
|
'https://server.example.com/api/v4/image?url=' + encodeURIComponent(baseProps.src),
|
|
);
|
|
});
|
|
});
|