mattermost-mobile/app/components/post_list/post/post.test.tsx
Elias Nahum 374f812b98
Update dependencies (#8721)
* update fastlane

* update dev dependencies

* update to eslint 9+

* update testing-library

* update react-intl

* update bottom-sheet

* update expo

* update reanimated

* upgrade msgpack

* upgrade datepicker

* upgrade react-navigation

* update sentry

* update FlasList

* update fuse.js moment-timezone node-html-parser and semver

* update gesture-handler

* update image-picker

* update react-native-keychain

* update react-native-localize

* update react-native-navigation

* update watermelonDB

* update react-native-permissions

* update react-native-safe-area-context and react-native-screens

* update react-native-share and react-native-svg

* update react-native-video and react-native-webrtc

* update @mattermost/rnutils

* update @mattermost/rnshare

* update @mattermost/hardware-keyboard

* fix isMainActivity

* update android dependencies

* fix upload file progress indicator

* fix entry update config & license

* revert to stable version of @sentry/react-native

* update react-intl again

* update moment-timezone

* upgrade @react-native-camera-roll/camera-roll

* update @react-native-clipboard/clipboard

* update @react-navigation again

* update @shopify/flash-list

* update eslint

* update expo again

* update html-entities

* update mime-db

* update react-native-permissions

* Revert "update react-intl again"

This reverts commit e8e6d5a60dfa56b82b810cbbd7cdffec7697ffc7.

* Revert "update react-intl"

This reverts commit c77f329bb38910aeeba03869b72d77a8b0e00ba1.

* update react-native-keychain

* update and patch react-intl

* mend

* feedback during review 1
2025-04-07 09:30:06 +08:00

81 lines
3 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {type ComponentProps} from 'react';
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 Post from './post';
import type {Database} from '@nozbe/watermelondb';
import type PostModel from '@typings/database/models/servers/post';
jest.mock('@managers/performance_metrics_manager');
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,
};
}
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);
});
});
});