diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index d559ab726..262983923 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -178,13 +178,16 @@ const RocketChat = { checkAndReopen() { return this?.sdk?.checkAndReopen(); }, + disconnect() { + this.sdk?.disconnect?.(); + this.sdk = null; + }, connect({ server, user, logoutOnError = false }) { return new Promise((resolve) => { if (this?.sdk?.client?.host === server) { return resolve(); } else { - this.sdk?.disconnect?.(); - this.sdk = null; + this.disconnect(); database.setActiveDB(server); } reduxStore.dispatch(connectRequest()); diff --git a/app/presentation/RoomItem/Actions.js b/app/presentation/RoomItem/Actions.js index b24fd0016..4a557d20e 100644 --- a/app/presentation/RoomItem/Actions.js +++ b/app/presentation/RoomItem/Actions.js @@ -3,12 +3,12 @@ import { Animated, View, Text } from 'react-native'; import { RectButton } from 'react-native-gesture-handler'; import PropTypes from 'prop-types'; -import I18n from '../../i18n'; +import I18n, { isRTL } from '../../i18n'; import styles, { ACTION_WIDTH, LONG_SWIPE } from './styles'; import { CustomIcon } from '../../lib/Icons'; import { themes } from '../../constants/colors'; -const reverse = new Animated.Value(I18n.isRTL ? -1 : 1); +const reverse = new Animated.Value(isRTL() ? -1 : 1); export const LeftActions = React.memo(({ theme, transX, isRead, width, onToggleReadPress diff --git a/app/presentation/RoomItem/Touchable.js b/app/presentation/RoomItem/Touchable.js index 37b45639d..defb5e105 100644 --- a/app/presentation/RoomItem/Touchable.js +++ b/app/presentation/RoomItem/Touchable.js @@ -9,7 +9,7 @@ import { SMALL_SWIPE, LONG_SWIPE } from './styles'; -import I18n from '../../i18n'; +import { isRTL } from '../../i18n'; import { themes } from '../../constants/colors'; import { LeftActions, RightActions } from './Actions'; @@ -35,7 +35,7 @@ class Touchable extends React.Component { super(props); this.dragX = new Animated.Value(0); this.rowOffSet = new Animated.Value(0); - this.reverse = new Animated.Value(I18n.isRTL ? -1 : 1); + this.reverse = new Animated.Value(isRTL() ? -1 : 1); this.transX = Animated.add( this.rowOffSet, this.dragX @@ -69,7 +69,7 @@ class Touchable extends React.Component { if (rowState === 0) { // if no option is opened if (translationX > 0 && translationX < LONG_SWIPE) { // open leading option if he swipe right but not enough to trigger action - if (I18n.isRTL) { + if (isRTL()) { toValue = 2 * ACTION_WIDTH; } else { toValue = ACTION_WIDTH; @@ -77,14 +77,14 @@ class Touchable extends React.Component { this.setState({ rowState: -1 }); } else if (translationX >= LONG_SWIPE) { toValue = 0; - if (I18n.isRTL) { + if (isRTL()) { this.hideChannel(); } else { this.toggleRead(); } } else if (translationX < 0 && translationX > -LONG_SWIPE) { // open trailing option if he swipe left - if (I18n.isRTL) { + if (isRTL()) { toValue = -ACTION_WIDTH; } else { toValue = -2 * ACTION_WIDTH; @@ -93,7 +93,7 @@ class Touchable extends React.Component { } else if (translationX <= -LONG_SWIPE) { toValue = 0; this.setState({ rowState: 0 }); - if (I18n.isRTL) { + if (isRTL()) { this.toggleRead(); } else { this.hideChannel(); @@ -110,12 +110,12 @@ class Touchable extends React.Component { } else if (this._value > LONG_SWIPE) { toValue = 0; this.setState({ rowState: 0 }); - if (I18n.isRTL) { + if (isRTL()) { this.hideChannel(); } else { this.toggleRead(); } - } else if (I18n.isRTL) { + } else if (isRTL()) { toValue = 2 * ACTION_WIDTH; } else { toValue = ACTION_WIDTH; @@ -129,12 +129,12 @@ class Touchable extends React.Component { } else if (this._value < -LONG_SWIPE) { toValue = 0; this.setState({ rowState: 0 }); - if (I18n.isRTL) { + if (isRTL()) { this.toggleRead(); } else { this.hideChannel(); } - } else if (I18n.isRTL) { + } else if (isRTL()) { toValue = -ACTION_WIDTH; } else { toValue = -2 * ACTION_WIDTH; diff --git a/app/views/SettingsView/index.js b/app/views/SettingsView/index.js index b67c7f1ea..55687cf0f 100644 --- a/app/views/SettingsView/index.js +++ b/app/views/SettingsView/index.js @@ -109,7 +109,8 @@ class SettingsView extends React.Component { await RocketChat.clearCache({ server }); await FastImage.clearMemoryCache(); await FastImage.clearDiskCache(); - selectServerRequest(server, null, true); + RocketChat.disconnect(); + selectServerRequest(server); } }); } @@ -285,7 +286,7 @@ class SettingsView extends React.Component { { await waitFor(element(by.id('sidebar-settings'))).toBeVisible().withTimeout(2000); await element(by.id('sidebar-settings')).tap(); await waitFor(element(by.id('settings-view'))).toBeVisible().withTimeout(2000); - }); describe('Render', async() => { @@ -63,7 +62,7 @@ describe('Settings screen', () => { }); }); - describe('Language', async() => { + describe('Usage', async() => { it('should navigate to language view', async() => { await element(by.id('settings-view-language')).tap(); await waitFor(element(by.id('language-view'))).toBeVisible().withTimeout(60000); @@ -74,27 +73,18 @@ describe('Settings screen', () => { await expect(element(by.id('language-view-pt-BR'))).toExist(); await expect(element(by.id('language-view-pt-PT'))).toExist(); await expect(element(by.id('language-view-ru'))).toExist(); + await tapBack(); }); - - // it('should navigate to change language', async() => { - // await expect(element(by.id('language-view-zh-CN'))).toExist(); - // await element(by.id('language-view-zh-CN')).tap() - // await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(60000); - // await expect(element(by.id('rooms-list-view'))).toBeVisible(); - // await element(by.id('rooms-list-view-sidebar')).tap(); - // await waitFor(element(by.id('sidebar-view'))).toBeVisible().withTimeout(2000); - // await waitFor(element(by.text('设置'))).toBeVisible().withTimeout(2000); - // await element(by.text('设置')).tap(); - // await waitFor(element(by.id('settings-view'))).toBeVisible().withTimeout(2000); - // await element(by.id('settings-view-language')).tap(); - // await element(by.id('language-view-en')).tap(); - // await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(60000); - // await expect(element(by.id('rooms-list-view'))).toBeVisible(); - // await element(by.id('rooms-list-view-sidebar')).tap(); - // await waitFor(element(by.id('sidebar-view'))).toBeVisible().withTimeout(2000); - // await expect(element(by.text('Settings'))).toBeVisible(); - // await element(by.text('Settings')).tap(); - // await expect(element(by.id('settings-view'))).toBeVisible(); - // }); + + it('should tap clear cache and navigate to roomslistview', async() => { + await waitFor(element(by.id('settings-view'))).toBeVisible().withTimeout(2000); + await element(by.id('settings-view-clear-cache')).tap(); + await waitFor(element(by.text('This will clear all your offline data.'))).toExist().withTimeout(2000); + await element(by.label('Clear').and(by.type('_UIAlertControllerActionView'))).tap(); + await waitFor(element(by.id('rooms-list-view'))).toBeVisible().withTimeout(5000); + // Database was cleared, so the room shouldn't be there anymore while it's fetched again from the server + await waitFor(element(by.id(`rooms-list-view-item-${ data.groups.private.name }`))).toNotExist().withTimeout(10000); + await waitFor(element(by.id(`rooms-list-view-item-${ data.groups.private.name }`))).toExist().withTimeout(10000); + }) }); });