Skip to content

Commit

Permalink
test: implement test for ui error
Browse files Browse the repository at this point in the history
  • Loading branch information
lipej committed Apr 29, 2024
1 parent 9f95e77 commit 1318446
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 102 deletions.
16 changes: 8 additions & 8 deletions SearchEmptyState.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
3457BCFB2BDFDC530082C060 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3457BCFA2BDFDC530082C060 /* Assets.xcassets */; };
3457BCFE2BDFDC530082C060 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3457BCFD2BDFDC530082C060 /* Preview Assets.xcassets */; };
3457BD082BDFDC540082C060 /* SearchEmptyStateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3457BD072BDFDC540082C060 /* SearchEmptyStateTests.swift */; };
3457BD122BDFDC540082C060 /* SearchEmptyStateUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3457BD112BDFDC540082C060 /* SearchEmptyStateUITests.swift */; };
3457BD142BDFDC540082C060 /* SearchEmptyStateUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3457BD132BDFDC540082C060 /* SearchEmptyStateUITestsLaunchTests.swift */; };
34B5305A2BE0143700C5D766 /* SearchEmptyStateUITestsSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34B530592BE0143700C5D766 /* SearchEmptyStateUITestsSearchTests.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -42,8 +41,7 @@
3457BD032BDFDC540082C060 /* SearchEmptyStateTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SearchEmptyStateTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3457BD072BDFDC540082C060 /* SearchEmptyStateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchEmptyStateTests.swift; sourceTree = "<group>"; };
3457BD0D2BDFDC540082C060 /* SearchEmptyStateUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SearchEmptyStateUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
3457BD112BDFDC540082C060 /* SearchEmptyStateUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchEmptyStateUITests.swift; sourceTree = "<group>"; };
3457BD132BDFDC540082C060 /* SearchEmptyStateUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchEmptyStateUITestsLaunchTests.swift; sourceTree = "<group>"; };
34B530592BE0143700C5D766 /* SearchEmptyStateUITestsSearchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchEmptyStateUITestsSearchTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -121,8 +119,7 @@
3457BD102BDFDC540082C060 /* SearchEmptyStateUITests */ = {
isa = PBXGroup;
children = (
3457BD112BDFDC540082C060 /* SearchEmptyStateUITests.swift */,
3457BD132BDFDC540082C060 /* SearchEmptyStateUITestsLaunchTests.swift */,
34B530592BE0143700C5D766 /* SearchEmptyStateUITestsSearchTests.swift */,
);
path = SearchEmptyStateUITests;
sourceTree = "<group>";
Expand Down Expand Up @@ -202,6 +199,7 @@
};
3457BD0C2BDFDC540082C060 = {
CreatedOnToolsVersion = 15.3;
LastSwiftMigration = 1530;
TestTargetID = 3457BCF22BDFDC520082C060;
};
};
Expand Down Expand Up @@ -274,8 +272,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3457BD142BDFDC540082C060 /* SearchEmptyStateUITestsLaunchTests.swift in Sources */,
3457BD122BDFDC540082C060 /* SearchEmptyStateUITests.swift in Sources */,
34B5305A2BE0143700C5D766 /* SearchEmptyStateUITestsSearchTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -518,6 +515,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
Expand All @@ -527,6 +525,7 @@
PRODUCT_BUNDLE_IDENTIFIER = tech.lipejose.SearchEmptyStateUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_TARGET_NAME = SearchEmptyState;
Expand All @@ -537,6 +536,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
Expand Down

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions SearchEmptyState/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct ContentView: View {
List(filteredWizards, id: \.self) {
wizard in Text(wizard)
}
.searchable(text: $searchTerm)
.searchable(text: $searchTerm, prompt: "Search a Wizard")
.overlay {
if filteredWizards.isEmpty {
ContentUnavailableView(label: {
Expand All @@ -33,7 +33,7 @@ struct ContentView: View {
Text("No Wizards").bold()
}
}, description: {
Text("No wizards was found with: \(searchTerm), maybe you're looking for a muggle?")
Text("No wizards was found with: \(searchTerm), maybe you're looking for a muggle?").accessibilityIdentifier("ResultError")
}
)
}
Expand Down
41 changes: 0 additions & 41 deletions SearchEmptyStateUITests/SearchEmptyStateUITests.swift

This file was deleted.

32 changes: 0 additions & 32 deletions SearchEmptyStateUITests/SearchEmptyStateUITestsLaunchTests.swift

This file was deleted.

38 changes: 38 additions & 0 deletions SearchEmptyStateUITests/SearchEmptyStateUITestsSearchTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// SearchEmptyStateUITestsSearchTests.swift
// SearchEmptyStateUITests
//
// Created by Felipe José on 29/04/24.
//

import XCTest

final class SearchEmptyStateUITestsSearchTests: XCTestCase {

override class var runsForEachTargetApplicationUIConfiguration: Bool {
false
}

var app: XCUIApplication!

override func setUpWithError() throws {
continueAfterFailure = false
app = XCUIApplication()
app.launch()
app.swipeDown()
}


func testErrorMessage() throws {
let searchTerm = "Testing"
let expectedResultErrorMessage = "No wizards was found with: \(searchTerm), maybe you're looking for a muggle?"
let search = app.searchFields["Search a Wizard"]

search.tap()
search.typeText(searchTerm)

let resultError = app.staticTexts["ResultError"]
XCTAssertTrue(resultError.isHittable)
XCTAssertEqual(resultError.label, expectedResultErrorMessage)
}
}

0 comments on commit 1318446

Please sign in to comment.