Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions app/sagas/__tests__/shareExtension.sameWorkspace.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
jest.mock('~/lib/methods/userPreferences', () => ({
__esModule: true,
default: {
getString: jest.fn(),
getBool: jest.fn()
}
}));

jest.mock('~/lib/database/services/Server', () => ({
getServerById: jest.fn()
}));

jest.mock('~/lib/methods/helpers/localAuthentication', () => ({
localAuthenticate: jest.fn(),
UserCanceledError: class UserCanceledError extends Error {}
}));

jest.mock('~/lib/services/sdk', () => ({
__esModule: true,
default: {
host: null
}
}));

jest.mock('~/lib/methods/helpers/sslPinning', () => ({
applyServerCertificate: jest.fn(() => Promise.resolve()),
registerCertificates: jest.fn(() => Promise.resolve())
}));

jest.mock('~/lib/methods/migrateTokenKeysToServerScoped', () => ({
migrateTokenKeysToServerScoped: jest.fn(() => Promise.resolve())
}));

jest.mock('@react-native-async-storage/async-storage', () => ({
__esModule: true,
default: {
getItem: jest.fn(() => Promise.resolve(null)),
removeItem: jest.fn(() => Promise.resolve(null))
}
}));

jest.mock('~/lib/services/voip/resetVoipState', () => ({
resetVoipState: jest.fn()
}));

jest.mock('~/lib/services/connect', () => ({
connect: jest.fn(() => Promise.resolve()),
disconnect: jest.fn(),
loginOAuthOrSso: jest.fn()
}));

import { all, fork } from 'redux-saga/effects';

import { deepLinkingOpen } from '~/actions/deepLinking';
import { SERVER } from '~/actions/actionsTypes';
import { RootEnum } from '~/definitions';
import deepLinkingRoot from '../deepLinking';
import initRoot from '../init';
import selectServerRoot from '../selectServer';
import UserPreferences from '~/lib/methods/userPreferences';
import { getServerById } from '~/lib/database/services/Server';
import sdk from '~/lib/services/sdk';
import { localAuthenticate, UserCanceledError } from '~/lib/methods/helpers/localAuthentication';
import { cancelSagaTasks, createRecordingStore, flushSagaMicrotasks } from '~/lib/testUtils/sagaStore';
import type { PreloadedState } from '~/lib/testUtils/sagaStore';

const HOST = 'https://open.rocket.chat';

const shareAndSelectServerRoot = function* shareAndSelectServerRoot() {
yield all([fork(deepLinkingRoot), fork(initRoot), fork(selectServerRoot)]);
};

describe('share extension opened while connected to the same Workspace', () => {
beforeEach(() => {
jest.mocked(UserPreferences.getString).mockImplementation((key: string) => (key === 'currentServer' ? HOST : 'user-1'));
jest.mocked(getServerById).mockResolvedValue({ id: HOST, version: '7.0.0' } as any);
(sdk as any).host = HOST;
});

afterEach(() => {
cancelSagaTasks();
(sdk as any).host = null;
});

it('lands on the share extension root, not the Inside Stack', async () => {
const { store } = createRecordingStore(shareAndSelectServerRoot, { app: { root: RootEnum.ROOT_INSIDE } } as PreloadedState);

store.dispatch(deepLinkingOpen({ type: 'shareextension', mediaUris: 'file:///photo.jpg' } as any));
await flushSagaMicrotasks();

expect(store.getState().app.root).toBe(RootEnum.ROOT_SHARE_EXTENSION);
expect(store.getState().share.params).toMatchObject({ mediaUris: 'file:///photo.jpg' });
});

it('opens the Inside Stack after the share unlock is canceled and the app restarts', async () => {
jest.mocked(localAuthenticate).mockRejectedValueOnce(new UserCanceledError());
const { store, dispatchedActions } = createRecordingStore(shareAndSelectServerRoot, {
app: { root: RootEnum.ROOT_INSIDE }
} as PreloadedState);

store.dispatch(deepLinkingOpen({ type: 'shareextension', mediaUris: 'file:///photo.jpg' } as any));
await flushSagaMicrotasks();

expect(dispatchedActions.filter(action => action.type === SERVER.SELECT_REQUEST)).toEqual([
expect.objectContaining({ server: HOST, version: '7.0.0' })
]);
expect(store.getState().app.root).toBe(RootEnum.ROOT_INSIDE);
});
});
1 change: 1 addition & 0 deletions app/sagas/deepLinking.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ const handleShareExtension = function* handleOpen({ params }) {
}
// Unlock canceled or superseded by another lock request — restart the normal flow instead
// of leaving the share extension stuck on the loading root.
yield put(appStart({ root: RootEnum.ROOT_LOADING }));
yield put(appInit());
return;
}
Expand Down
6 changes: 2 additions & 4 deletions app/sagas/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { hasPermission } from '../lib/methods/helpers/helpers';
import { mediaSessionStore } from '../lib/services/voip/MediaSessionStore';
import { isInActiveVoipCall } from '../lib/services/voip/isInActiveVoipCall';
import { store as reduxStore } from '../lib/store/auxStore';
import { startInsideUnlessSharing } from './selectServer';

const getServer = state => state.server.server;
const loginWithPasswordCall = args => loginWithPassword(args);
Expand Down Expand Up @@ -385,10 +386,7 @@ const handleLoginSuccess = function* handleLoginSuccess({ user }) {
UserPreferences.setString(getUserTokenKey(server, user.id), user.token);
UserPreferences.setString(CURRENT_SERVER, server);
EventEmitter.emit('connected');
const currentRoot = yield select(state => state.app.root);
if (currentRoot !== RootEnum.ROOT_SHARE_EXTENSION && currentRoot !== RootEnum.ROOT_LOADING_SHARE_EXTENSION) {
yield put(appStart({ root: RootEnum.ROOT_INSIDE }));
}
yield* startInsideUnlessSharing();
const inviteLinkToken = yield select(state => state.inviteLinks.token);
if (inviteLinkToken) {
yield put(inviteLinksRequest(inviteLinkToken));
Expand Down
14 changes: 9 additions & 5 deletions app/sagas/selectServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,19 @@ const getServerInfoSaga = function* getServerInfoSaga({
}
};

export const startInsideUnlessSharing = function* startInsideUnlessSharing() {
const currentRoot = yield* appSelector(state => state.app.root);
if (currentRoot !== RootEnum.ROOT_SHARE_EXTENSION && currentRoot !== RootEnum.ROOT_LOADING_SHARE_EXTENSION) {
yield put(appStart({ root: RootEnum.ROOT_INSIDE }));
}
};

const handleSelectServer = function* handleSelectServer({ server, version, fetchVersion }: ISelectServerAction) {
try {
yield* call(applyServerCertificate, server);
if (sdk.host === server) {
applyBasicAuth(server);
yield put(appStart({ root: RootEnum.ROOT_INSIDE }));
yield* startInsideUnlessSharing();
yield put(selectServerCancel());
return;
}
Expand Down Expand Up @@ -188,10 +195,7 @@ const handleSelectServer = function* handleSelectServer({ server, version, fetch
yield put(clearSettings());
yield put(setUser(user));
yield connect({ server, logoutOnError: true });
const currentRoot = yield* appSelector(state => state.app.root);
if (currentRoot !== RootEnum.ROOT_SHARE_EXTENSION && currentRoot !== RootEnum.ROOT_LOADING_SHARE_EXTENSION) {
yield put(appStart({ root: RootEnum.ROOT_INSIDE }));
}
yield* startInsideUnlessSharing();
UserPreferences.setString(CURRENT_SERVER, server); // only set server after have a user
} else {
yield put(clearUser());
Expand Down
11 changes: 11 additions & 0 deletions e2e/tests/share-extension/share-extension-deeplink.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,14 @@ test('shares files into a room and handles a missing shared file', { tags: ['tes
await expect(missingFileToast).toBeVisible({ timeout: 15_000 });
await expect(screen.getByTestId('rooms-list-view')).toBeVisible({ timeout: LONG_TIMEOUT });
});

test('opens the share list when sharing while the app is running', { tags: ['test-6'], platforms: ['ios'] }, async fixtures => {
const { device } = fixtures;
const user = await createUser();

await loginWithDeepLink(fixtures, user);
const rocketChatApp = await device.foregroundApp();

await openPhotoShareSheet(fixtures);
await shareToRocketChat(fixtures, rocketChatApp.bundleId ?? rocketChatApp.name);
});
Loading