Files
swift-composable-architectu…/Examples/Integration/IntegrationUITests/Legacy/LegacyNavigationTests.swift
Stephen Celis f02fab5000 Allow an alert to present another alert (#3309)
* Allow an alert to present another alert

When we added support for vanilla SwiftUI modifiers, we lost the ability
to present one alert after another because `nil` writes to the alert
bindings unconditionally dismissed the feature, even if the feature was
freshly presented.

This fixes things by suppressing dismissal when the identity of a
presented item has changed.

Fix #3272.

* wip
2024-08-26 15:19:08 -07:00

101 lines
3.6 KiB
Swift

import Integration
import TestCases
import XCTest
final class LegacyNavigationTests: BaseIntegrationTests {
@MainActor
override func setUpWithError() throws {
try super.setUpWithError()
self.app.buttons["Legacy"].tap()
self.app.buttons[TestCase.Legacy.navigationStack.rawValue].tap()
}
@MainActor
func testChildLogic() {
self.app.buttons["Go to counter"].tap()
XCTAssertEqual(self.app.staticTexts["0"].exists, true)
self.app.buttons["Increment"].tap()
XCTAssertEqual(self.app.staticTexts["1"].exists, true)
self.app.buttons["Decrement"].tap()
XCTAssertEqual(self.app.staticTexts["0"].exists, true)
}
@MainActor
func testPushAndDismiss() {
XCTAssertEqual(self.app.staticTexts["Root"].exists, true)
self.app.buttons["Go to counter"].tap()
XCTAssertEqual(self.app.staticTexts["0"].find().exists, true)
self.app.buttons["Increment"].tap()
XCTAssertEqual(self.app.staticTexts["1"].find().exists, true)
self.app.buttons["Go to counter: 1"].tap()
XCTAssertEqual(self.app.staticTexts["1"].find().exists, true)
self.app.buttons["Increment"].tap()
XCTAssertEqual(self.app.staticTexts["2"].find().exists, true)
self.app.buttons["Go to counter: 2"].tap()
XCTAssertEqual(self.app.staticTexts["2"].find().exists, true)
self.app.buttons["Increment"].tap()
XCTAssertEqual(self.app.staticTexts["3"].find().exists, true)
self.app.buttons["Dismiss"].tap()
XCTAssertEqual(self.app.staticTexts["2"].find().exists, true)
self.app.buttons["Dismiss"].tap()
XCTAssertEqual(self.app.staticTexts["1"].find().exists, true)
self.app.buttons["Dismiss"].tap()
XCTAssertEqual(self.app.staticTexts["Root"].find().exists, true)
}
@MainActor
func testPopToRoot() {
XCTAssertEqual(self.app.staticTexts["Root"].exists, true)
self.app.buttons["Go to counter"].tap()
XCTAssertEqual(self.app.staticTexts["0"].exists, true)
self.app.buttons["Increment"].tap()
XCTAssertEqual(self.app.staticTexts["1"].exists, true)
self.app.buttons["Go to counter: 1"].tap()
XCTAssertEqual(self.app.staticTexts["1"].exists, true)
self.app.buttons["Increment"].tap()
XCTAssertEqual(self.app.staticTexts["2"].exists, true)
self.app.buttons["Go to counter: 2"].tap()
XCTAssertEqual(self.app.staticTexts["2"].exists, true)
self.app.buttons["Increment"].tap()
XCTAssertEqual(self.app.staticTexts["3"].exists, true)
self.app.buttons["Pop to root"].tap()
XCTAssertEqual(self.app.staticTexts["Root"].exists, true)
}
@MainActor
func testChildEffectsCancelOnDismiss() {
self.app.buttons["Go to counter"].tap()
self.app.buttons["Run effect"].tap()
self.app.buttons["Root"].tap()
XCTAssertEqual(
self.app.staticTexts["Child response: 1"].waitForExistence(timeout: 3),
false
)
}
@MainActor
func testChildViewIdentity() {
self.app.buttons["Go to counter"].tap()
XCTAssertEqual(self.app.staticTexts["Has appeared"].exists, true)
self.app.buttons["Recreate stack"].tap()
XCTAssertEqual(self.app.staticTexts["Has appeared"].exists, true)
}
@MainActor
func testSimultaneousDismissAlertAndPop() async throws {
self.app.buttons["Go to counter"].tap()
self.app.buttons["Show alert"].tap()
self.app.buttons["Parent pops feature"].tap()
try await Task.sleep(for: .seconds(1))
XCTAssertEqual(self.app.staticTexts["What do you want to do?"].exists, false)
try await Task.sleep(for: .seconds(1))
}
@MainActor
func testNavigationDestination() async throws {
self.app.buttons["Go to counter"].tap()
self.app.buttons["Open navigation destination"].tap()
XCTAssert(self.app.staticTexts["Destination"].exists)
}
}