Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
1 change: 0 additions & 1 deletion app/lib/methods/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ async function removeServerData({ server }) {

async function removeCurrentServer() {
await UserPreferences.removeItem(RocketChat.CURRENT_SERVER);
await UserPreferences.removeItem(RocketChat.TOKEN_KEY);
}

async function removeServerDatabase({ server }) {
Expand Down
39 changes: 28 additions & 11 deletions app/sagas/init.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { put, takeLatest, all } from 'redux-saga/effects';
import { put, takeLatest } from 'redux-saga/effects';
import RNBootSplash from 'react-native-bootsplash';

import UserPreferences from '../lib/userPreferences';
import { selectServerRequest } from '../actions/server';
import { setAllPreferences } from '../actions/sortPreferences';
import { toggleCrashReport, toggleAnalyticsEvents } from '../actions/crashReport';
import {
toggleCrashReport,
toggleAnalyticsEvents
} from '../actions/crashReport';
import { APP } from '../actions/actionsTypes';
import RocketChat from '../lib/rocketchat';
import log from '../utils/log';
Expand All @@ -25,16 +28,30 @@ export const initLocalSettings = function* initLocalSettings() {

const restore = function* restore() {
try {
const { token, server } = yield all({
token: UserPreferences.getStringAsync(RocketChat.TOKEN_KEY),
server: UserPreferences.getStringAsync(RocketChat.CURRENT_SERVER)
});
const server = yield UserPreferences.getStringAsync('currentServer');
Comment thread
gerzonc marked this conversation as resolved.
Outdated
let userId = server
Comment thread
gerzonc marked this conversation as resolved.
Outdated
? yield UserPreferences.getStringAsync(
`${ RocketChat.TOKEN_KEY }-${ server }`
)
: null;

if (!token || !server) {
yield all([
UserPreferences.removeItem(RocketChat.TOKEN_KEY),
UserPreferences.removeItem(RocketChat.CURRENT_SERVER)
]);
if (!server) {
yield put(appStart({ root: ROOT_OUTSIDE }));
} else if (!userId) {
const serversDB = database.servers;
const serversCollection = serversDB.collections.get('servers');
const servers = yield serversCollection.query().fetch();

// Check if there're other logged in servers and picks first one
if (servers.length > 0) {
for (let i = 0; i < servers.length; i += 1) {
const newServer = servers[i].id;
userId = yield UserPreferences.getStringAsync(`${ RocketChat.TOKEN_KEY }-${ newServer }`);
if (userId) {
return yield put(selectServerRequest(newServer));
}
}
}
yield put(appStart({ root: ROOT_OUTSIDE }));
} else {
const serversDB = database.servers;
Expand Down
4 changes: 2 additions & 2 deletions app/sagas/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ const fetchRooms = function* fetchRooms() {
const handleLoginSuccess = function* handleLoginSuccess({ user }) {
try {
const adding = yield select(state => state.server.adding);
yield UserPreferences.setStringAsync(RocketChat.TOKEN_KEY, user.token);

Comment thread
gerzonc marked this conversation as resolved.

RocketChat.getUserPresence(user.id);

const server = yield select(getServer);
yield fork(fetchRooms);
yield fork(fetchRooms, { server });
Comment thread
gerzonc marked this conversation as resolved.
Outdated
yield fork(fetchPermissions);
yield fork(fetchCustomEmojis);
yield fork(fetchRoles);
Expand Down
6 changes: 3 additions & 3 deletions app/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ class Root extends React.Component {

init = async() => {
UserPreferences.getMapAsync(THEME_PREFERENCES_KEY).then(this.setTheme);
const currentServer = await UserPreferences.getStringAsync(RocketChat.CURRENT_SERVER);
const userId = await UserPreferences.getStringAsync(`${ RocketChat.TOKEN_KEY }-${ currentServer }`);

const [currentServer, token] = await Promise.all([UserPreferences.getStringAsync(RocketChat.CURRENT_SERVER), UserPreferences.getStringAsync(RocketChat.TOKEN_KEY)]);

if (currentServer && token) {
if (currentServer && userId) {
await localAuthenticate(currentServer);
this.setState({ root: 'inside' });
await RocketChat.shareExtensionInit(currentServer);
Expand Down
2 changes: 1 addition & 1 deletion app/views/RoomsListView/Header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const Header = React.memo(({
size={18}
/>
</View>
{subtitle ? <Text style={[styles.subtitle, { color: themes[theme].auxiliaryText, fontSize: subTitleFontSize }]} numberOfLines={1}>{subtitle}</Text> : null}
{subtitle ? <Text testID='rooms-list-header-server-subtitle' style={[styles.subtitle, { color: themes[theme].auxiliaryText, fontSize: subTitleFontSize }]} numberOfLines={1}>{subtitle}</Text> : null}
Comment thread
gerzonc marked this conversation as resolved.
</TouchableOpacity>
</View>
);
Expand Down
86 changes: 86 additions & 0 deletions e2e/tests/onboarding/08-persistantworkspace.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const {
expect, element, by, waitFor
} = require('detox');
const { navigateToLogin, tapBack, sleep } = require('../../helpers/app');
const data = require('../../data');

describe('Persistant workspace', () => {
describe('From Onboarding', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true, delete: true });

});

it('should select a valid server, close the app and open again', async() => {
await waitFor(element(by.id('onboarding-view'))).toBeVisible().withTimeout(2000);
await element(by.id('join-workspace')).tap();
await waitFor(element(by.id('new-server-view'))).toBeVisible().withTimeout(6000);
await element(by.id('new-server-view-input')).replaceText(data.server);
await element(by.id('new-server-view-button')).tap();
await waitFor(element(by.id('workspace-view'))).toBeVisible().withTimeout(6000);
await device.terminateApp();
await device.launchApp({ permissions: { notifications: 'YES' }});
await waitFor(element(by.id('onboarding-view'))).toBeVisible().withTimeout(2000);
});
});

describe('From Current Server', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true, delete: true });
await navigateToLogin();
});

it('should login to server, add new server, close the app, open the app and show previous logged server', async() => {
await element(by.id('login-view-email')).replaceText(data.users.regular.username);
await element(by.id('login-view-password')).replaceText(data.users.regular.password);
await element(by.id('login-view-submit')).tap();
await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(6000);

await element(by.id('rooms-list-header-server-dropdown-button')).tap();
await waitFor(element(by.id('rooms-list-header-server-dropdown'))).toBeVisible().withTimeout(5000);
await element(by.id('rooms-list-header-server-add')).tap();

await waitFor(element(by.id('new-server-view'))).toBeVisible().withTimeout(6000);
await element(by.id('new-server-view-input')).replaceText(data.alternateServer);
await element(by.id('new-server-view-button')).tap();
await waitFor(element(by.id('workspace-view'))).toBeVisible().withTimeout(6000);
await device.terminateApp();
await device.launchApp({ permissions: { notifications: 'YES' } });
await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(6000);
});
});

describe('From New Server', () => {
before(async() => {
await device.launchApp({ permissions: { notifications: 'YES' }, newInstance: true, delete: true });
await navigateToLogin();
});

it('should login to server, add new server, login to new server, close the app, open the app and show latest logged server', async() => {
await element(by.id('login-view-email')).replaceText(data.users.regular.username);
await element(by.id('login-view-password')).replaceText(data.users.regular.password);
await element(by.id('login-view-submit')).tap();
await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(6000);

await element(by.id('rooms-list-header-server-dropdown-button')).tap();
await waitFor(element(by.id('rooms-list-header-server-dropdown'))).toBeVisible().withTimeout(5000);
await element(by.id('rooms-list-header-server-add')).tap();

await waitFor(element(by.id('new-server-view'))).toBeVisible().withTimeout(6000);
await element(by.id('new-server-view-input')).replaceText(data.alternateServer);
await element(by.id('new-server-view-button')).tap();
await waitFor(element(by.id('workspace-view'))).toBeVisible().withTimeout(6000);

await element(by.id('workspace-view-login')).tap();
await waitFor(element(by.id('login-view'))).toBeVisible().withTimeout(2000);
await expect(element(by.id('login-view'))).toBeVisible();
await element(by.id('login-view-email')).replaceText('userfourkjadssldkjaasdf');
await element(by.id('login-view-password')).replaceText('123');
await element(by.id('login-view-submit')).tap();
await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(6000);
await device.terminateApp();
await device.launchApp({ permissions: { notifications: 'YES' } });
await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(6000);
});
});
});