* 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 --------- Co-authored-by: Matthew Birtch <mattbirtch@gmail.com>
123 lines
4.5 KiB
TypeScript
123 lines
4.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 UnrevealedBurnOnReadPost from '@components/post_list/post/burn_on_read/unrevealed';
|
|
import {PostTypes} from '@constants/post';
|
|
import NetworkManager from '@managers/network_manager';
|
|
import PerformanceMetricsManager from '@managers/performance_metrics_manager';
|
|
import {getPostById} from '@queries/servers/post';
|
|
import {renderWithEverything, waitFor} from '@test/intl-test-helper';
|
|
import TestHelper from '@test/test_helper';
|
|
|
|
import Body from './body';
|
|
import Post from './post';
|
|
|
|
import type {Database} from '@nozbe/watermelondb';
|
|
import type PostModel from '@typings/database/models/servers/post';
|
|
|
|
jest.mock('@managers/performance_metrics_manager');
|
|
jest.mock('@components/post_list/post/burn_on_read/unrevealed');
|
|
jest.mock('./body');
|
|
|
|
describe('performance metrics', () => {
|
|
let database: Database;
|
|
let post: PostModel;
|
|
|
|
function getBaseProps(): ComponentProps<typeof Post> {
|
|
return {
|
|
appsEnabled: false,
|
|
canDelete: false,
|
|
customEmojiNames: [],
|
|
differentThreadSequence: false,
|
|
hasFiles: false,
|
|
hasReactions: false,
|
|
hasReplies: false,
|
|
highlightReplyBar: false,
|
|
isEphemeral: false,
|
|
isPostAddChannelMember: false,
|
|
isPostPriorityEnabled: false,
|
|
location: 'Channel',
|
|
post,
|
|
isLastPost: true,
|
|
isChannelAutotranslated: false,
|
|
};
|
|
}
|
|
|
|
const serverUrl = 'http://www.someserverurl.com';
|
|
beforeEach(async () => {
|
|
const client = await NetworkManager.createClient(serverUrl);
|
|
expect(client).toBeTruthy();
|
|
database = (await TestHelper.setupServerDatabase(serverUrl)).database;
|
|
post = (await getPostById(database, TestHelper.basicPost!.id))!;
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await TestHelper.tearDown();
|
|
NetworkManager.invalidateClient(serverUrl);
|
|
});
|
|
|
|
it('do not call the performance metrics if it is not the last post', async () => {
|
|
const props = getBaseProps();
|
|
props.isLastPost = false;
|
|
renderWithEverything(<Post {...props}/>, {database, serverUrl});
|
|
await waitFor(() => {
|
|
expect(PerformanceMetricsManager.finishLoad).not.toHaveBeenCalled();
|
|
expect(PerformanceMetricsManager.endMetric).not.toHaveBeenCalled();
|
|
});
|
|
});
|
|
it('on channel', async () => {
|
|
const props = getBaseProps();
|
|
renderWithEverything(<Post {...props}/>, {database, serverUrl});
|
|
await waitFor(() => {
|
|
expect(PerformanceMetricsManager.finishLoad).toHaveBeenCalledWith('CHANNEL', serverUrl);
|
|
expect(PerformanceMetricsManager.endMetric).toHaveBeenCalledWith('mobile_channel_switch', serverUrl);
|
|
});
|
|
});
|
|
it('on thread', async () => {
|
|
const props = getBaseProps();
|
|
props.location = 'Thread';
|
|
renderWithEverything(<Post {...props}/>, {database, serverUrl});
|
|
await waitFor(() => {
|
|
expect(PerformanceMetricsManager.finishLoad).toHaveBeenCalledWith('THREAD', serverUrl);
|
|
expect(PerformanceMetricsManager.endMetric).toHaveBeenCalledWith('mobile_channel_switch', serverUrl);
|
|
});
|
|
});
|
|
|
|
it('should render unrevealed post correctly', async () => {
|
|
const props = getBaseProps();
|
|
props.post = TestHelper.fakePostModel({
|
|
type: PostTypes.BURN_ON_READ,
|
|
props: {
|
|
expire_at: Date.now() + 1000000,
|
|
},
|
|
});
|
|
|
|
renderWithEverything(<Post {...props}/>, {database, serverUrl});
|
|
await waitFor(() => {
|
|
expect(UnrevealedBurnOnReadPost).toHaveBeenCalled();
|
|
});
|
|
});
|
|
|
|
it('own BoR post should show as revealed even without metadata', async () => {
|
|
const currentUser = TestHelper.fakeUserModel();
|
|
const props = {
|
|
...getBaseProps(),
|
|
currentUser,
|
|
};
|
|
props.post = TestHelper.fakePostModel({
|
|
type: PostTypes.BURN_ON_READ,
|
|
userId: currentUser.id,
|
|
props: {
|
|
expire_at: Date.now() + 1000000,
|
|
},
|
|
});
|
|
|
|
renderWithEverything(<Post {...props}/>, {database, serverUrl});
|
|
await waitFor(() => {
|
|
expect(Body).toHaveBeenCalled();
|
|
});
|
|
expect(UnrevealedBurnOnReadPost).not.toHaveBeenCalled();
|
|
});
|
|
});
|