Skip to content

Fix UI test for ForEach bindings. #1933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Examples/Integration/Integration/ForEachBindingTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,30 @@ struct ForEachBindingTestCase: ReducerProtocol {
}

struct ForEachBindingTestCaseView: View {
@State var assertion: String?
let store: StoreOf<ForEachBindingTestCase>

var body: some View {
WithViewStore(self.store, observe: { $0 }) { viewStore in
VStack { // ⚠️ Must use VStack, not List.
if let assertion = self.assertion {
Text(assertion)
}
ForEach(Array(viewStore.values.enumerated()), id: \.offset) { offset, value in
HStack { // ⚠️ Must wrap in an HStack.
TextField( // ⚠️ Must use a TextField.
"\(value)",
text: viewStore.binding(
get: { $0.values[offset] },
get: {
if offset < $0.values.count {
return $0.values[offset]
} else {
DispatchQueue.main.async {
self.assertion = "🛑"
}
return ""
}
},
send: { .change(offset: offset, value: $0) }
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import XCTest
final class EscapedWithViewStoreTests: XCTestCase {

override func setUpWithError() throws {
continueAfterFailure = false
self.continueAfterFailure = false
}

func testExample() async throws {
Expand Down
16 changes: 13 additions & 3 deletions Examples/Integration/IntegrationUITests/ForEachBindingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import XCTest

@MainActor
final class ForEachBindingTests: XCTestCase {

override func setUpWithError() throws {
continueAfterFailure = false
self.continueAfterFailure = false
}

func testExample() async throws {
Expand All @@ -13,7 +12,18 @@ final class ForEachBindingTests: XCTestCase {

app.collectionViews.buttons["ForEachBindingTestCase"].tap()
app.buttons["Remove last"].tap()

XCTAssertFalse(app.textFields["C"].exists)
app.buttons["Remove last"].tap()
XCTAssertFalse(app.textFields["B"].exists)
app.buttons["Remove last"].tap()
XCTAssertFalse(app.textFields["A"].exists)

XCTExpectFailure("""
This ideally would not fail, but currently does. See this PR for more details:

https://github.com/pointfreeco/swift-composable-architecture/pull/1845
""") {
XCTAssertFalse(app.staticTexts["🛑"].exists)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import XCTest
@MainActor
final class NavigationStackBindingTests: XCTestCase {
override func setUpWithError() throws {
continueAfterFailure = false
self.continueAfterFailure = false
}

func testExample() async throws {
Expand Down
40 changes: 21 additions & 19 deletions Tests/ComposableArchitectureTests/ViewStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,27 +168,29 @@ final class ViewStoreTests: XCTestCase {
}

func testSendWhile() async {
enum Action {
case response
case tapped
}
let reducer = Reduce<Bool, Action> { state, action in
switch action {
case .response:
state = false
return .none
case .tapped:
state = true
return .task { .response }
await _withMainSerialExecutor {
enum Action {
case response
case tapped
}
let reducer = Reduce<Bool, Action> { state, action in
switch action {
case .response:
state = false
return .none
case .tapped:
state = true
return .task { .response }
}
}

let store = Store(initialState: false, reducer: reducer)
let viewStore = ViewStore(store, observe: { $0 })

XCTAssertEqual(viewStore.state, false)
await viewStore.send(.tapped, while: { $0 })
XCTAssertEqual(viewStore.state, false)
}

let store = Store(initialState: false, reducer: reducer)
let viewStore = ViewStore(store, observe: { $0 })

XCTAssertEqual(viewStore.state, false)
await viewStore.send(.tapped, while: { $0 })
XCTAssertEqual(viewStore.state, false)
}

func testSuspend() {
Expand Down