From 9c4cb86deaa2c68fc4ab27e05e1af6bd857ec4a6 Mon Sep 17 00:00:00 2001 From: Jonathan Ruddell Date: Mon, 30 Mar 2020 18:54:10 -0400 Subject: [PATCH] fix e2e tests on iOS, goBack method was incorrectly replaced polish websocket code to pass lint, remove deprecated methods --- boilerplate/app/modules/chat/chat-screen.js | 25 ++++++++----------- .../app/modules/chat/chat-screen.styles.js | 5 ++-- .../shared/websockets/websocket.service.js | 17 ++++++------- boilerplate/e2e/utils.js | 4 +-- test/scripts/generate-ignite-jhipster-app.sh | 1 + 5 files changed, 25 insertions(+), 27 deletions(-) diff --git a/boilerplate/app/modules/chat/chat-screen.js b/boilerplate/app/modules/chat/chat-screen.js index c56f609d9..59d662a12 100644 --- a/boilerplate/app/modules/chat/chat-screen.js +++ b/boilerplate/app/modules/chat/chat-screen.js @@ -15,7 +15,6 @@ class ChatScreen extends React.PureComponent { super(props) this.state = { message: '', - dataObjects: props.chat } } @@ -28,7 +27,7 @@ class ChatScreen extends React.PureComponent { ) } - componentWillMount () { + componentDidMount () { WebsocketService.connect() WebsocketService.subscribeToChat() } @@ -37,14 +36,8 @@ class ChatScreen extends React.PureComponent { WebsocketService.disconnect() } - componentWillReceiveProps (newProps) { - if (newProps.chat) { - this.setState({ - dataObjects: newProps.chat - }, () => { - this.refs['chatList'].scrollToEnd() - }) - } + componentDidUpdate(prevProps) { + this.chatList.scrollToEnd() } updateMessage = (message) => { @@ -71,10 +64,12 @@ class ChatScreen extends React.PureComponent { { + this.chatList = c + }} style={styles.list} contentContainerStyle={styles.listContent} - data={this.state.dataObjects} + data={this.props.chat} renderItem={this.renderRow} keyExtractor={this.keyExtractor} initialNumToRender={this.oneScreensWorth} @@ -82,7 +77,9 @@ class ChatScreen extends React.PureComponent { /> { + this.messageText = c + }} placeholder='Type a message...' placeholderTextColor={Colors.snow} underlineColorAndroid='transparent' @@ -96,7 +93,7 @@ class ChatScreen extends React.PureComponent { selectionColor={Colors.snow} testID='chatScreenInput' /> - + diff --git a/boilerplate/app/modules/chat/chat-screen.styles.js b/boilerplate/app/modules/chat/chat-screen.styles.js index e87a5cd3f..5f7d2853e 100644 --- a/boilerplate/app/modules/chat/chat-screen.styles.js +++ b/boilerplate/app/modules/chat/chat-screen.styles.js @@ -9,6 +9,9 @@ export default StyleSheet.create({ flexDirection: 'column', flex: 1 }, + button: { + flex: 1 + }, row: { backgroundColor: Colors.fire, marginVertical: 1, @@ -33,8 +36,6 @@ export default StyleSheet.create({ }, list: { flex: 1 - // todo replace with flex styling - // height: Metrics.screenHeight - ((Platform.OS === 'ios') ? 110 : 130) }, listContent: { left: 0, diff --git a/boilerplate/app/shared/websockets/websocket.service.js b/boilerplate/app/shared/websockets/websocket.service.js index 96ed76fd8..51fd5d6e9 100644 --- a/boilerplate/app/shared/websockets/websocket.service.js +++ b/boilerplate/app/shared/websockets/websocket.service.js @@ -8,7 +8,6 @@ import { processWebsocketMessage } from './websocket.sagas' const webstomp = require('stompjs') let em -let accessToken let connection = createConnection() let alreadyConnectedOnce = false let connected = false @@ -64,9 +63,8 @@ function connect () { if (!alreadyConnectedOnce) { if (connectedPromise === null) connection = createConnection() var url = AppConfig.apiUrl + 'websocket/chat' - if (accessToken) { - token = accessToken - url += '?access_token=' + accessToken + if (token) { + url += '?access_token=' + token } socket = new SockJS(url) stompClient = webstomp.over(socket) @@ -121,8 +119,9 @@ function onMessage (subscription, fullMessage) { let msg = null try { msg = JSON.parse(fullMessage.body) - } catch (fullMessage) { + } catch (e) { console.tron.error(`Error parsing : ${fullMessage}`) + console.tron.error(e) } if (msg) { return em({ subscription, msg }) @@ -134,8 +133,8 @@ function getToken () { return token } -function setToken (token) { - accessToken = token +function setToken (jwtToken) { + token = jwtToken if (connected) { disconnect() connect() @@ -150,8 +149,8 @@ function getWsSessionId () { return wsSessionId } -function setWsSessionId (socket) { - const splitUrl = socket._transport.url.split('/') +function setWsSessionId (socketObject) { + const splitUrl = socketObject._transport.url.split('/') wsSessionId = splitUrl[5] console.tron.log(`Set WS Session ID to ${wsSessionId}`) } diff --git a/boilerplate/e2e/utils.js b/boilerplate/e2e/utils.js index c3e7a4709..3b971e03f 100644 --- a/boilerplate/e2e/utils.js +++ b/boilerplate/e2e/utils.js @@ -19,14 +19,14 @@ const logout = async () => { const goBack = async () => { if (device.getPlatform() === 'ios') { - await Utils.goBack(); + await element(by.type('_UIBackButtonContainerView')).tap() } else { await device.pressBack(); } } const scrollTo = async (fieldId, listId) => { - await waitFor(element(by.id(fieldId))).toBeVisible().whileElement(by.id(listId)).scroll(50, 'down', 0, 0) + await waitFor(element(by.id(fieldId))).toBeVisible().whileElement(by.id(listId)).scroll(50, 'down', 0.01, 0.01) } module.exports = { diff --git a/test/scripts/generate-ignite-jhipster-app.sh b/test/scripts/generate-ignite-jhipster-app.sh index 68eb877e4..aeca625d3 100755 --- a/test/scripts/generate-ignite-jhipster-app.sh +++ b/test/scripts/generate-ignite-jhipster-app.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -e +set -x; # switch to the directory containing the jhipster app folder cd ../