Skip to content

Commit 52bbb36

Browse files
authored
test: reorganize test suites and improve UI alignment (#861)
1 parent 2b466b4 commit 52bbb36

File tree

11 files changed

+557
-624
lines changed

11 files changed

+557
-624
lines changed

example/src/components/TestItem.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ const styles = StyleSheet.create({
123123
color: colors.red,
124124
},
125125
count: {
126-
fontSize: 12,
127-
fontWeight: 'bold',
126+
fontSize: 11,
128127
flex: 1,
129128
textAlign: 'right',
130129
},

example/src/hooks/useTestsList.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import '../tests/blake3/blake3_tests';
66
import '../tests/cipher/cipher_tests';
77
import '../tests/cipher/chacha_tests';
88
import '../tests/cipher/xsalsa20_tests';
9-
import '../tests/cfrg/ed25519_tests';
10-
import '../tests/cfrg/x25519_tests';
11-
import '../tests/constants/constants_tests';
129
import '../tests/hash/hash_tests';
1310
import '../tests/hmac/hmac_tests';
1411
import '../tests/hkdf/hkdf_tests';
@@ -19,10 +16,8 @@ import '../tests/keys/generate_keypair';
1916
import '../tests/keys/public_cipher';
2017
import '../tests/keys/sign_verify_streaming';
2118
import '../tests/pbkdf2/pbkdf2_tests';
22-
import '../tests/scrypt/scrypt_tests';
2319
import '../tests/random/random_tests';
24-
import '../tests/utils/timingSafeEqual_tests';
25-
import '../tests/subtle/x25519_x448';
20+
import '../tests/scrypt/scrypt_tests';
2621
import '../tests/subtle/deriveBits';
2722
import '../tests/subtle/derive_key';
2823
import '../tests/subtle/digest';
@@ -32,6 +27,7 @@ import '../tests/subtle/import_export';
3227
import '../tests/subtle/jwk_rfc7517_tests';
3328
import '../tests/subtle/sign_verify';
3429
import '../tests/subtle/wrap_unwrap';
30+
import '../tests/utils/utils_tests';
3531

3632
export const useTestsList = (): [
3733
TestSuites,

example/src/navigators/children/TestSuitesScreen.tsx

Lines changed: 91 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,92 @@
1-
import React from 'react';
2-
import { Text, View, ScrollView, StyleSheet } from 'react-native';
1+
import React, { useMemo } from 'react';
2+
import {
3+
Text,
4+
View,
5+
FlatList,
6+
StyleSheet,
7+
TouchableOpacity,
8+
} from 'react-native';
39
import { SafeAreaView } from 'react-native-safe-area-context';
410
import { Button } from '../../components/Button';
511
import { TestItem } from '../../components/TestItem';
612
import { useTestsList } from '../../hooks/useTestsList';
713
import { useTestsRun } from '../../hooks/useTestsRun';
814
import { colors } from '../../styles/colors';
915

16+
type SuiteEntry = {
17+
name: string;
18+
suite: { value: boolean; tests: Record<string, () => void | Promise<void>> };
19+
count: number;
20+
};
21+
1022
export const TestSuitesScreen = () => {
1123
const [suites, toggle, clearAll, checkAll] = useTestsList();
1224
const [results, runTests, stats] = useTestsRun();
13-
let totalCount = 0;
25+
26+
const suiteEntries = useMemo(() => {
27+
return Object.entries(suites).map(([name, suite]) => ({
28+
name,
29+
suite,
30+
count: Object.keys(suite.tests).length,
31+
}));
32+
}, [suites]);
33+
34+
const totalCount = useMemo(
35+
() => suiteEntries.reduce((sum, entry) => sum + entry.count, 0),
36+
[suiteEntries],
37+
);
38+
39+
const renderItem = ({ item, index }: { item: SuiteEntry; index: number }) => (
40+
<TestItem
41+
suiteIndex={index}
42+
description={item.name}
43+
value={item.suite.value}
44+
count={item.count}
45+
results={results[item.name]?.results || []}
46+
onToggle={toggle}
47+
/>
48+
);
1449

1550
return (
1651
<SafeAreaView style={styles.mainContainer} edges={['left', 'right']}>
1752
<View style={styles.testList}>
18-
<ScrollView style={styles.scrollView} testID="test-suites-list">
19-
{Object.entries(suites).map(([suiteName, suite], index) => {
20-
const suiteTestCount = Object.keys(suite.tests).length;
21-
totalCount += suiteTestCount;
22-
return (
23-
<TestItem
24-
key={index.toString()}
25-
suiteIndex={index}
26-
description={suiteName}
27-
value={suite.value}
28-
count={suiteTestCount}
29-
results={results[suiteName]?.results || []}
30-
onToggle={toggle}
31-
/>
32-
);
33-
})}
34-
</ScrollView>
53+
<FlatList
54+
data={suiteEntries}
55+
renderItem={renderItem}
56+
keyExtractor={(_item, index) => index.toString()}
57+
testID="test-suites-list"
58+
/>
3559
</View>
3660
{results && Object.keys(results).length > 0 && stats && (
37-
<View style={styles.statsContainer}>
38-
<Text style={styles.timeLabel}>⏱️ {stats.duration}ms</Text>
39-
<Text
40-
style={[styles.pass, styles.statNumber]}
41-
testID="completion-stats"
42-
>
43-
{Object.values(results).reduce(
44-
(sum, suite) =>
45-
sum + suite.results.filter(r => r.type === 'correct').length,
46-
0,
47-
)}
48-
</Text>
49-
<Text
50-
style={[styles.fail, styles.statNumber]}
51-
testID="total-fail-count"
52-
>
53-
{Object.values(results).reduce(
54-
(sum, suite) =>
55-
sum + suite.results.filter(r => r.type === 'incorrect').length,
56-
0,
57-
)}
58-
</Text>
59-
<Text style={styles.statNumber}>{totalCount}</Text>
61+
<View style={styles.footerItem}>
62+
<View style={styles.footerCheckbox} />
63+
<TouchableOpacity style={styles.footerContent} activeOpacity={1}>
64+
<Text style={styles.footerLabel}>⏱️ {stats.duration}ms</Text>
65+
<Text
66+
style={[styles.pass, styles.footerCount]}
67+
testID="completion-stats"
68+
>
69+
{Object.values(results).reduce(
70+
(sum, suite) =>
71+
sum + suite.results.filter(r => r.type === 'correct').length,
72+
0,
73+
)}
74+
</Text>
75+
<Text
76+
style={[styles.fail, styles.footerCount]}
77+
testID="total-fail-count"
78+
>
79+
{Object.values(results).reduce(
80+
(sum, suite) =>
81+
sum +
82+
suite.results.filter(r => r.type === 'incorrect').length,
83+
0,
84+
)}
85+
</Text>
86+
<Text style={styles.footerCount} testID="total-test-count">
87+
{totalCount}
88+
</Text>
89+
</TouchableOpacity>
6090
</View>
6191
)}
6292
<View style={styles.menu}>
@@ -97,24 +127,31 @@ const styles = StyleSheet.create({
97127
alignContent: 'space-around',
98128
justifyContent: 'space-around',
99129
},
100-
scrollView: {},
101-
statsContainer: {
102-
paddingHorizontal: 10,
103-
paddingVertical: 5,
130+
footerItem: {
131+
width: '100%',
104132
flexDirection: 'row',
105-
alignItems: 'center',
106133
alignContent: 'center',
107-
justifyContent: 'space-evenly',
134+
alignItems: 'center',
108135
gap: 10,
136+
borderTopWidth: 1,
137+
borderTopColor: colors.gray,
138+
paddingHorizontal: 10,
139+
paddingVertical: 5,
140+
},
141+
footerCheckbox: {
142+
width: 24,
109143
},
110-
timeLabel: {
111-
fontSize: 12,
144+
footerContent: {
145+
flex: 1,
146+
flexDirection: 'row',
147+
},
148+
footerLabel: {
149+
fontSize: 11,
112150
fontWeight: 'bold',
113151
flex: 8,
114152
},
115-
statNumber: {
116-
fontSize: 12,
117-
fontWeight: 'bold',
153+
footerCount: {
154+
fontSize: 11,
118155
flex: 1,
119156
textAlign: 'right',
120157
},

example/src/tests/cfrg/ed25519_tests.ts

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)