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