mattermost-mobile/app/screens/channel_info/options/index.test.tsx
Mattermost Build e8f1d0c729
Add autotranslations (#9324) (#9500)
* Add autotranslations

* Develop latest changes and missing features

* i18n-extract

* Fix tests and update api behavior

* Fix minor bugs

* adjustments to shimmer animation, showtranslation modal style

* Update post.tsx

* Update show_translation.tsx

* adjust sizing and opacity of translate icon

* Add channel header translated icon

* Disable auto translation item if it is not a supported language

* Move channel info to the top

* Update edit channel to channel info

* Fix align of option items

* Fix i18n

* Add detox related changes for channel settings changes

* Add tests

* Address changes around the my channel column change

* Address feedback

* Fix test

* Fix bad import

* Fix set my channel autotranslation

* Fix test

* Address feedback

* Add missing files from last commit

* Remove unneeded change

---------


(cherry picked from commit 23565b5135)

Co-authored-by: Daniel Espino García <larkox@gmail.com>
Co-authored-by: Matthew Birtch <mattbirtch@gmail.com>
2026-02-11 08:09:39 +02:00

80 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 {General} from '@constants';
import DatabaseManager from '@database/manager';
import PlaybookRunsOption from '@playbooks/components/channel_actions/playbook_runs_option';
import {renderWithEverything} from '@test/intl-test-helper';
import MyAutotranslation from './my_autotranslation';
import ChannelInfoOptions from './';
import type {Database} from '@nozbe/watermelondb';
const serverUrl = 'some.server.url';
jest.mock('@playbooks/components/channel_actions/playbook_runs_option');
jest.mocked(PlaybookRunsOption).mockImplementation((props) => {
return React.createElement('PlaybookRunsOption', {...props, testID: 'playbook-runs-option'});
});
jest.mock('./my_autotranslation');
jest.mocked(MyAutotranslation).mockImplementation((props) => {
return React.createElement('MyAutotranslation', {...props, testID: 'my-autotranslation-option'});
});
describe('ChannelInfoOptions', () => {
let database: Database;
function getBaseProps(): ComponentProps<typeof ChannelInfoOptions> {
return {
channelId: 'channel-id',
callsEnabled: false,
canManageMembers: false,
isCRTEnabled: false,
isPlaybooksEnabled: true,
hasChannelSettingsActions: false,
isAutotranslationEnabledForThisChannel: true,
};
}
beforeEach(async () => {
await DatabaseManager.init([serverUrl]);
const serverDatabaseAndOperator = DatabaseManager.getServerDatabaseAndOperator(serverUrl);
database = serverDatabaseAndOperator.database;
});
it('should pass the channel id correctly to the PlaybookRunsOption', () => {
const props = getBaseProps();
const {getByTestId, rerender} = renderWithEverything(<ChannelInfoOptions {...props}/>, {database});
expect(getByTestId('playbook-runs-option')).toHaveProp('channelId', 'channel-id');
expect(getByTestId('playbook-runs-option')).toHaveProp('location', 'channel_actions');
props.channelId = 'channel-id-2';
rerender(<ChannelInfoOptions {...props}/>);
expect(getByTestId('playbook-runs-option')).toHaveProp('channelId', 'channel-id-2');
});
it('should not show playbook runs option when is DM or GM', () => {
const props = getBaseProps();
props.type = General.DM_CHANNEL;
const {queryByTestId, rerender} = renderWithEverything(<ChannelInfoOptions {...props}/>, {database});
expect(queryByTestId('playbook-runs-option')).toBeNull();
props.type = General.GM_CHANNEL;
rerender(<ChannelInfoOptions {...props}/>);
expect(queryByTestId('playbook-runs-option')).toBeNull();
});
it('should not show my autotranslation option when isAutotranslationEnabledForThisChannel is false', () => {
const props = getBaseProps();
props.isAutotranslationEnabledForThisChannel = false;
const {queryByTestId} = renderWithEverything(<ChannelInfoOptions {...props}/>, {database});
expect(queryByTestId('my-autotranslation-option')).toBeNull();
});
it('should show my autotranslation option when isAutotranslationEnabledForThisChannel is true', () => {
const props = getBaseProps();
props.isAutotranslationEnabledForThisChannel = true;
const {getByTestId} = renderWithEverything(<ChannelInfoOptions {...props}/>, {database});
expect(getByTestId('my-autotranslation-option')).toBeTruthy();
});
});