Skip to content

Commit

Permalink
feat: expose constants (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
iJimmyWei authored Sep 11, 2021
1 parent 2d5dc3f commit ed6562b
Show file tree
Hide file tree
Showing 7 changed files with 33,862 additions and 20,735 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class FileGatewayModule(reactContext: ReactApplicationContext) : ReactContextBas

override fun getConstants(): Map<String, Any>? {
val constants: MutableMap<String, Any> = HashMap()
constants["Cache"] = reactApplicationContext.cacheDir.path
constants["Application"] = reactApplicationContext.filesDir.path
constants["CacheDirectory"] = reactApplicationContext.cacheDir.path
constants["ApplicationDirectory"] = reactApplicationContext.filesDir.path
return constants
}

Expand Down
6 changes: 3 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
"watch": "tsc --watch"
},
"dependencies": {
"faker": "5.5.3",
"react": "17.0.2",
"react-native": "0.65.1",
"faker": "5.5.3"
"react-native": "0.65.1"
},
"devDependencies": {
"@babel/core": "7.14.3",
"@types/faker": "5.5.8",
"@babel/runtime": "7.14.0",
"@types/faker": "5.5.8",
"@types/react-native": "0.65.0",
"babel-plugin-module-resolver": "4.1.0",
"metro-react-native-babel-preset": "0.66.2",
Expand Down
30 changes: 16 additions & 14 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import { useState } from "react";

import { StyleSheet, View, Button } from "react-native";
import { StyleSheet, View, Button, ScrollView } from "react-native";

import FileGateway from "../../src";
export { FileGateway };
Expand All @@ -24,30 +24,32 @@ function TestCaseButton({testCaseName, testNumber, onPress}: {testCaseName: stri
}

return (
<Button
title={`test case ${testNumber + 1} - ${testCaseName}`}
onPress={runTest}
color={hasPassed
? "green"
: hasFailed
? "red"
: "orange"
}
>
</Button>
<View style={{paddingBottom: 4}}>
<Button
title={`test case ${testNumber + 1} - ${testCaseName}`}
onPress={runTest}
color={hasPassed
? "green"
: hasFailed
? "red"
: "orange"
}
>
</Button>
</View>
)
}

export default function App() {
return (
<View style={styles.container}>
<ScrollView contentContainerStyle={styles.container}>
{tests.map((test, index) => <TestCaseButton
key={index}
testCaseName={test.title}
testNumber={index}
onPress={test.handler}
/>)}
</View>
</ScrollView>
);
}

Expand Down
4 changes: 3 additions & 1 deletion example/src/tests/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { applicationFileTests } from "./writeRead";
import listFilesTests from "./listFiles";

interface Test {
title: string;
handler(): Promise<boolean>;
}

export const tests: Test[] = [
...applicationFileTests
...applicationFileTests,
...listFilesTests
]
30 changes: 30 additions & 0 deletions example/src/tests/listFiles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { FileGateway } from "../App";
import faker from "faker";

async function testListFiles(): Promise<boolean> {
const file = {
name: faker.internet.userName(),
contents: faker.lorem.paragraph()
}

const secondFileName = file.name + "1";
await FileGateway.writeFile(file.name, file.contents, "application");
await FileGateway.writeFile(secondFileName, file.contents, "application");

const contents = await FileGateway.listFiles(FileGateway.constants.ApplicationDirectory);
if (
contents.includes(file.name) &&
contents.includes(secondFileName)
) {
return true;
}

return false;
}

export default [
{
title: "should list files in application storage",
handler: testListFiles
}
]
Loading

0 comments on commit ed6562b

Please sign in to comment.