[REGRESSION] Clear local server cache not loading rooms (#3007)

* Fix clear cache

* Write e2e tests

* Fix lint

* Fix isRTL
This commit is contained in:
Diego Mello 2021-04-01 09:58:20 -03:00 committed by GitHub
parent ed181aa863
commit bb844e52fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 40 deletions

View File

@ -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());

View File

@ -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

View File

@ -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;

View File

@ -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 {
<List.Separator />
<List.Item
title='Clear_cache'
testID='settings-clear-cache'
testID='settings-view-clear-cache'
onPress={this.handleClearCache}
showActionIndicator
color={themes[theme].dangerColor}

View File

@ -1,7 +1,7 @@
const {
device, expect, element, by, waitFor
} = require('detox');
const { navigateToLogin, login } = require('../../helpers/app');
const { navigateToLogin, login, tapBack } = require('../../helpers/app');
const data = require('../../data');
@ -18,7 +18,6 @@ describe('Settings screen', () => {
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);
})
});
});