mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-10 13:10: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>
109 lines
3.5 KiB
TypeScript
109 lines
3.5 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React, {type ComponentProps} from 'react';
|
|
|
|
import DatabaseManager from '@database/manager';
|
|
import {act, renderWithEverything, waitFor} from '@test/intl-test-helper';
|
|
|
|
import ExternalImage from './external_image';
|
|
|
|
import EnhancedExternalImage from './';
|
|
|
|
import type ServerDataOperator from '@database/operator/server_data_operator';
|
|
import type {Database} from '@nozbe/watermelondb';
|
|
|
|
jest.mock('./external_image', () => ({
|
|
__esModule: true,
|
|
default: jest.fn(),
|
|
}));
|
|
jest.mocked(ExternalImage).mockImplementation(
|
|
(props) => React.createElement('ExternalImage', {testID: 'external-image', ...props}),
|
|
);
|
|
|
|
describe('EnhancedExternalImage (withObservables and withDatabase)', () => {
|
|
let database: Database;
|
|
let operator: ServerDataOperator;
|
|
const serverUrl = 'https://server-url.com';
|
|
|
|
beforeEach(async () => {
|
|
await DatabaseManager.init([serverUrl]);
|
|
const serverDatabaseAndOperator = DatabaseManager.getServerDatabaseAndOperator(serverUrl);
|
|
database = serverDatabaseAndOperator.database;
|
|
operator = serverDatabaseAndOperator.operator;
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await DatabaseManager.destroyServerDatabase(serverUrl);
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
function getBaseProps(): ComponentProps<typeof EnhancedExternalImage> {
|
|
return {
|
|
children: jest.fn(() => null),
|
|
src: 'https://example.com/image.png',
|
|
};
|
|
}
|
|
|
|
it('should pass default config values when not set in the database', async () => {
|
|
const props = getBaseProps();
|
|
const {getByTestId} = renderWithEverything(
|
|
<EnhancedExternalImage {...props}/>,
|
|
{database, serverUrl},
|
|
);
|
|
|
|
await waitFor(() => {
|
|
const component = getByTestId('external-image');
|
|
expect(component.props.enableSVGs).toBe(false);
|
|
expect(component.props.hasImageProxy).toBe(false);
|
|
});
|
|
});
|
|
|
|
it('should pass config values from the database', async () => {
|
|
await operator.handleConfigs({
|
|
configs: [
|
|
{id: 'EnableSVGs', value: 'true'},
|
|
{id: 'HasImageProxy', value: 'true'},
|
|
],
|
|
configsToDelete: [],
|
|
prepareRecordsOnly: false,
|
|
});
|
|
|
|
const props = getBaseProps();
|
|
const {getByTestId} = renderWithEverything(
|
|
<EnhancedExternalImage {...props}/>,
|
|
{database, serverUrl},
|
|
);
|
|
|
|
await waitFor(() => {
|
|
const component = getByTestId('external-image');
|
|
expect(component.props.enableSVGs).toBe(true);
|
|
expect(component.props.hasImageProxy).toBe(true);
|
|
});
|
|
});
|
|
|
|
it('should update when config values change', async () => {
|
|
const props = getBaseProps();
|
|
const {getByTestId} = renderWithEverything(
|
|
<EnhancedExternalImage {...props}/>,
|
|
{database, serverUrl},
|
|
);
|
|
|
|
await waitFor(() => {
|
|
expect(getByTestId('external-image').props.enableSVGs).toBe(false);
|
|
});
|
|
|
|
await act(async () => {
|
|
await operator.handleConfigs({
|
|
configs: [{id: 'EnableSVGs', value: 'true'}],
|
|
configsToDelete: [],
|
|
prepareRecordsOnly: false,
|
|
});
|
|
});
|
|
|
|
await waitFor(() => {
|
|
expect(getByTestId('external-image').props.enableSVGs).toBe(true);
|
|
});
|
|
});
|
|
});
|