Skip to content

Commit 5437871

Browse files
authored
Merge pull request #242 from synonymdev/test/scan-prompt-test-form
Test/scan prompt test form
2 parents c5abceb + 668f8d2 commit 5437871

File tree

6 files changed

+134
-4
lines changed

6 files changed

+134
-4
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ jobs:
108108
# - { name: onchain_boost_receive_widgets, grep: "@onchain|@boost|@receive|@widgets" }
109109
# - { name: settings, grep: "@settings" }
110110
# - { name: security, grep: "@security" }
111-
- { name: e2e, grep: '^(?!.*@settings_10)(@backup|@onboarding|@onchain_1|@onchain_2|@numberpad|@widgets|@boost|@receive|@settings|@security)' }
111+
- { name: e2e, grep: '@backup|@onboarding|@onchain_1|@onchain_2|@numberpad|@widgets|@boost|@receive|@settings|@security' }
112112

113113
name: e2e-tests - ${{ matrix.shard.name }}
114114

@@ -175,15 +175,15 @@ jobs:
175175
working-directory: bitkit-e2e-tests
176176
run: |
177177
echo "Waiting for Electrum server..."
178-
while ! nc -z '127.0.0.1' 60001; do
178+
while ! nc -z '127.0.0.1' 60001; do
179179
echo "Electrum server not ready, waiting..."
180180
sleep 5
181181
done
182182
echo "Electrum server is ready!"
183183
184184
- name: Clear previous E2E artifacts
185185
working-directory: bitkit-e2e-tests
186-
run: |
186+
run: |
187187
rm -rf artifacts/
188188
rm -rf /tmp/lock/
189189
@@ -249,4 +249,4 @@ jobs:
249249
echo "❌ Some E2E shards failed."
250250
exit 1
251251
fi
252-
echo "✅ All E2E shards passed!"
252+
echo "✅ All E2E shards passed!"

Bitkit/Components/TabBar/ScanButton.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct ScanButton: View {
2020
.background(Circle().fill(background))
2121
.foregroundColor(.gray1)
2222
}
23+
.accessibilityIdentifier("Scan")
2324
.shadow(color: Color.gray2, radius: 0, x: 0, y: -1)
2425
.shadow(color: Color.black.opacity(0.25), radius: 25, x: 0, y: 20)
2526
.overlay(

Bitkit/Managers/ScannerManager.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,18 @@ class ScannerManager: ObservableObject {
233233
)
234234
}
235235
}
236+
237+
func handleManualEntry(
238+
_ value: String,
239+
context: ScannerContext,
240+
onSuccess: @MainActor () -> Void
241+
) async {
242+
let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines)
243+
guard !trimmed.isEmpty else { return }
244+
245+
await handleScan(trimmed, context: context)
246+
await MainActor.run {
247+
onSuccess()
248+
}
249+
}
236250
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import SwiftUI
2+
3+
struct ScannerManualEntryPrompt: View {
4+
@Binding var text: String
5+
var onSubmit: () -> Void
6+
var onCancel: () -> Void
7+
8+
var body: some View {
9+
VStack(alignment: .leading, spacing: 16) {
10+
HStack {
11+
Spacer()
12+
Button(action: onCancel) {
13+
Image("x-mark")
14+
.resizable()
15+
.frame(width: 16, height: 16)
16+
}
17+
.accessibilityIdentifier("DialogCancel")
18+
}
19+
20+
BodyMSBText("Enter QR Code String")
21+
22+
SwiftUI.TextField("", text: $text)
23+
.textInputAutocapitalization(.never)
24+
.autocorrectionDisabled()
25+
.padding()
26+
.background(Color.white10)
27+
.cornerRadius(10)
28+
.accessibilityIdentifier("QRInput")
29+
30+
CustomButton(title: t("common__yes_proceed"), shouldExpand: true) {
31+
onSubmit()
32+
}
33+
.accessibilityIdentifier("DialogConfirm")
34+
35+
Spacer()
36+
}
37+
.padding(16)
38+
.accessibilityElement(children: .contain)
39+
.accessibilityIdentifier("QRDialog")
40+
}
41+
}

Bitkit/Views/Scanner/ScannerScreen.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ struct ScannerScreen: View {
77
@EnvironmentObject private var scanner: ScannerManager
88
@EnvironmentObject private var settings: SettingsViewModel
99
@EnvironmentObject private var sheets: SheetViewModel
10+
@State private var isManualEntryPresented = false
11+
@State private var manualEntry = ""
1012

1113
private var scannerContext: ScannerContext {
1214
if navigation.path.contains(.electrumSettings) {
@@ -39,6 +41,19 @@ struct ScannerScreen: View {
3941
) {
4042
await scanner.handlePaste(context: scannerContext)
4143
}
44+
.padding(.bottom, Env.isE2E ? 12 : 0)
45+
46+
if Env.isE2E {
47+
CustomButton(
48+
title: "Enter QR Code String",
49+
variant: .secondary,
50+
shouldExpand: true
51+
) {
52+
manualEntry = ""
53+
isManualEntryPresented = true
54+
}
55+
.accessibilityIdentifier("ScanPrompt")
56+
}
4257
}
4358
.navigationBarHidden(true)
4459
.padding(.horizontal, 16)
@@ -52,5 +67,27 @@ struct ScannerScreen: View {
5267
sheets: sheets
5368
)
5469
}
70+
.sheet(isPresented: $isManualEntryPresented) {
71+
ScannerManualEntryPrompt(
72+
text: $manualEntry,
73+
onSubmit: {
74+
Task {
75+
await handleManualEntrySubmit()
76+
}
77+
},
78+
onCancel: {
79+
isManualEntryPresented = false
80+
}
81+
)
82+
.presentationDetents([.fraction(0.35)])
83+
.presentationDragIndicator(.visible)
84+
}
85+
}
86+
87+
private func handleManualEntrySubmit() async {
88+
await scanner.handleManualEntry(manualEntry, context: scannerContext) {
89+
isManualEntryPresented = false
90+
manualEntry = ""
91+
}
5592
}
5693
}

Bitkit/Views/Scanner/ScannerSheet.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ struct ScannerSheet: View {
1212
@EnvironmentObject private var scanner: ScannerManager
1313
@EnvironmentObject private var settings: SettingsViewModel
1414
@EnvironmentObject private var sheets: SheetViewModel
15+
@State private var isManualEntryPresented = false
16+
@State private var manualEntry = ""
1517

1618
let config: ScannerSheetItem
1719

@@ -40,6 +42,19 @@ struct ScannerSheet: View {
4042
) {
4143
await scanner.handlePaste(context: .main)
4244
}
45+
46+
if Env.isE2E {
47+
CustomButton(
48+
title: "Enter QRCode String",
49+
variant: .secondary,
50+
shouldExpand: true
51+
) {
52+
manualEntry = ""
53+
isManualEntryPresented = true
54+
}
55+
.padding(.top, 12)
56+
.accessibilityIdentifier("ScanPrompt")
57+
}
4358
}
4459
}
4560
.navigationBarHidden(false)
@@ -54,6 +69,28 @@ struct ScannerSheet: View {
5469
sheets: sheets
5570
)
5671
}
72+
.sheet(isPresented: $isManualEntryPresented) {
73+
ScannerManualEntryPrompt(
74+
text: $manualEntry,
75+
onSubmit: {
76+
Task {
77+
await handleManualEntrySubmit()
78+
}
79+
},
80+
onCancel: {
81+
isManualEntryPresented = false
82+
}
83+
)
84+
.presentationDetents([.fraction(0.35)])
85+
.presentationDragIndicator(.visible)
86+
}
87+
}
88+
}
89+
90+
private func handleManualEntrySubmit() async {
91+
await scanner.handleManualEntry(manualEntry, context: .main) {
92+
isManualEntryPresented = false
93+
manualEntry = ""
5794
}
5895
}
5996
}

0 commit comments

Comments
 (0)