forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {useState} from 'react'
2import {LogBox, Pressable, TextInput, View} from 'react-native'
3import {useQueryClient} from '@tanstack/react-query'
4
5import {BLUESKY_PROXY_HEADER} from '#/lib/constants'
6import {useAgent, useSessionApi} 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 accessibilityLabel="Text input field"
54 accessibilityHint="Enter proxy header"
55 testID="e2eProxyHeaderInput"
56 onChangeText={val => setProxyHeader(val as any)}
57 onSubmitEditing={() => {
58 const header = `${proxyHeader}#bsky_appview`
59 BLUESKY_PROXY_HEADER.set(header)
60 agent.configureProxy(header as any)
61 }}
62 style={BTN}
63 />
64 <Pressable
65 testID="e2eSignInAlice"
66 onPress={onPressSignInAlice}
67 accessibilityRole="button"
68 style={BTN}
69 />
70 <Pressable
71 testID="e2eSignInBob"
72 onPress={onPressSignInBob}
73 accessibilityRole="button"
74 style={BTN}
75 />
76 <Pressable
77 testID="e2eSignOut"
78 onPress={() => logoutEveryAccount('Settings')}
79 accessibilityRole="button"
80 style={BTN}
81 />
82 <Pressable
83 testID="e2eGotoHome"
84 onPress={() => navigate('Home')}
85 accessibilityRole="button"
86 style={BTN}
87 />
88 <Pressable
89 testID="e2eGotoSettings"
90 onPress={() => navigate('Settings')}
91 accessibilityRole="button"
92 style={BTN}
93 />
94 <Pressable
95 testID="e2eGotoModeration"
96 onPress={() => navigate('Moderation')}
97 accessibilityRole="button"
98 style={BTN}
99 />
100 <Pressable
101 testID="e2eGotoLists"
102 onPress={() => navigate('Lists')}
103 accessibilityRole="button"
104 style={BTN}
105 />
106 <Pressable
107 testID="e2eGotoFeeds"
108 onPress={() => navigate('Feeds')}
109 accessibilityRole="button"
110 style={BTN}
111 />
112 <Pressable
113 testID="storybookBtn"
114 onPress={() => navigate('Debug')}
115 accessibilityRole="button"
116 style={BTN}
117 />
118 <Pressable
119 testID="e2eRefreshHome"
120 onPress={() => queryClient.invalidateQueries({queryKey: ['post-feed']})}
121 accessibilityRole="button"
122 style={BTN}
123 />
124 <Pressable
125 testID="e2eOpenLoggedOutView"
126 onPress={() => setShowLoggedOut(true)}
127 accessibilityRole="button"
128 style={BTN}
129 />
130 <Pressable
131 testID="e2eStartOnboarding"
132 onPress={() => {
133 onboardingDispatch({type: 'start'})
134 }}
135 accessibilityRole="button"
136 style={BTN}
137 />
138 {/* TODO remove this entire control when experiment is over */}
139 <Pressable
140 testID="e2eStartLongboarding"
141 onPress={() => {
142 onboardingDispatch({type: 'start'})
143 }}
144 accessibilityRole="button"
145 style={BTN}
146 />
147 </View>
148 )
149}