1import React from 'react'; 2import { View, Text, Pressable } from 'react-native'; 3 4import * as Updates from '../'; 5 6const { checkForUpdateAsync, fetchUpdateAsync, useUpdates } = Updates; 7 8const UseUpdatesTestApp = () => { 9 const { 10 currentlyRunning, 11 availableUpdate, 12 downloadedUpdate, 13 isUpdateAvailable, 14 isUpdatePending, 15 checkError, 16 downloadError, 17 initializationError, 18 lastCheckForUpdateTimeSinceRestart, 19 } = useUpdates(); 20 return ( 21 <View> 22 {/* Currently running info */} 23 <Text testID="currentlyRunning_updateId">{currentlyRunning.updateId}</Text> 24 <Text testID="currentlyRunning_channel">{currentlyRunning.channel}</Text> 25 <Text testID="currentlyRunning_createdAt"> 26 {currentlyRunning?.createdAt ? currentlyRunning?.createdAt.toISOString() : ''} 27 </Text> 28 {/* Last time there was a check for update */} 29 <Text testID="lastCheckForUpdateTime"> 30 {lastCheckForUpdateTimeSinceRestart?.toISOString().substring(0, 19) || ''} 31 </Text> 32 {/* Available update, if one is present */} 33 <Text testID="availableUpdate_updateId">{availableUpdate?.updateId || ''}</Text> 34 {/* Downloaded update, if one is present */} 35 <Text testID="downloadedUpdate_updateId">{downloadedUpdate?.updateId || ''}</Text> 36 {/* Booleans */} 37 <Text testID="isUpdateAvailable">{`${isUpdateAvailable}`}</Text> 38 <Text testID="isUpdatePending">{`${isUpdatePending}`}</Text> 39 <Text testID="isRollback">{`${ 40 availableUpdate?.type === Updates.UpdateInfoType.ROLLBACK 41 }`}</Text> 42 <Text testID="rollbackTime">{`${ 43 availableUpdate?.createdAt.toISOString().substring(0, 19) || '' 44 }`}</Text> 45 {/* Errors, if they occur */} 46 {checkError ? <Text testID="checkError">{checkError.message}</Text> : null} 47 {downloadError ? <Text testID="downloadError">{downloadError.message}</Text> : null} 48 {initializationError ? ( 49 <Text testID="initializationError">{initializationError.message}</Text> 50 ) : null} 51 {/* Buttons for test code to invoke methods */} 52 <Pressable testID="checkForUpdate" onPress={() => checkForUpdateAsync()} /> 53 <Pressable testID="downloadUpdate" onPress={() => fetchUpdateAsync()} /> 54 </View> 55 ); 56}; 57 58export default UseUpdatesTestApp; 59