Skip to content

Commit a65b61b

Browse files
committed
test: add a UI test proving the issue118
1 parent 101b51c commit a65b61b

File tree

4 files changed

+220
-3
lines changed

4 files changed

+220
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import SwiftUI
2+
import iPhoneNumberField
3+
4+
struct Issue118: View {
5+
@State private var phoneNumber = ""
6+
@State private var selectedCountry: String = "US"
7+
8+
var body: some View {
9+
iPhoneNumberField("Phone Number", text: $phoneNumber)
10+
.flagSelectable(true)
11+
.defaultRegion(selectedCountry)
12+
.formatted(true)
13+
.prefixHidden(false)
14+
.flagHidden(false)
15+
}
16+
}
17+
18+
#Preview {
19+
Issue118()
20+
.padding()
21+
}

Demo/MultiplatformDemo/MultiplatformDemoApp.swift

+11-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,19 @@ import SwiftUI
99

1010
@main
1111
struct MultiplatformDemoApp: App {
12+
private let issue: String?
13+
14+
init() {
15+
let argument = ProcessInfo.processInfo.arguments.first { $0.hasPrefix("UIT-GHI-") }
16+
self.issue = argument?.split(separator: "-").map(String.init).last
17+
}
18+
1219
var body: some Scene {
1320
WindowGroup {
14-
ContentView()
21+
switch issue {
22+
case "118": Issue118()
23+
default: ContentView()
24+
}
1525
}
1626
}
1727
}

Demo/iPhoneNumberFieldDemo.xcodeproj/project.pbxproj

+143-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 56;
6+
objectVersion = 70;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -12,8 +12,19 @@
1212
2AA44DCB28A11688001BF8F0 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2AA44DCA28A11688001BF8F0 /* Assets.xcassets */; };
1313
2AA44DCF28A11688001BF8F0 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2AA44DCE28A11688001BF8F0 /* Preview Assets.xcassets */; };
1414
2AA44DD928A116D8001BF8F0 /* iPhoneNumberField in Frameworks */ = {isa = PBXBuildFile; productRef = 2AA44DD828A116D8001BF8F0 /* iPhoneNumberField */; };
15+
2AD9C8152D6F21E4008B6062 /* issue118.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AD9C8142D6F21E4008B6062 /* issue118.swift */; };
1516
/* End PBXBuildFile section */
1617

18+
/* Begin PBXContainerItemProxy section */
19+
2AD9C8212D6F2321008B6062 /* PBXContainerItemProxy */ = {
20+
isa = PBXContainerItemProxy;
21+
containerPortal = 2AA44DBB28A11687001BF8F0 /* Project object */;
22+
proxyType = 1;
23+
remoteGlobalIDString = 2AA44DC228A11687001BF8F0;
24+
remoteInfo = iPhoneNumberFieldDemo;
25+
};
26+
/* End PBXContainerItemProxy section */
27+
1728
/* Begin PBXFileReference section */
1829
2AA44DC328A11687001BF8F0 /* iPhoneNumberFieldDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iPhoneNumberFieldDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
1930
2AA44DC628A11687001BF8F0 /* MultiplatformDemoApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiplatformDemoApp.swift; sourceTree = "<group>"; };
@@ -22,8 +33,14 @@
2233
2AA44DCC28A11688001BF8F0 /* MultiplatformDemo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MultiplatformDemo.entitlements; sourceTree = "<group>"; };
2334
2AA44DCE28A11688001BF8F0 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
2435
2AA44DD628A11699001BF8F0 /* iPhoneNumberField */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = iPhoneNumberField; path = ..; sourceTree = "<group>"; };
36+
2AD9C8142D6F21E4008B6062 /* issue118.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = issue118.swift; sourceTree = "<group>"; };
37+
2AD9C81B2D6F2321008B6062 /* iPhoneNumberFieldDemoUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = iPhoneNumberFieldDemoUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
2538
/* End PBXFileReference section */
2639

40+
/* Begin PBXFileSystemSynchronizedRootGroup section */
41+
2AD9C81C2D6F2321008B6062 /* iPhoneNumberFieldDemoUITests */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = iPhoneNumberFieldDemoUITests; sourceTree = "<group>"; };
42+
/* End PBXFileSystemSynchronizedRootGroup section */
43+
2744
/* Begin PBXFrameworksBuildPhase section */
2845
2AA44DC028A11687001BF8F0 /* Frameworks */ = {
2946
isa = PBXFrameworksBuildPhase;
@@ -33,6 +50,13 @@
3350
);
3451
runOnlyForDeploymentPostprocessing = 0;
3552
};
53+
2AD9C8182D6F2321008B6062 /* Frameworks */ = {
54+
isa = PBXFrameworksBuildPhase;
55+
buildActionMask = 2147483647;
56+
files = (
57+
);
58+
runOnlyForDeploymentPostprocessing = 0;
59+
};
3660
/* End PBXFrameworksBuildPhase section */
3761

3862
/* Begin PBXGroup section */
@@ -41,6 +65,7 @@
4165
children = (
4266
2AA44DD528A11699001BF8F0 /* Packages */,
4367
2AA44DC528A11687001BF8F0 /* MultiplatformDemo */,
68+
2AD9C81C2D6F2321008B6062 /* iPhoneNumberFieldDemoUITests */,
4469
2AA44DC428A11687001BF8F0 /* Products */,
4570
2AA44DD728A116D8001BF8F0 /* Frameworks */,
4671
);
@@ -50,6 +75,7 @@
5075
isa = PBXGroup;
5176
children = (
5277
2AA44DC328A11687001BF8F0 /* iPhoneNumberFieldDemo.app */,
78+
2AD9C81B2D6F2321008B6062 /* iPhoneNumberFieldDemoUITests.xctest */,
5379
);
5480
name = Products;
5581
sourceTree = "<group>";
@@ -59,6 +85,7 @@
5985
children = (
6086
2AA44DC628A11687001BF8F0 /* MultiplatformDemoApp.swift */,
6187
2AA44DC828A11687001BF8F0 /* ContentView.swift */,
88+
2AD9C8162D6F222C008B6062 /* GitHubIssues */,
6289
2AA44DCA28A11688001BF8F0 /* Assets.xcassets */,
6390
2AA44DCC28A11688001BF8F0 /* MultiplatformDemo.entitlements */,
6491
2AA44DCD28A11688001BF8F0 /* Preview Content */,
@@ -89,6 +116,14 @@
89116
name = Frameworks;
90117
sourceTree = "<group>";
91118
};
119+
2AD9C8162D6F222C008B6062 /* GitHubIssues */ = {
120+
isa = PBXGroup;
121+
children = (
122+
2AD9C8142D6F21E4008B6062 /* issue118.swift */,
123+
);
124+
path = GitHubIssues;
125+
sourceTree = "<group>";
126+
};
92127
/* End PBXGroup section */
93128

94129
/* Begin PBXNativeTarget section */
@@ -112,19 +147,46 @@
112147
productReference = 2AA44DC328A11687001BF8F0 /* iPhoneNumberFieldDemo.app */;
113148
productType = "com.apple.product-type.application";
114149
};
150+
2AD9C81A2D6F2321008B6062 /* iPhoneNumberFieldDemoUITests */ = {
151+
isa = PBXNativeTarget;
152+
buildConfigurationList = 2AD9C8232D6F2321008B6062 /* Build configuration list for PBXNativeTarget "iPhoneNumberFieldDemoUITests" */;
153+
buildPhases = (
154+
2AD9C8172D6F2321008B6062 /* Sources */,
155+
2AD9C8182D6F2321008B6062 /* Frameworks */,
156+
2AD9C8192D6F2321008B6062 /* Resources */,
157+
);
158+
buildRules = (
159+
);
160+
dependencies = (
161+
2AD9C8222D6F2321008B6062 /* PBXTargetDependency */,
162+
);
163+
fileSystemSynchronizedGroups = (
164+
2AD9C81C2D6F2321008B6062 /* iPhoneNumberFieldDemoUITests */,
165+
);
166+
name = iPhoneNumberFieldDemoUITests;
167+
packageProductDependencies = (
168+
);
169+
productName = iPhoneNumberFieldDemoUITests;
170+
productReference = 2AD9C81B2D6F2321008B6062 /* iPhoneNumberFieldDemoUITests.xctest */;
171+
productType = "com.apple.product-type.bundle.ui-testing";
172+
};
115173
/* End PBXNativeTarget section */
116174

117175
/* Begin PBXProject section */
118176
2AA44DBB28A11687001BF8F0 /* Project object */ = {
119177
isa = PBXProject;
120178
attributes = {
121179
BuildIndependentTargetsInParallel = 1;
122-
LastSwiftUpdateCheck = 1400;
180+
LastSwiftUpdateCheck = 1620;
123181
LastUpgradeCheck = 1400;
124182
TargetAttributes = {
125183
2AA44DC228A11687001BF8F0 = {
126184
CreatedOnToolsVersion = 14.0;
127185
};
186+
2AD9C81A2D6F2321008B6062 = {
187+
CreatedOnToolsVersion = 16.2;
188+
TestTargetID = 2AA44DC228A11687001BF8F0;
189+
};
128190
};
129191
};
130192
buildConfigurationList = 2AA44DBE28A11687001BF8F0 /* Build configuration list for PBXProject "iPhoneNumberFieldDemo" */;
@@ -141,6 +203,7 @@
141203
projectRoot = "";
142204
targets = (
143205
2AA44DC228A11687001BF8F0 /* iPhoneNumberFieldDemo */,
206+
2AD9C81A2D6F2321008B6062 /* iPhoneNumberFieldDemoUITests */,
144207
);
145208
};
146209
/* End PBXProject section */
@@ -155,6 +218,13 @@
155218
);
156219
runOnlyForDeploymentPostprocessing = 0;
157220
};
221+
2AD9C8192D6F2321008B6062 /* Resources */ = {
222+
isa = PBXResourcesBuildPhase;
223+
buildActionMask = 2147483647;
224+
files = (
225+
);
226+
runOnlyForDeploymentPostprocessing = 0;
227+
};
158228
/* End PBXResourcesBuildPhase section */
159229

160230
/* Begin PBXSourcesBuildPhase section */
@@ -164,11 +234,27 @@
164234
files = (
165235
2AA44DC928A11687001BF8F0 /* ContentView.swift in Sources */,
166236
2AA44DC728A11687001BF8F0 /* MultiplatformDemoApp.swift in Sources */,
237+
2AD9C8152D6F21E4008B6062 /* issue118.swift in Sources */,
238+
);
239+
runOnlyForDeploymentPostprocessing = 0;
240+
};
241+
2AD9C8172D6F2321008B6062 /* Sources */ = {
242+
isa = PBXSourcesBuildPhase;
243+
buildActionMask = 2147483647;
244+
files = (
167245
);
168246
runOnlyForDeploymentPostprocessing = 0;
169247
};
170248
/* End PBXSourcesBuildPhase section */
171249

250+
/* Begin PBXTargetDependency section */
251+
2AD9C8222D6F2321008B6062 /* PBXTargetDependency */ = {
252+
isa = PBXTargetDependency;
253+
target = 2AA44DC228A11687001BF8F0 /* iPhoneNumberFieldDemo */;
254+
targetProxy = 2AD9C8212D6F2321008B6062 /* PBXContainerItemProxy */;
255+
};
256+
/* End PBXTargetDependency section */
257+
172258
/* Begin XCBuildConfiguration section */
173259
2AA44DD028A11688001BF8F0 /* Debug */ = {
174260
isa = XCBuildConfiguration;
@@ -351,6 +437,52 @@
351437
};
352438
name = Release;
353439
};
440+
2AD9C8242D6F2321008B6062 /* Debug */ = {
441+
isa = XCBuildConfiguration;
442+
buildSettings = {
443+
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
444+
CODE_SIGN_STYLE = Automatic;
445+
CURRENT_PROJECT_VERSION = 1;
446+
ENABLE_USER_SCRIPT_SANDBOXING = YES;
447+
GCC_C_LANGUAGE_STANDARD = gnu17;
448+
GENERATE_INFOPLIST_FILE = YES;
449+
IPHONEOS_DEPLOYMENT_TARGET = 18.2;
450+
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
451+
MARKETING_VERSION = 1.0;
452+
PRODUCT_BUNDLE_IDENTIFIER = com.example.iphonetextfield.demo.uitests;
453+
PRODUCT_NAME = "$(TARGET_NAME)";
454+
SDKROOT = iphoneos;
455+
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
456+
SWIFT_EMIT_LOC_STRINGS = NO;
457+
SWIFT_VERSION = 5.0;
458+
TARGETED_DEVICE_FAMILY = "1,2";
459+
TEST_TARGET_NAME = iPhoneNumberFieldDemo;
460+
};
461+
name = Debug;
462+
};
463+
2AD9C8252D6F2321008B6062 /* Release */ = {
464+
isa = XCBuildConfiguration;
465+
buildSettings = {
466+
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
467+
CODE_SIGN_STYLE = Automatic;
468+
CURRENT_PROJECT_VERSION = 1;
469+
ENABLE_USER_SCRIPT_SANDBOXING = YES;
470+
GCC_C_LANGUAGE_STANDARD = gnu17;
471+
GENERATE_INFOPLIST_FILE = YES;
472+
IPHONEOS_DEPLOYMENT_TARGET = 18.2;
473+
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
474+
MARKETING_VERSION = 1.0;
475+
PRODUCT_BUNDLE_IDENTIFIER = com.example.iphonetextfield.demo.uitests;
476+
PRODUCT_NAME = "$(TARGET_NAME)";
477+
SDKROOT = iphoneos;
478+
SWIFT_EMIT_LOC_STRINGS = NO;
479+
SWIFT_VERSION = 5.0;
480+
TARGETED_DEVICE_FAMILY = "1,2";
481+
TEST_TARGET_NAME = iPhoneNumberFieldDemo;
482+
VALIDATE_PRODUCT = YES;
483+
};
484+
name = Release;
485+
};
354486
/* End XCBuildConfiguration section */
355487

356488
/* Begin XCConfigurationList section */
@@ -372,6 +504,15 @@
372504
defaultConfigurationIsVisible = 0;
373505
defaultConfigurationName = Release;
374506
};
507+
2AD9C8232D6F2321008B6062 /* Build configuration list for PBXNativeTarget "iPhoneNumberFieldDemoUITests" */ = {
508+
isa = XCConfigurationList;
509+
buildConfigurations = (
510+
2AD9C8242D6F2321008B6062 /* Debug */,
511+
2AD9C8252D6F2321008B6062 /* Release */,
512+
);
513+
defaultConfigurationIsVisible = 0;
514+
defaultConfigurationName = Release;
515+
};
375516
/* End XCConfigurationList section */
376517

377518
/* Begin XCSwiftPackageProductDependency section */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// iPhoneNumberFieldDemoUITests.swift
3+
// iPhoneNumberFieldDemoUITests
4+
//
5+
// Created by Seyed Mojtaba Hosseini Zeidabadi on 2/26/25.
6+
//
7+
8+
import XCTest
9+
10+
final class iPhoneNumberFieldDemoUITests: XCTestCase {
11+
12+
func testIssue118() throws {
13+
let app = XCUIApplication()
14+
app.launchArguments.append("UIT-GHI-118")
15+
app.launch()
16+
17+
let usFlag = "🇺🇸"
18+
let expectedFlag = "🇦🇫"
19+
20+
// I have set up the iPhoneNumberField like:
21+
// @State private var selectedCountry: String = "US"
22+
let selectYourCountryCodeButton = app.buttons["Select your country code"]
23+
let countryFlag = selectYourCountryCodeButton.staticTexts.firstMatch
24+
XCTAssert(countryFlag.label.contains(usFlag), "Expected US flag")
25+
26+
// When I change the country flag
27+
selectYourCountryCodeButton.tap()
28+
29+
// Find and tap the Afghanistan entry using the flag
30+
let allStaticTexts = app.tables.staticTexts.allElementsBoundByIndex
31+
let expectedEntry = try XCTUnwrap(allStaticTexts.first { $0.label.contains(expectedFlag) })
32+
expectedEntry.tap()
33+
34+
XCTAssert(countryFlag.label.contains(expectedFlag), "Expected another flag")
35+
36+
// And begin to type in a phone number
37+
app.textFields["Phone Number"].tap()
38+
app.keys["1"].tap()
39+
app.keys["2"].tap()
40+
app.keys["3"].tap()
41+
42+
// the flag just reverts back to US (unexpected).
43+
XCTAssert(countryFlag.label.contains(expectedFlag), "Expected the flag to stay the same")
44+
}
45+
}

0 commit comments

Comments
 (0)