Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions example/src/components/TestItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ const styles = StyleSheet.create({
color: colors.red,
},
count: {
fontSize: 12,
fontWeight: 'bold',
fontSize: 11,
flex: 1,
textAlign: 'right',
},
Expand Down
8 changes: 2 additions & 6 deletions example/src/hooks/useTestsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import '../tests/blake3/blake3_tests';
import '../tests/cipher/cipher_tests';
import '../tests/cipher/chacha_tests';
import '../tests/cipher/xsalsa20_tests';
import '../tests/cfrg/ed25519_tests';
import '../tests/cfrg/x25519_tests';
import '../tests/constants/constants_tests';
import '../tests/hash/hash_tests';
import '../tests/hmac/hmac_tests';
import '../tests/hkdf/hkdf_tests';
Expand All @@ -19,10 +16,8 @@ import '../tests/keys/generate_keypair';
import '../tests/keys/public_cipher';
import '../tests/keys/sign_verify_streaming';
import '../tests/pbkdf2/pbkdf2_tests';
import '../tests/scrypt/scrypt_tests';
import '../tests/random/random_tests';
import '../tests/utils/timingSafeEqual_tests';
import '../tests/subtle/x25519_x448';
import '../tests/scrypt/scrypt_tests';
import '../tests/subtle/deriveBits';
import '../tests/subtle/derive_key';
import '../tests/subtle/digest';
Expand All @@ -32,6 +27,7 @@ import '../tests/subtle/import_export';
import '../tests/subtle/jwk_rfc7517_tests';
import '../tests/subtle/sign_verify';
import '../tests/subtle/wrap_unwrap';
import '../tests/utils/utils_tests';

export const useTestsList = (): [
TestSuites,
Expand Down
145 changes: 91 additions & 54 deletions example/src/navigators/children/TestSuitesScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,62 +1,92 @@
import React from 'react';
import { Text, View, ScrollView, StyleSheet } from 'react-native';
import React, { useMemo } from 'react';
import {
Text,
View,
FlatList,
StyleSheet,
TouchableOpacity,
} from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { Button } from '../../components/Button';
import { TestItem } from '../../components/TestItem';
import { useTestsList } from '../../hooks/useTestsList';
import { useTestsRun } from '../../hooks/useTestsRun';
import { colors } from '../../styles/colors';

type SuiteEntry = {
name: string;
suite: { value: boolean; tests: Record<string, () => void | Promise<void>> };
count: number;
};

export const TestSuitesScreen = () => {
const [suites, toggle, clearAll, checkAll] = useTestsList();
const [results, runTests, stats] = useTestsRun();
let totalCount = 0;

const suiteEntries = useMemo(() => {
return Object.entries(suites).map(([name, suite]) => ({
name,
suite,
count: Object.keys(suite.tests).length,
}));
}, [suites]);

const totalCount = useMemo(
() => suiteEntries.reduce((sum, entry) => sum + entry.count, 0),
[suiteEntries],
);

const renderItem = ({ item, index }: { item: SuiteEntry; index: number }) => (
<TestItem
suiteIndex={index}
description={item.name}
value={item.suite.value}
count={item.count}
results={results[item.name]?.results || []}
onToggle={toggle}
/>
);

return (
<SafeAreaView style={styles.mainContainer} edges={['left', 'right']}>
<View style={styles.testList}>
<ScrollView style={styles.scrollView} testID="test-suites-list">
{Object.entries(suites).map(([suiteName, suite], index) => {
const suiteTestCount = Object.keys(suite.tests).length;
totalCount += suiteTestCount;
return (
<TestItem
key={index.toString()}
suiteIndex={index}
description={suiteName}
value={suite.value}
count={suiteTestCount}
results={results[suiteName]?.results || []}
onToggle={toggle}
/>
);
})}
</ScrollView>
<FlatList
data={suiteEntries}
renderItem={renderItem}
keyExtractor={(_item, index) => index.toString()}
testID="test-suites-list"
/>
</View>
{results && Object.keys(results).length > 0 && stats && (
<View style={styles.statsContainer}>
<Text style={styles.timeLabel}>⏱️ {stats.duration}ms</Text>
<Text
style={[styles.pass, styles.statNumber]}
testID="completion-stats"
>
{Object.values(results).reduce(
(sum, suite) =>
sum + suite.results.filter(r => r.type === 'correct').length,
0,
)}
</Text>
<Text
style={[styles.fail, styles.statNumber]}
testID="total-fail-count"
>
{Object.values(results).reduce(
(sum, suite) =>
sum + suite.results.filter(r => r.type === 'incorrect').length,
0,
)}
</Text>
<Text style={styles.statNumber}>{totalCount}</Text>
<View style={styles.footerItem}>
<View style={styles.footerCheckbox} />
<TouchableOpacity style={styles.footerContent} activeOpacity={1}>
<Text style={styles.footerLabel}>⏱️ {stats.duration}ms</Text>
<Text
style={[styles.pass, styles.footerCount]}
testID="completion-stats"
>
{Object.values(results).reduce(
(sum, suite) =>
sum + suite.results.filter(r => r.type === 'correct').length,
0,
)}
</Text>
<Text
style={[styles.fail, styles.footerCount]}
testID="total-fail-count"
>
{Object.values(results).reduce(
(sum, suite) =>
sum +
suite.results.filter(r => r.type === 'incorrect').length,
0,
)}
</Text>
<Text style={styles.footerCount} testID="total-test-count">
{totalCount}
</Text>
</TouchableOpacity>
</View>
)}
<View style={styles.menu}>
Expand Down Expand Up @@ -97,24 +127,31 @@ const styles = StyleSheet.create({
alignContent: 'space-around',
justifyContent: 'space-around',
},
scrollView: {},
statsContainer: {
paddingHorizontal: 10,
paddingVertical: 5,
footerItem: {
width: '100%',
flexDirection: 'row',
alignItems: 'center',
alignContent: 'center',
justifyContent: 'space-evenly',
alignItems: 'center',
gap: 10,
borderTopWidth: 1,
borderTopColor: colors.gray,
paddingHorizontal: 10,
paddingVertical: 5,
},
footerCheckbox: {
width: 24,
},
timeLabel: {
fontSize: 12,
footerContent: {
flex: 1,
flexDirection: 'row',
},
footerLabel: {
fontSize: 11,
fontWeight: 'bold',
flex: 8,
},
statNumber: {
fontSize: 12,
fontWeight: 'bold',
footerCount: {
fontSize: 11,
flex: 1,
textAlign: 'right',
},
Expand Down
156 changes: 0 additions & 156 deletions example/src/tests/cfrg/ed25519_tests.ts

This file was deleted.

Loading