From 1c8fbc21efee6b784571cef57cd1a92c6ac15860 Mon Sep 17 00:00:00 2001 From: KonstantinKai Date: Tue, 21 Nov 2017 15:54:11 +0200 Subject: [PATCH] [expo] add tests --- types/expo/expo-tests.ts | 86 ----------------- types/expo/expo-tests.tsx | 191 ++++++++++++++++++++++++++++++++++++++ types/expo/index.d.ts | 75 +++++++-------- types/expo/tsconfig.json | 3 +- 4 files changed, 227 insertions(+), 128 deletions(-) delete mode 100644 types/expo/expo-tests.ts create mode 100644 types/expo/expo-tests.tsx diff --git a/types/expo/expo-tests.ts b/types/expo/expo-tests.ts deleted file mode 100644 index c8b7d5dc64..0000000000 --- a/types/expo/expo-tests.ts +++ /dev/null @@ -1,86 +0,0 @@ -import { - Accelerometer, - Amplitude, - Asset, - AuthSession, - Audio -} from 'expo'; - -Accelerometer.addListener((obj) => { - obj.x; - obj.y; - obj.z; -}); -Accelerometer.removeAllListeners(); -Accelerometer.setUpdateInterval(1000); - -Amplitude.initialize('key'); -Amplitude.setUserId('userId'); -Amplitude.setUserProperties({key: 1}); -Amplitude.clearUserProperties(); -Amplitude.logEvent('name'); -Amplitude.logEventWithProperties('event', {key: 'value'}); -Amplitude.setGroup('type', {key: 'value'}); - -const asset = Asset.fromModule(1); -asset.downloadAsync(); -Asset.loadAsync(1); -Asset.loadAsync([1, 2, 3]); -const asset1 = new Asset({ - uri: 'uri', - type: 'type', - name: 'name', - hash: 'hash', - width: 122, - height: 122 -}); - -const url = AuthSession.getRedirectUrl(); -AuthSession.dismiss(); -AuthSession.startAsync({ - authUrl: 'url1', - returnUrl: 'url2' -}).then(result => { - switch (result.type) { - case 'success': - result.event; - result.params; - break; - case 'error': - result.errorCode; - result.params; - result.event; - break; - case 'dismissed': - case 'cancel': - result.type; - break; - } -}); - -Audio.setAudioModeAsync({ - shouldDuckAndroid: false, - playsInSilentModeIOS: true, - interruptionModeIOS: 2, - interruptionModeAndroid: 1, - allowsRecordingIOS: true -}); -Audio.setIsEnabledAsync(true); -Audio.Sound.create('uri', { - volume: 0.5, - rate: 0.6 -}, null, true).then(result => { - const sound = result.sound; - const status = result.status; - - if (!status.isLoaded) { - status.error; - } else { - status.didJustFinish; - // etc. - } - - sound.getStatusAsync().then(_status => { - _status.isLoaded; - }); -}); diff --git a/types/expo/expo-tests.tsx b/types/expo/expo-tests.tsx new file mode 100644 index 0000000000..c2ac532ace --- /dev/null +++ b/types/expo/expo-tests.tsx @@ -0,0 +1,191 @@ +import { + Accelerometer, + Amplitude, + Asset, + AuthSession, + Audio, + AppLoading, + BarCodeScanner, + BlurViewProps, + BlurView, + Brightness, + Camera, + DocumentPicker, + Facebook, + FacebookAds, + FileSystem +} from 'expo'; + +Accelerometer.addListener((obj) => { + obj.x; + obj.y; + obj.z; +}); +Accelerometer.removeAllListeners(); +Accelerometer.setUpdateInterval(1000); + +Amplitude.initialize('key'); +Amplitude.setUserId('userId'); +Amplitude.setUserProperties({key: 1}); +Amplitude.clearUserProperties(); +Amplitude.logEvent('name'); +Amplitude.logEventWithProperties('event', {key: 'value'}); +Amplitude.setGroup('type', {key: 'value'}); + +const asset = Asset.fromModule(1); +asset.downloadAsync(); +Asset.loadAsync(1); +Asset.loadAsync([1, 2, 3]); +const asset1 = new Asset({ + uri: 'uri', + type: 'type', + name: 'name', + hash: 'hash', + width: 122, + height: 122 +}); + +const url = AuthSession.getRedirectUrl(); +AuthSession.dismiss(); +AuthSession.startAsync({ + authUrl: 'url1', + returnUrl: 'url2' +}).then(result => { + switch (result.type) { + case 'success': + result.event; + result.params; + break; + case 'error': + result.errorCode; + result.params; + result.event; + break; + case 'dismissed': + case 'cancel': + result.type; + break; + } +}); + +Audio.setAudioModeAsync({ + shouldDuckAndroid: false, + playsInSilentModeIOS: true, + interruptionModeIOS: 2, + interruptionModeAndroid: 1, + allowsRecordingIOS: true +}); +Audio.setIsEnabledAsync(true); +async () => { + const result = await Audio.Sound.create('uri', { + volume: 0.5, + rate: 0.6 + }, null, true); + + const sound = result.sound; + const status = result.status; + + if (!status.isLoaded) { + status.error; + } else { + status.didJustFinish; + // etc. + } + + const _status = await sound.getStatusAsync(); + await sound.loadAsync('uri'); +}; + +() => ( + Promise.resolve()} + onFinish={() => {}} + onError={(error) => console.log(error)} /> +); +() => ( + +); + +const barcodeReadCallback = () => {}; +() => ( + +); + +() => ( + +); + +async () => { + await Brightness.setBrightnessAsync(.6); + await Brightness.setSystemBrightnessAsync(.7); + const br1 = await Brightness.getBrightnessAsync(); + const br2 = await Brightness.getSystemBrightnessAsync(); +}; + +Camera.Constants.AutoFocus; +Camera.Constants.Type; +Camera.Constants.FlashMode; +Camera.Constants.WhiteBalance; +Camera.Constants.VideoQuality; +Camera.Constants.BarCodeType; +() => { + return( { + if (component) { + component.recordAsync(); + } + }} />); +}; + +async () => { + const result = await DocumentPicker.getDocumentAsync(); + + if (result.type === 'success') { + result.name; + result.uri; + result.size; + } +}; + +async () => { + const result = await Facebook.logInWithReadPermissionsAsync('appId'); + + if (result.type === 'success') { + result.expires; + result.token; + } +}; + +() => ( + {}} + onError={() => {}} /> +); + +async () => { + const info = await FileSystem.getInfoAsync('file'); + + info.exists; + info.isDirectory; + + if (info.exists) { + info.md5; + info.uri; + info.size; + info.modificationTime; + } + + const string = await FileSystem.readAsStringAsync('file'); + await FileSystem.writeAsStringAsync('file', 'content'); + await FileSystem.deleteAsync('file'); +}; diff --git a/types/expo/index.d.ts b/types/expo/index.d.ts index 5dfff55946..4e808c348a 100644 --- a/types/expo/index.d.ts +++ b/types/expo/index.d.ts @@ -24,6 +24,7 @@ export type Axis = number; export interface HashMap { [key: string]: any; } export type FloatFromZeroToOne = 0 | 0.1 | 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 | 0.9 | 1; export type BarCodeReadCallback = (params: { type: string; data: string; }) => void; +export type Md5 = string; /** * Accelerometer @@ -146,7 +147,7 @@ export interface PlaybackStatusToSet { export type Source = string | RequireSource | Asset; export class PlaybackObject { - loadAsync(source: Source, initialStatus: PlaybackStatusToSet, downloadFirst: boolean): Promise; + loadAsync(source: Source, initialStatus?: PlaybackStatusToSet, downloadFirst?: boolean): Promise; unloadAsync(): Promise; getStatusAsync(): Promise; setOnPlaybackStatusUpdate(onPlaybackStatusUpdate: (status: PlaybackStatus) => void): void; @@ -335,7 +336,7 @@ export type AppLoadingProperties = { } | { startAsync: null; onFinish: null; - onError: null; + onError?: null; }; export class AppLoading extends Component { } @@ -364,10 +365,10 @@ export class BlurView extends Component { } * Brightness */ export namespace Brightness { - function setBrightnessAsync(brightnessValue: number): Promise; - function getBrightnessAsync(): Promise; - function getSystemBrightnessAsync(): Promise; - function setSystemBrightnessAsync(brightnessValue: number): Promise; + function setBrightnessAsync(brightnessValue: FloatFromZeroToOne): Promise; + function getBrightnessAsync(): Promise; + function getSystemBrightnessAsync(): Promise; + function setSystemBrightnessAsync(brightnessValue: FloatFromZeroToOne): Promise; } /** @@ -398,29 +399,29 @@ export class CameraObject { getSupportedRatiosAsync(): Promise; // Android only } export interface CameraProperties extends ViewProperties { - onCameraReady: () => void; - onMountError: () => void; - flashMode: string | number; - type: string | number; - ratio: string; - autoFocus: string | number | boolean; - focusDepth: FloatFromZeroToOne; - zoom: FloatFromZeroToOne; - whiteBalance: string | number; - barCodeTypes: string[]; - onBarCodeRead: BarCodeReadCallback; - ref?: CameraObject; + flashMode?: string | number; + type?: string | number; + ratio?: string; + autoFocus?: string | number | boolean; + focusDepth?: FloatFromZeroToOne; + zoom?: FloatFromZeroToOne; + whiteBalance?: string | number; + barCodeTypes?: string[]; + onCameraReady?: () => void; + onMountError?: () => void; + onBarCodeRead?: BarCodeReadCallback; + ref?: Ref; } export interface CameraConstants { - Type: string; - FlashMode: string; - AutoFocus: string; - WhiteBalance: string; - VideoQuality: string; - BarCodeType: string; + readonly Type: string; + readonly FlashMode: string; + readonly AutoFocus: string; + readonly WhiteBalance: string; + readonly VideoQuality: string; + readonly BarCodeType: string; } export class Camera extends Component { - static Constants: CameraConstants; + static readonly Constants: CameraConstants; } /** @@ -694,7 +695,7 @@ export namespace Contacts { */ export namespace DocumentPicker { interface Options { - type: string; + type?: string; } type Response = { type: 'success'; @@ -705,7 +706,7 @@ export namespace DocumentPicker { type: 'cancel'; }; - function getDocumentAsync(options: Options): Response; + function getDocumentAsync(options?: Options): Promise; } /** @@ -730,7 +731,7 @@ export namespace Facebook { } | { type: 'cancel'; }; - function logInWithReadPermissionsAsync(appId: string, options: Options): Promise; + function logInWithReadPermissionsAsync(appId: string, options?: Options): Promise; } /** @@ -803,7 +804,7 @@ export namespace FileSystem { uri: string; size: number; modificationTime: number; - md5?: string; + md5?: Md5; } | { exists: false; isDirectory: false; @@ -813,7 +814,7 @@ export namespace FileSystem { uri: string; status: number; headers: { [name: string]: string }; - md5?: string; + md5?: Md5; } const documentDirectory: string; @@ -825,9 +826,9 @@ export namespace FileSystem { function deleteAsync(fileUri: string, options?: { idempotent: boolean; }): Promise; function moveAsync(options: { from: string, to: string; }): Promise; function copyAsync(options: { from: string, to: string; }): Promise; - function makeDirectoryAsync(fireUri: string, options?: { intermediates: boolean }): Promise; - function readDirectoryAsync(fileUri: string): Promise; - function downloadAsync(uri: string, fileUri: string, options?: { md5: boolean; }): Promise; + function makeDirectoryAsync(dirUri: string, options?: { intermediates: boolean }): Promise; + function readDirectoryAsync(dirUri: string): Promise; + function downloadAsync(uri: string, fileUri: string, options?: { md5?: boolean; }): Promise; function createDownloadResumable( uri: string, fileUri: string, @@ -863,14 +864,6 @@ export namespace FileSystem { callback?: DownloadProgressCallback, resumeData?: string ); - private _uuid: string; - private _url: string; - private _fileUri: string; - private _options: DownloadOptions; - private _emitter: NativeEventEmitter; - private _resumeData?: string; - private _callback?: DownloadProgressCallback; - private _subscription?: () => void; downloadAsync(): Promise; pauseAsync(): Promise; diff --git a/types/expo/tsconfig.json b/types/expo/tsconfig.json index f397f7494c..04edeb26ab 100644 --- a/types/expo/tsconfig.json +++ b/types/expo/tsconfig.json @@ -4,6 +4,7 @@ "lib": [ "es6" ], + "jsx": "react-native", "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, @@ -18,6 +19,6 @@ }, "files": [ "index.d.ts", - "expo-tests.ts" + "expo-tests.tsx" ] }