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      {/* Errors, if they occur */}
40      {checkError ? <Text testID="checkError">{checkError.message}</Text> : null}
41      {downloadError ? <Text testID="downloadError">{downloadError.message}</Text> : null}
42      {initializationError ? (
43        <Text testID="initializationError">{initializationError.message}</Text>
44      ) : null}
45      {/* Buttons for test code to invoke methods */}
46      <Pressable testID="checkForUpdate" onPress={() => checkForUpdateAsync()} />
47      <Pressable testID="downloadUpdate" onPress={() => fetchUpdateAsync()} />
48    </View>
49  );
50};
51
52export default UseUpdatesTestApp;
53