From 629908077bac27e8495c716d5785164eccf96b4f Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Wed, 24 Aug 2022 16:27:03 +0200 Subject: [PATCH 1/4] test: simplify all the tests --- example/App.tsx | 73 ++--- example/e2e/asyncstorage.e2e.js | 276 ++---------------- example/examples/Basic.tsx | 9 +- example/examples/Functional.tsx | 137 +++++++++ example/examples/GetSetClear.tsx | 11 +- example/examples/MergeItem.tsx | 11 +- example/examples/tests.ts | 46 +++ .../AsyncStorageDevSupport.m | 16 +- package.json | 2 + yarn.lock | 5 + 10 files changed, 268 insertions(+), 318 deletions(-) create mode 100644 example/examples/Functional.tsx create mode 100644 example/examples/tests.ts diff --git a/example/App.tsx b/example/App.tsx index 6ea3b65a..70c65496 100644 --- a/example/App.tsx +++ b/example/App.tsx @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import React, { useCallback, useState } from 'react'; +import React, { useCallback, useMemo, useState } from 'react'; import { Button, Keyboard, @@ -15,52 +15,42 @@ import { TouchableOpacity, View, } from 'react-native'; -import BasicExample from './examples/Basic'; +import Basic from './examples/Basic'; +import Functional from './examples/Functional'; import GetSetClear from './examples/GetSetClear'; import MergeItem from './examples/MergeItem'; -const TESTS = { - GetSetClear: { - title: 'Simple Get/Set value', - testId: 'get-set-clear', - description: 'Store and retrieve persisted data', - render() { - return ; - }, - }, - MergeItem: { - title: 'Merge item', - testId: 'merge-item', - description: 'Merge object with already stored data', - render() { - return ; - }, - }, - Basic: { - title: 'Basic', - testId: 'basic', - description: 'Basic functionality test', - render() { - return ; - }, - }, +const SCREENS = { + Functional, + GetSetClear, + MergeItem, + Basic, }; export default function App(): JSX.Element { const [iteration, setIteration] = useState(0); - const [currentTest, setCurrentTest] = useState(TESTS.GetSetClear); + const [currentTest, setCurrentTest] = useState(SCREENS.Functional); - const dismissKeyboard = useCallback(() => Keyboard.dismiss(), []); + const dismissKeyboard = useCallback(Keyboard.dismiss, []); const simulateRestart = useCallback( () => setIteration(iteration + 1), [iteration] ); - const testBasic = useCallback(() => setCurrentTest(TESTS.Basic), []); - const testGetSetClear = useCallback( - () => setCurrentTest(TESTS.GetSetClear), + const navigationBar = useMemo( + () => + Object.values(SCREENS).map((t) => { + const { testId, title } = t; + return ( +