mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {LogBox, Pressable, View} from 'react-native'
2import {useQueryClient} from '@tanstack/react-query'
3
4import {useModalControls} from '#/state/modals'
5import {useSessionApi} from '#/state/session'
6import {useLoggedOutViewControls} from '#/state/shell/logged-out'
7import {useOnboardingDispatch} from '#/state/shell/onboarding'
8import {navigate} from '../../../Navigation'
9
10LogBox.ignoreAllLogs()
11
12/**
13 * This utility component is only included in the test simulator
14 * build. It gives some quick triggers which help improve the pace
15 * of the tests dramatically.
16 */
17
18const BTN = {height: 1, width: 1, backgroundColor: 'red'}
19
20export function TestCtrls() {
21 const queryClient = useQueryClient()
22 const {logoutEveryAccount, login} = useSessionApi()
23 const {openModal} = useModalControls()
24 const onboardingDispatch = useOnboardingDispatch()
25 const {setShowLoggedOut} = useLoggedOutViewControls()
26 const onPressSignInAlice = async () => {
27 await login(
28 {
29 service: 'http://localhost:3000',
30 identifier: 'alice.test',
31 password: 'hunter2',
32 },
33 'LoginForm',
34 )
35 setShowLoggedOut(false)
36 }
37 const onPressSignInBob = async () => {
38 await login(
39 {
40 service: 'http://localhost:3000',
41 identifier: 'bob.test',
42 password: 'hunter2',
43 },
44 'LoginForm',
45 )
46 setShowLoggedOut(false)
47 }
48 return (
49 <View style={{position: 'absolute', top: 100, right: 0, zIndex: 100}}>
50 <Pressable
51 testID="e2eSignInAlice"
52 onPress={onPressSignInAlice}
53 accessibilityRole="button"
54 style={BTN}
55 />
56 <Pressable
57 testID="e2eSignInBob"
58 onPress={onPressSignInBob}
59 accessibilityRole="button"
60 style={BTN}
61 />
62 <Pressable
63 testID="e2eSignOut"
64 onPress={() => logoutEveryAccount('Settings')}
65 accessibilityRole="button"
66 style={BTN}
67 />
68 <Pressable
69 testID="e2eGotoHome"
70 onPress={() => navigate('Home')}
71 accessibilityRole="button"
72 style={BTN}
73 />
74 <Pressable
75 testID="e2eGotoSettings"
76 onPress={() => navigate('Settings')}
77 accessibilityRole="button"
78 style={BTN}
79 />
80 <Pressable
81 testID="e2eGotoModeration"
82 onPress={() => navigate('Moderation')}
83 accessibilityRole="button"
84 style={BTN}
85 />
86 <Pressable
87 testID="e2eGotoLists"
88 onPress={() => navigate('Lists')}
89 accessibilityRole="button"
90 style={BTN}
91 />
92 <Pressable
93 testID="e2eGotoFeeds"
94 onPress={() => navigate('Feeds')}
95 accessibilityRole="button"
96 style={BTN}
97 />
98 <Pressable
99 testID="e2eRefreshHome"
100 onPress={() => queryClient.invalidateQueries({queryKey: ['post-feed']})}
101 accessibilityRole="button"
102 style={BTN}
103 />
104 <Pressable
105 testID="e2eOpenInviteCodesModal"
106 onPress={() => openModal({name: 'invite-codes'})}
107 accessibilityRole="button"
108 style={BTN}
109 />
110 <Pressable
111 testID="e2eOpenLoggedOutView"
112 onPress={() => setShowLoggedOut(true)}
113 accessibilityRole="button"
114 style={BTN}
115 />
116 <Pressable
117 testID="e2eStartOnboarding"
118 onPress={() => {
119 onboardingDispatch({type: 'start'})
120 }}
121 accessibilityRole="button"
122 style={BTN}
123 />
124 {/* TODO remove this entire control when experiment is over */}
125 <Pressable
126 testID="e2eStartLongboarding"
127 onPress={() => {
128 onboardingDispatch({type: 'start'})
129 }}
130 accessibilityRole="button"
131 style={BTN}
132 />
133 </View>
134 )
135}