Skip to content

Commit 50324ef

Browse files
authored
feat: more test formatting (#866)
1 parent 52bbb36 commit 50324ef

File tree

3 files changed

+95
-123
lines changed

3 files changed

+95
-123
lines changed

example/src/components/TestItem.tsx

Lines changed: 73 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,70 @@ import { useNavigation } from '@react-navigation/native';
66
import { colors } from '../styles/colors';
77

88
type TestItemProps = {
9-
suiteIndex: number;
9+
suiteIndex?: number;
1010
description: string;
11-
value: boolean;
11+
value?: boolean;
1212
count: number;
13-
results: TestResult[];
14-
onToggle: (description: string) => void;
13+
results?: TestResult[];
14+
onToggle?: (description: string) => void;
15+
isFooter?: boolean;
16+
passCount?: number;
17+
failCount?: number;
1518
};
1619

1720
export const TestItem: React.FC<TestItemProps> = ({
18-
suiteIndex,
21+
suiteIndex = 0,
1922
description,
20-
value,
23+
value = false,
2124
count,
22-
results,
25+
results = [],
2326
onToggle,
27+
isFooter = false,
28+
passCount,
29+
failCount,
2430
}: TestItemProps) => {
2531
const navigation = useNavigation();
2632

2733
// get pass/fail stats from results
28-
let pass = 0;
29-
let fail = 0;
30-
results.map(r => {
31-
if (r.type === 'correct') {
32-
pass++;
33-
}
34-
if (r.type === 'incorrect') {
35-
fail++;
36-
}
37-
});
34+
let pass = passCount ?? 0;
35+
let fail = failCount ?? 0;
36+
37+
if (!isFooter) {
38+
results.map(r => {
39+
if (r.type === 'correct') {
40+
pass++;
41+
}
42+
if (r.type === 'incorrect') {
43+
fail++;
44+
}
45+
});
46+
}
3847

3948
return (
40-
<View
41-
style={styles.container}
42-
testID={`test-suite-${description.replace(/\s+/g, '-').toLowerCase()}`}
43-
>
44-
<BouncyCheckbox
45-
isChecked={value}
46-
onPress={() => {
47-
onToggle(description);
48-
}}
49-
fillColor={colors.blue}
50-
style={styles.checkbox}
51-
disableBuiltInState={true}
52-
/>
49+
<View style={styles.container}>
50+
{isFooter ? (
51+
<Text style={styles.timer}>⏱️</Text>
52+
) : (
53+
<BouncyCheckbox
54+
isChecked={value}
55+
onPress={() => {
56+
onToggle?.(description);
57+
}}
58+
fillColor={colors.blue}
59+
style={styles.checkbox}
60+
disableBuiltInState={true}
61+
/>
62+
)}
5363
<TouchableOpacity
5464
style={styles.touchable}
5565
onPress={() => {
56-
// @ts-expect-error - not dealing with navigation types rn
57-
navigation.navigate('TestDetailsScreen', {
58-
results,
59-
suiteName: description,
60-
});
66+
if (!isFooter) {
67+
// @ts-expect-error - not dealing with navigation types rn
68+
navigation.navigate('TestDetailsScreen', {
69+
results,
70+
suiteName: description,
71+
});
72+
}
6173
}}
6274
>
6375
<Text
@@ -70,21 +82,33 @@ export const TestItem: React.FC<TestItemProps> = ({
7082
<Text
7183
style={[styles.pass, styles.count]}
7284
numberOfLines={1}
73-
testID={`test-suite-${suiteIndex}-pass-count`}
85+
testID={
86+
isFooter
87+
? 'completion-stats'
88+
: `test-suite-${suiteIndex}-pass-count`
89+
}
7490
>
75-
{pass || ''}
91+
{isFooter ? pass : pass || ''}
7692
</Text>
7793
<Text
7894
style={[styles.fail, styles.count]}
7995
numberOfLines={1}
80-
testID={`test-suite-${suiteIndex}-fail-count`}
96+
testID={
97+
isFooter
98+
? 'total-fail-count'
99+
: `test-suite-${suiteIndex}-fail-count`
100+
}
81101
>
82-
{fail || ''}
102+
{isFooter ? fail : fail || ''}
83103
</Text>
84104
<Text
85105
style={styles.count}
86106
numberOfLines={1}
87-
testID={`test-suite-${suiteIndex}-total-count`}
107+
testID={
108+
isFooter
109+
? 'total-test-count'
110+
: `test-suite-${suiteIndex}-total-count`
111+
}
88112
>
89113
{count}
90114
</Text>
@@ -104,12 +128,13 @@ const styles = StyleSheet.create({
104128
borderBottomWidth: 1,
105129
borderBottomColor: colors.gray,
106130
paddingHorizontal: 10,
131+
marginVertical: -1,
107132
},
108133
checkbox: {
109-
transform: [{ scaleX: 0.7 }, { scaleY: 0.7 }],
134+
transform: [{ scaleX: 0.6 }, { scaleY: 0.6 }],
110135
},
111136
label: {
112-
fontSize: 12,
137+
fontSize: 11,
113138
flex: 8,
114139
},
115140
touchable: {
@@ -126,5 +151,11 @@ const styles = StyleSheet.create({
126151
fontSize: 11,
127152
flex: 1,
128153
textAlign: 'right',
154+
paddingHorizontal: 1,
155+
},
156+
timer: {
157+
fontSize: 14,
158+
paddingHorizontal: 6,
159+
paddingVertical: 4,
129160
},
130161
});
Lines changed: 22 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import React, { useMemo } from 'react';
2-
import {
3-
Text,
4-
View,
5-
FlatList,
6-
StyleSheet,
7-
TouchableOpacity,
8-
} from 'react-native';
2+
import { View, FlatList, StyleSheet } from 'react-native';
93
import { SafeAreaView } from 'react-native-safe-area-context';
104
import { Button } from '../../components/Button';
115
import { TestItem } from '../../components/TestItem';
@@ -57,38 +51,22 @@ export const TestSuitesScreen = () => {
5751
testID="test-suites-list"
5852
/>
5953
</View>
60-
{results && Object.keys(results).length > 0 && stats && (
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>
90-
</View>
91-
)}
54+
<TestItem
55+
suiteIndex={-1}
56+
isFooter
57+
description={stats ? `${stats?.duration}ms` : ''}
58+
count={totalCount}
59+
passCount={Object.values(results).reduce(
60+
(sum, suite) =>
61+
sum + suite.results.filter(r => r.type === 'correct').length,
62+
0,
63+
)}
64+
failCount={Object.values(results).reduce(
65+
(sum, suite) =>
66+
sum + suite.results.filter(r => r.type === 'incorrect').length,
67+
0,
68+
)}
69+
/>
9270
<View style={styles.menu}>
9371
<Button
9472
title="Check All"
@@ -119,46 +97,16 @@ const styles = StyleSheet.create({
11997
},
12098
testList: {
12199
flex: 9,
100+
borderTopWidth: 1,
101+
borderTopColor: colors.gray,
102+
borderBottomWidth: 1,
103+
borderBottomColor: colors.gray,
122104
},
123105
menu: {
124106
flex: 1,
125107
flexDirection: 'row',
126108
alignItems: 'center',
127-
alignContent: 'space-around',
128109
justifyContent: 'space-around',
129-
},
130-
footerItem: {
131-
width: '100%',
132-
flexDirection: 'row',
133-
alignContent: 'center',
134-
alignItems: 'center',
135-
gap: 10,
136-
borderTopWidth: 1,
137-
borderTopColor: colors.gray,
138-
paddingHorizontal: 10,
139-
paddingVertical: 5,
140-
},
141-
footerCheckbox: {
142-
width: 24,
143-
},
144-
footerContent: {
145-
flex: 1,
146-
flexDirection: 'row',
147-
},
148-
footerLabel: {
149-
fontSize: 11,
150-
fontWeight: 'bold',
151-
flex: 8,
152-
},
153-
footerCount: {
154-
fontSize: 11,
155-
flex: 1,
156-
textAlign: 'right',
157-
},
158-
pass: {
159-
color: colors.green,
160-
},
161-
fail: {
162-
color: colors.red,
110+
marginVertical: -5,
163111
},
164112
});

example/test/e2e/test-suites-flow.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ jsEngine: graaljs
1313
- assertVisible: 'Check All'
1414
- assertVisible: 'Clear All'
1515

16-
# Clear any previous test results
17-
- tapOn: 'Clear All'
18-
19-
# Wait for clear to complete
20-
- waitForAnimationToEnd:
21-
timeout: 2000
22-
2316
# Select all tests by tapping "Check All"
2417
- tapOn: 'Check All'
2518

0 commit comments

Comments
 (0)