Skip to content

Commit

Permalink
fix e2e tests
Browse files Browse the repository at this point in the history
on iOS, goBack method was incorrectly replaced
polish websocket code to pass lint, remove deprecated methods
  • Loading branch information
ruddell committed Apr 13, 2020
1 parent 14de03d commit 9c4cb86
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 27 deletions.
25 changes: 11 additions & 14 deletions boilerplate/app/modules/chat/chat-screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class ChatScreen extends React.PureComponent {
super(props)
this.state = {
message: '',
dataObjects: props.chat
}
}

Expand All @@ -28,7 +27,7 @@ class ChatScreen extends React.PureComponent {
)
}

componentWillMount () {
componentDidMount () {
WebsocketService.connect()
WebsocketService.subscribeToChat()
}
Expand All @@ -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) => {
Expand All @@ -71,18 +64,22 @@ class ChatScreen extends React.PureComponent {
<View style={styles.container} testID='chatScreen'>
<KeyboardAwareScrollView style={styles.scrollView} scrollEnabled={false}>
<FlatList
ref='chatList'
ref={(c) => {
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}
testID='chatScreenFlatList'
/>
<View style={styles.inputContainer}>
<TextInput
ref='messageText'
ref={(c) => {
this.messageText = c
}}
placeholder='Type a message...'
placeholderTextColor={Colors.snow}
underlineColorAndroid='transparent'
Expand All @@ -96,7 +93,7 @@ class ChatScreen extends React.PureComponent {
selectionColor={Colors.snow}
testID='chatScreenInput'
/>
<RoundedButton style={{ flex: 1 }} onPress={this.sendMessage} text={'Send'} testID='chatScreenSendButton' />
<RoundedButton style={styles.button} onPress={this.sendMessage} text={'Send'} testID='chatScreenSendButton' />
</View>
</KeyboardAwareScrollView>
</View>
Expand Down
5 changes: 3 additions & 2 deletions boilerplate/app/modules/chat/chat-screen.styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export default StyleSheet.create({
flexDirection: 'column',
flex: 1
},
button: {
flex: 1
},
row: {
backgroundColor: Colors.fire,
marginVertical: 1,
Expand All @@ -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,
Expand Down
17 changes: 8 additions & 9 deletions boilerplate/app/shared/websockets/websocket.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 })
Expand All @@ -134,8 +133,8 @@ function getToken () {
return token
}

function setToken (token) {
accessToken = token
function setToken (jwtToken) {
token = jwtToken
if (connected) {
disconnect()
connect()
Expand All @@ -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}`)
}
Expand Down
4 changes: 2 additions & 2 deletions boilerplate/e2e/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions test/scripts/generate-ignite-jhipster-app.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
set -e
set -x;

# switch to the directory containing the jhipster app folder
cd ../
Expand Down

0 comments on commit 9c4cb86

Please sign in to comment.