[FIX] App forgetting workspace when server is not finished added (#2798)
* [FIX] App forgetting workspace * Added e2e tests * Update login.js * Update logout.js * Reverted changes on login and share, updated init * Update 08-persistantworkspace.spec.js * Revert unnecessary changes * Revert line change * Update share.js * Tweak tests * Use wm shorthand * Remove irrelevant calls to RocketChat.TOKEN_KEY Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
b2c200a5d1
commit
1ff6530a19
|
@ -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 }) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
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';
|
||||
|
@ -25,16 +25,26 @@ 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(RocketChat.CURRENT_SERVER);
|
||||
let userId = yield UserPreferences.getStringAsync(`${ RocketChat.TOKEN_KEY }-${ server }`);
|
||||
|
||||
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.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;
|
||||
|
|
|
@ -126,7 +126,6 @@ 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);
|
||||
|
||||
RocketChat.getUserPresence(user.id);
|
||||
|
||||
|
|
|
@ -143,9 +143,9 @@ class Root extends React.Component {
|
|||
init = async() => {
|
||||
UserPreferences.getMapAsync(THEME_PREFERENCES_KEY).then(this.setTheme);
|
||||
|
||||
const [currentServer, token] = await Promise.all([UserPreferences.getStringAsync(RocketChat.CURRENT_SERVER), UserPreferences.getStringAsync(RocketChat.TOKEN_KEY)]);
|
||||
const currentServer = await UserPreferences.getStringAsync(RocketChat.CURRENT_SERVER);
|
||||
|
||||
if (currentServer && token) {
|
||||
if (currentServer) {
|
||||
await localAuthenticate(currentServer);
|
||||
this.setState({ root: 'inside' });
|
||||
await RocketChat.shareExtensionInit(currentServer);
|
||||
|
|
|
@ -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}
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
);
|
||||
|
|
|
@ -12,6 +12,12 @@ const checkServer = async(server) => {
|
|||
await element(by.id('sidebar-close-drawer')).tap();
|
||||
}
|
||||
|
||||
const reopenAndCheckServer = async(server) => {
|
||||
await device.launchApp({ permissions: { notifications: 'YES' } });
|
||||
await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(6000);
|
||||
await checkServer(server);
|
||||
}
|
||||
|
||||
describe('Change server', () => {
|
||||
before(async() => {
|
||||
await device.launchApp({ permissions: { notifications: 'YES' }, delete: true });
|
||||
|
@ -20,20 +26,22 @@ describe('Change server', () => {
|
|||
await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(10000);
|
||||
});
|
||||
|
||||
it('should be logged in main server', async() => {
|
||||
await checkServer(data.server);
|
||||
})
|
||||
|
||||
it('should add server and create new user', async() => {
|
||||
await sleep(5000);
|
||||
it('should login to server, add new server, close the app, open the app and show previous logged server', async() => {
|
||||
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();
|
||||
|
||||
// TODO: refactor
|
||||
await waitFor(element(by.id('new-server-view'))).toBeVisible().withTimeout(60000);
|
||||
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 reopenAndCheckServer(data.server);
|
||||
});
|
||||
|
||||
it('should add server and create new user', async() => {
|
||||
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-${ data.alternateServer }`)).tap();
|
||||
await waitFor(element(by.id('workspace-view'))).toBeVisible().withTimeout(60000);
|
||||
await element(by.id('workspace-view-register')).tap();
|
||||
await waitFor(element(by.id('register-view'))).toBeVisible().withTimeout(2000);
|
||||
|
@ -46,18 +54,24 @@ describe('Change server', () => {
|
|||
await element(by.id('register-view-submit')).tap();
|
||||
await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(60000);
|
||||
|
||||
// For a sanity test, to make sure roomslist is showing correct rooms
|
||||
// app CANNOT show public room created on previous tests
|
||||
// await waitFor(element(by.id(`rooms-list-view-item-public${ data.random }`))).toBeNotVisible().withTimeout(60000);
|
||||
// await expect(element(by.id(`rooms-list-view-item-public${ data.random }`))).toBeNotVisible();
|
||||
await waitFor(element(by.id(`rooms-list-view-item-${ data.groups.private.name }`))).toBeNotVisible().withTimeout(60000);
|
||||
await checkServer(data.alternateServer);
|
||||
});
|
||||
|
||||
it('should change back', async() => {
|
||||
it('should reopen the app and show alternate server', async() => {
|
||||
await reopenAndCheckServer(data.alternateServer);
|
||||
});
|
||||
|
||||
it('should change back to main server', async() => {
|
||||
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-${ data.server }`)).tap();
|
||||
await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(10000);
|
||||
await waitFor(element(by.id(`rooms-list-view-item-${ data.groups.private.name }`))).toBeVisible().withTimeout(60000);
|
||||
await checkServer(data.server);
|
||||
});
|
||||
|
||||
it('should reopen the app and show main server', async() => {
|
||||
await reopenAndCheckServer(data.server);
|
||||
})
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue