This repository has been archived by the owner on Aug 13, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: respect updates to placeholder and callbacks
Fixes #9
- Loading branch information
1 parent
37485cd
commit e1ad0ac
Showing
6 changed files
with
140 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import SwiftUI | ||
|
||
struct CallbackUpdateTest: View { | ||
@State | ||
var searchString = "" | ||
|
||
@State | ||
var doSearchTxt = "a" | ||
@State | ||
var doCancelTxt = "b" | ||
|
||
@State | ||
var doSearch = { } | ||
@State | ||
var doCancel = { } | ||
|
||
var body: some View { | ||
List { | ||
Button(action: { | ||
self.doSearch = { self.doSearchTxt = "1: \(Date().timeIntervalSince1970)" } | ||
self.doCancel = { self.doCancelTxt = "2: \(Date().timeIntervalSince1970)" } | ||
}) { | ||
Text("Update callbacks") | ||
.foregroundColor(.accentColor) | ||
} | ||
.accessibility(identifier: "callbacks button") | ||
|
||
Text(doSearchTxt) | ||
.accessibility(identifier: "do search text") | ||
Text(doCancelTxt) | ||
.accessibility(identifier: "do cancel text") | ||
} | ||
.navigationBarTitle("Callback Update Test") | ||
.navigationBarSearch($searchString, cancelClicked: doCancel, searchClicked: doSearch) | ||
} | ||
} | ||
|
||
struct CallbackUpdateTest_Previews: PreviewProvider { | ||
static var previews: some View { | ||
CallbackUpdateTest() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import SwiftUI | ||
|
||
struct PlaceholderTest: View { | ||
@State | ||
var searchString = "" | ||
@State | ||
var placeholder = "" | ||
|
||
var body: some View { | ||
List { | ||
Button(action: { | ||
self.placeholder = "\(Date().timeIntervalSince1970)" | ||
}) { | ||
Text("Update placeholder") | ||
.foregroundColor(.accentColor) | ||
} | ||
.accessibility(identifier: "placeholder button") | ||
|
||
Text("Expected placeholder: '\(placeholder)'") | ||
} | ||
.navigationBarTitle("Placeholder Test") | ||
.navigationBarSearch($searchString, placeholder: placeholder) | ||
} | ||
} | ||
|
||
struct PlaceholderTest_Previews: PreviewProvider { | ||
static var previews: some View { | ||
PlaceholderTest() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import XCTest | ||
|
||
class CallbackUpdateTests: UITest { | ||
func testCallbackUpdate() throws { | ||
// Setup test state. | ||
selectTest("Callback Update") | ||
app.children(matching: .any).firstMatch.slowSwipeDown(offset: 0.5, distance: 0.1) | ||
|
||
// Ensure the searchbar exists. | ||
let navBar = app.navigationBars.firstMatch | ||
XCTAssertTrue(navBar.children(matching: .searchField).firstMatch.exists, "Searchbar exists") | ||
let searchBar = navBar.children(matching: .searchField).firstMatch | ||
|
||
// Test that changing the callbacks actually works. | ||
let searchVal = app.staticTexts["do search text"].label | ||
let cancelVal = app.staticTexts["do cancel text"].label | ||
|
||
app.buttons["callbacks button"].tap() | ||
|
||
searchBar.tap() | ||
searchBar.typeText("hello") | ||
app.keyboards.buttons["search"].tap() | ||
XCTAssertNotEqual(searchVal, app.staticTexts["do search text"].label, "search callback updated") | ||
|
||
navBar.buttons["Cancel"].tap() | ||
XCTAssertNotEqual(cancelVal, app.staticTexts["do cancel text"].label, "cancel callback updated") | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import XCTest | ||
|
||
class PlaceholderTests: UITest { | ||
func testPlaceholder() throws { | ||
// Setup test state. | ||
selectTest("Placeholder") | ||
app.children(matching: .any).firstMatch.slowSwipeDown(offset: 0.5, distance: 0.1) | ||
|
||
// Ensure the searchbar exists. | ||
XCTAssertTrue(app.navigationBars.firstMatch.children(matching: .searchField).firstMatch.exists, "Searchbar exists") | ||
let searchBar = app.navigationBars.firstMatch.children(matching: .searchField).firstMatch | ||
|
||
// Test that tapping the button changes the placeholder text. | ||
let value = searchBar.placeholderValue | ||
app.buttons["placeholder button"].tap() | ||
XCTAssertNotEqual(value, searchBar.placeholderValue, "placeholder text updated") | ||
} | ||
} |