* Added scaffolding for unrevealed BoR post * Displayed reveal UI * Displayed expiry timer * WIP * Displayed own post indicator and blur text * restored button * Ungrouped BoR posts * WIP * WIP * DIsplayed error message on revealing * Added last run check on mobile app cleanup job * Cleanup * lint fix * i18n-fix * Added tests * test: add test suite for revealBoRPost function * test: add unrevealed burn on read post test file * feat: add tests for UnrevealedBurnOnReadPost component * test: update UnrevealedBurnOnReadPost test with PostModel type * test: replace toBeTruthy with toBeVisible for component visibility assertions * test: add initial test file for expiry timer component * test: add comprehensive tests for ExpiryCountdown component * refactor: clean up test formatting and remove redundant test case * fix: adjust test timing for ExpiryCountdown onExpiry callback * test: fix timer test by advancing timers in smaller increments * Added tests * Updated tests * fixed accidental change * restored package.resolved * WIP review fixes * Review fixes * Review fixes * Fixed tests * restored package.resolved * WIP * test: add test for skipping BoR post cleanup within 15 minutes * test: add comprehensive test cases for expiredBoRPostCleanup * WIP * WIP * test: add bor.test.ts placeholder file * test: add comprehensive tests for BoR utility functions * test: add comprehensive tests for formatTime function * WIP * test: add comprehensive tests for getLastBoRPostCleanupRun function * Added tests * removed a commented code * post list optimization * test: add test case for updating unrevealed burn-on-read post * fix: handle error logging in expiredBoRPostCleanup test * test: add test case for updateLastBoRCleanupRun error handling * review fixes * lint fixes * Added WS event handling (#9320) * Added WS event handling * test: add burn on read websocket action test * test: add tests for handleBoRPostRevealedEvent in burn_on_read * Added tests * test: add comprehensive error handling test cases for burn on read * Added tests and error handling * BoR post - restricted actions (#9315) * Restricted post actions for BoR post type * Prevent opening thread fr nBoR post * WIP * fix: remove redundant observable wrapping in post options * fixed a change * removed broken * restored package.resolved * Added tests * Awaiting for last run to be set * Added tests for validating expiry timer behaviour (#9338) * Added tests for validating expiry timer behaviour * No need of use event setup * Bor ux fixes (#9336) * WIP * UI and delete fixes * lint fixes * fixed tests * Improved mocking * Improved test
222 lines
9.3 KiB
TypeScript
222 lines
9.3 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {DeviceEventEmitter} from 'react-native';
|
|
|
|
import {markChannelAsViewed} from '@actions/local/channel';
|
|
import {dataRetentionCleanup, expiredBoRPostCleanup} from '@actions/local/systems';
|
|
import {markChannelAsRead} from '@actions/remote/channel';
|
|
import {entry, handleEntryAfterLoadNavigation} from '@actions/remote/entry/common';
|
|
import {deferredAppEntryActions} from '@actions/remote/entry/deferred';
|
|
import {fetchPostsForChannel, fetchPostThread} from '@actions/remote/post';
|
|
import {openAllUnreadChannels} from '@actions/remote/preference';
|
|
import {loadConfigAndCalls} from '@calls/actions/calls';
|
|
import {isSupportedServerCalls} from '@calls/utils';
|
|
import DatabaseManager from '@database/manager';
|
|
import AppsManager from '@managers/apps_manager';
|
|
import {handlePlaybookReconnect} from '@playbooks/actions/websocket/reconnect';
|
|
import {getActiveServerUrl} from '@queries/app/servers';
|
|
import {getLastPostInThread} from '@queries/servers/post';
|
|
import {getConfig, getCurrentChannelId, getCurrentTeamId, setLastFullSync} from '@queries/servers/system';
|
|
import {getIsCRTEnabled} from '@queries/servers/thread';
|
|
import {getCurrentUser} from '@queries/servers/user';
|
|
import EphemeralStore from '@store/ephemeral_store';
|
|
import NavigationStore from '@store/navigation_store';
|
|
import TestHelper from '@test/test_helper';
|
|
|
|
import {handleFirstConnect, handleReconnect} from './index';
|
|
|
|
jest.mock('@actions/local/channel');
|
|
jest.mock('@actions/local/systems');
|
|
jest.mock('@actions/remote/channel');
|
|
jest.mock('@actions/remote/entry/common');
|
|
jest.mock('@actions/remote/entry/deferred');
|
|
jest.mock('@actions/remote/post');
|
|
jest.mock('@actions/remote/scheduled_post');
|
|
jest.mock('@actions/remote/preference');
|
|
jest.mock('@actions/remote/user');
|
|
jest.mock('@calls/actions/calls');
|
|
jest.mock('@calls/utils');
|
|
jest.mock('@database/manager');
|
|
jest.mock('@managers/apps_manager');
|
|
jest.mock('@queries/app/servers');
|
|
jest.mock('@queries/servers/post');
|
|
jest.mock('@queries/servers/system');
|
|
jest.mock('@queries/servers/thread');
|
|
jest.mock('@queries/servers/user');
|
|
jest.mock('@store/ephemeral_store');
|
|
jest.mock('@store/navigation_store');
|
|
jest.mock('@store/team_load_store');
|
|
jest.mock('@utils/helpers', () => ({
|
|
isTablet: jest.fn().mockReturnValue(false),
|
|
}));
|
|
|
|
jest.mock('@playbooks/actions/websocket/reconnect');
|
|
|
|
describe('WebSocket Index Actions', () => {
|
|
const serverUrl = 'baseHandler.test.com';
|
|
const currentUserId = 'current-user-id';
|
|
const currentTeamId = 'current-team-id';
|
|
const currentChannelId = 'current-channel-id';
|
|
const groupLabel = 'DeepLink';
|
|
|
|
beforeEach(async () => {
|
|
jest.clearAllMocks();
|
|
jest.spyOn(DeviceEventEmitter, 'emit');
|
|
await DatabaseManager.init([serverUrl]);
|
|
DatabaseManager.serverDatabases[serverUrl] = {
|
|
operator: {
|
|
database: {},
|
|
batchRecords: jest.fn(),
|
|
},
|
|
} as any;
|
|
DatabaseManager.getServerDatabaseAndOperator = jest.fn().mockReturnValue({
|
|
database: {},
|
|
operator: {
|
|
batchRecords: jest.fn(),
|
|
},
|
|
});
|
|
});
|
|
|
|
describe('handleFirstConnect', () => {
|
|
it('should handle first connection successfully', async () => {
|
|
const mockEntryData = {
|
|
models: [],
|
|
initialTeamId: currentTeamId,
|
|
initialChannelId: currentChannelId,
|
|
prefData: {preferences: []},
|
|
teamData: {memberships: [], teams: []},
|
|
chData: {memberships: [], channels: []},
|
|
gmConverted: false,
|
|
};
|
|
|
|
jest.mocked(entry).mockResolvedValue(mockEntryData);
|
|
jest.mocked(getCurrentUser).mockResolvedValue(TestHelper.fakeUserModel({
|
|
id: currentUserId,
|
|
locale: 'en',
|
|
}));
|
|
jest.mocked(getConfig).mockResolvedValue({Version: '9.0.0'} as ClientConfig);
|
|
jest.mocked(isSupportedServerCalls).mockReturnValue(true);
|
|
|
|
const error = await handleFirstConnect(serverUrl, groupLabel);
|
|
|
|
expect(error).toBeUndefined();
|
|
expect(entry).toHaveBeenCalled();
|
|
expect(handleEntryAfterLoadNavigation).toHaveBeenCalled();
|
|
expect(setLastFullSync).toHaveBeenCalled();
|
|
expect(loadConfigAndCalls).toHaveBeenCalled();
|
|
expect(deferredAppEntryActions).toHaveBeenCalled();
|
|
expect(handlePlaybookReconnect).toHaveBeenCalledWith(serverUrl);
|
|
});
|
|
|
|
it('should handle error when server database not found', async () => {
|
|
DatabaseManager.serverDatabases = {};
|
|
|
|
const error = await handleFirstConnect(serverUrl);
|
|
|
|
expect(error).toBeInstanceOf(Error);
|
|
expect((error as Error).message).toBe('cannot find server database');
|
|
});
|
|
});
|
|
|
|
describe('handleReconnect', () => {
|
|
beforeEach(() => {
|
|
jest.mocked(NavigationStore.getScreensInStack).mockReturnValue([]);
|
|
jest.mocked(getActiveServerUrl).mockResolvedValue(serverUrl);
|
|
jest.mocked(getCurrentChannelId).mockResolvedValue(currentChannelId);
|
|
jest.mocked(getCurrentTeamId).mockResolvedValue(currentTeamId);
|
|
jest.mocked(getIsCRTEnabled).mockResolvedValue(false);
|
|
jest.mocked(EphemeralStore.getCurrentThreadId).mockReturnValue('');
|
|
jest.mocked(EphemeralStore.wasNotificationTapped).mockReturnValue(false);
|
|
});
|
|
|
|
it('should handle reconnection successfully', async () => {
|
|
const mockEntryData = {
|
|
models: [],
|
|
initialTeamId: currentTeamId,
|
|
initialChannelId: currentChannelId,
|
|
prefData: {preferences: []},
|
|
teamData: {memberships: [], teams: []},
|
|
chData: {memberships: [], channels: []},
|
|
gmConverted: false,
|
|
};
|
|
|
|
jest.mocked(entry).mockResolvedValue(mockEntryData);
|
|
jest.mocked(getCurrentUser).mockResolvedValue(TestHelper.fakeUserModel({
|
|
id: currentUserId,
|
|
locale: 'en',
|
|
}));
|
|
jest.mocked(getConfig).mockResolvedValue({Version: '9.0.0'} as ClientConfig);
|
|
jest.mocked(isSupportedServerCalls).mockReturnValue(true);
|
|
jest.mocked(getActiveServerUrl).mockResolvedValue(serverUrl);
|
|
|
|
const error = await handleReconnect(serverUrl);
|
|
|
|
expect(error).toBeUndefined();
|
|
expect(entry).toHaveBeenCalled();
|
|
expect(handleEntryAfterLoadNavigation).toHaveBeenCalled();
|
|
expect(setLastFullSync).toHaveBeenCalled();
|
|
expect(loadConfigAndCalls).toHaveBeenCalled();
|
|
expect(deferredAppEntryActions).toHaveBeenCalled();
|
|
expect(openAllUnreadChannels).toHaveBeenCalled();
|
|
expect(dataRetentionCleanup).toHaveBeenCalled();
|
|
expect(expiredBoRPostCleanup).toHaveBeenCalled();
|
|
expect(AppsManager.refreshAppBindings).toHaveBeenCalled();
|
|
expect(handlePlaybookReconnect).toHaveBeenCalledWith(serverUrl);
|
|
});
|
|
|
|
it('should fetch posts for channel screen', async () => {
|
|
jest.mocked(NavigationStore.getScreensInStack).mockReturnValue(['Channel']);
|
|
await handleReconnect(serverUrl);
|
|
|
|
expect(fetchPostsForChannel).toHaveBeenCalledWith(serverUrl, currentChannelId, false, false, 'WebSocket Reconnect');
|
|
expect(markChannelAsRead).toHaveBeenCalledWith(serverUrl, currentChannelId, false, 'WebSocket Reconnect');
|
|
expect(markChannelAsViewed).toHaveBeenCalledWith(serverUrl, currentChannelId, true);
|
|
});
|
|
|
|
it('should fetch thread posts when CRT enabled', async () => {
|
|
const threadId = 'thread-id';
|
|
const lastPost = TestHelper.fakePostModel({id: 'post-id', createAt: 123});
|
|
|
|
jest.mocked(NavigationStore.getScreensInStack).mockReturnValue(['Thread']);
|
|
|
|
jest.mocked(getIsCRTEnabled).mockResolvedValue(true);
|
|
jest.mocked(EphemeralStore.getCurrentThreadId).mockReturnValue(threadId);
|
|
jest.mocked(getLastPostInThread).mockResolvedValue(lastPost);
|
|
|
|
await handleReconnect(serverUrl);
|
|
|
|
expect(fetchPostThread).toHaveBeenCalledWith(
|
|
serverUrl,
|
|
threadId,
|
|
{
|
|
fromCreateAt: lastPost.createAt,
|
|
fromPost: lastPost.id,
|
|
direction: 'down',
|
|
},
|
|
false,
|
|
'WebSocket Reconnect',
|
|
);
|
|
});
|
|
|
|
it('should handle notification tapped state', async () => {
|
|
jest.mocked(NavigationStore.getScreensInStack).mockReturnValue(['Channel']);
|
|
|
|
jest.mocked(EphemeralStore.wasNotificationTapped).mockReturnValue(true);
|
|
|
|
await handleReconnect(serverUrl);
|
|
|
|
expect(markChannelAsViewed).not.toHaveBeenCalled();
|
|
expect(EphemeralStore.setNotificationTapped).toHaveBeenCalledWith(false);
|
|
});
|
|
|
|
it('should handle error in entry data', async () => {
|
|
jest.mocked(entry).mockResolvedValue({error: new Error('entry error')});
|
|
|
|
const result = await handleReconnect(serverUrl);
|
|
|
|
expect(result).toBeInstanceOf(Error);
|
|
expect((result as Error).message).toBe('entry error');
|
|
});
|
|
});
|
|
});
|