Skip to content

Commit

Permalink
add e2e test for native module
Browse files Browse the repository at this point in the history
  • Loading branch information
hanwencheng committed Oct 19, 2019
1 parent 7bf54f3 commit 4ad0e1f
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 11 deletions.
16 changes: 8 additions & 8 deletions e2e/firstTest.spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import testIds from "./testIds";
import testIDs from "./testIDs";

describe('Example', () => {
describe('First test', () => {
beforeEach(async () => {
// await device.reloadReactNative();
await device.reloadReactNative();
});

it('should have account list screen', async () => {
await expect(element(by.id(testIds.TacScreen.tacView))).toBeVisible();
await element(by.id(testIds.TacScreen.agreePrivacyButton)).tap();
await element(by.id(testIds.TacScreen.agreeTacButton)).tap();
await element(by.id(testIds.TacScreen.nextButton)).tap();
await expect(element(by.id(testIds.AccountListScreen.accountList))).toBeVisible();
await expect(element(by.id(testIDs.TacScreen.tacView))).toBeVisible();
await element(by.id(testIDs.TacScreen.agreePrivacyButton)).tap();
await element(by.id(testIDs.TacScreen.agreeTacButton)).tap();
await element(by.id(testIDs.TacScreen.nextButton)).tap();
await expect(element(by.id(testIDs.AccountListScreen.accountList))).toBeVisible();
});
});
16 changes: 16 additions & 0 deletions e2e/native.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import testIDs from "./testIDs";

describe('First test', () => {
beforeEach(async () => {
// await device.clearKeychain();
});

it('should pass all the eccrypto function', async () => {
await expect(element(by.id(testIDs.TacScreen.tacView))).toBeVisible();
await element(by.id(testIDs.TacScreen.nativeModuleTestButton)).tap();
await expect(element(by.id(testIDs.NativeTestScreen.nativeTestView))).toBeVisible();
await expect(element(by.id(testIDs.NativeTestScreen.succeedView))).toNotExist();
await element(by.id(testIDs.NativeTestScreen.startButton)).tap();
await expect(element(by.id(testIDs.NativeTestScreen.succeedView))).toExist();
})
});
51 changes: 51 additions & 0 deletions e2e/screens/NativeModuleTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import React, {useState} from 'react';
import {View} from 'react-native';
import {encryptWithSecureKeystore, decryptWithSecureKeystore} from "../../src/util/native";
import testIDs from "../testIDs";
import Button from "../../src/components/Button";

const testSeed = '0xf49cd2aa6bda43467abc6aa0a4f37c5b1378146855f80f491e5dd6d053fa4279';
const testPublicAddress = '0x5Cc5dc62be3c95C771C142C2e30358B398265de21111';

export default function NativeModuleTest() {

const [testSucceed, setTestResult] = useState(false);

const generateTestResult = (expectedResult, actualResult) => expectedResult === actualResult ? setTestResult(true) : setTestResult(false);

const testECCryptoModule = async () => {
const encryptedSeed = await encryptWithSecureKeystore(testSeed, testPublicAddress);
const decryptedText = await decryptWithSecureKeystore(encryptedSeed, testPublicAddress);
generateTestResult(testSeed, decryptedText)
};

const startTest = async () => {
try {
await testECCryptoModule();
} catch (e) {
console.log('error is', e);
setTestResult(false)
}
};

return <View testID={testIDs.NativeTestScreen.nativeTestView}>
<Button title="Start Test" onPress={startTest} testID={testIDs.NativeTestScreen.startButton}/>
{testSucceed && <View testID={testIDs.NativeTestScreen.succeedView}/>}
</View>
}
10 changes: 8 additions & 2 deletions e2e/testIDs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ const testIDs = {
tacView: 'tac_view',
agreeTacButton: 'tac_agree',
agreePrivacyButton: 'tac_privacy',
nativeModuleTestButton: 'tac_native_test',
nextButton: 'tac_next'
},
AccountListScreen: {
accountList: 'accountList',
}
accountList: 'accountList'
},
NativeTestScreen: {
nativeTestView: 'native_test_view',
startButton: 'native_test_start',
succeedView: 'native_test_success'
},
};

export default testIDs;
4 changes: 4 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import AccountRecover from './screens/AccountRecover';
import { AccountUnlock, AccountUnlockAndSign } from './screens/AccountUnlock';
import Loading from './screens/Loading';
import MessageDetails from './screens/MessageDetails';
import NativeModuleTest from '../e2e/screens/NativeModuleTest';
import PrivacyPolicy from './screens/PrivacyPolicy';
import QrScanner from './screens/QrScanner';
import Security from './screens/Security';
Expand Down Expand Up @@ -207,6 +208,9 @@ const Screens = createStackNavigator(
MessageDetails: {
screen: MessageDetails
},
NativeModuleTest: {
screen: NativeModuleTest
},
QrScanner: {
screen: QrScanner
},
Expand Down
16 changes: 15 additions & 1 deletion src/screens/TermsAndConditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
'use strict';

import React from 'react';
import { ScrollView, StyleSheet, Text, View } from 'react-native';
import {
ScrollView,
StyleSheet,
Text,
View,
TouchableOpacity
} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import toc from '../../docs/terms-and-conditions.md';
import colors from '../colors';
Expand Down Expand Up @@ -108,6 +114,14 @@ export default class TermsAndConditions extends React.PureComponent {
navigation.dispatch(firstScreenActions);
}}
/>
{__DEV__ && (
<TouchableOpacity
onPress={() => navigation.navigate('NativeModuleTest')}
testID={testIDs.TacScreen.nativeModuleTestButton}
>
<View style={{ height: 1, width: 1 }} />
</TouchableOpacity>
)}
</View>
);
}
Expand Down

0 comments on commit 4ad0e1f

Please sign in to comment.