|
1 | 1 | // Copyright 2018 the FloatingPanel authors. All rights reserved. MIT license. |
2 | 2 |
|
3 | 3 | import XCTest |
| 4 | +#if canImport(Combine) |
| 5 | +import Combine |
| 6 | +#endif |
4 | 7 | @testable import FloatingPanel |
5 | 8 |
|
6 | 9 | class CoreTests: XCTestCase { |
@@ -1022,6 +1025,45 @@ class CoreTests: XCTestCase { |
1022 | 1025 | XCTAssertEqual(fpc.surfaceLocation(for: .full).y, fpc.surfaceLocation.y) |
1023 | 1026 | XCTAssertEqual(delegate.willAttract, false) |
1024 | 1027 | } |
| 1028 | + |
| 1029 | + @available(iOS 13.0, *) |
| 1030 | + func test_statePublisher() throws { |
| 1031 | + let fpc = FloatingPanelController() |
| 1032 | + fpc.showForTest() |
| 1033 | + |
| 1034 | + XCTAssertEqual(fpc.state, .half) |
| 1035 | + |
| 1036 | + // Verify statePublisher is available on iOS 13+ |
| 1037 | + XCTAssertNotNil(fpc.floatingPanel.statePublisher) |
| 1038 | + |
| 1039 | + var receivedStates: [FloatingPanelState] = [] |
| 1040 | + var cancellables = Set<AnyCancellable>() |
| 1041 | + |
| 1042 | + // Subscribe to statePublisher |
| 1043 | + fpc.floatingPanel.statePublisher? |
| 1044 | + .sink { state in |
| 1045 | + receivedStates.append(state) |
| 1046 | + } |
| 1047 | + .store(in: &cancellables) |
| 1048 | + |
| 1049 | + // The initial state should be emitted first |
| 1050 | + XCTAssertEqual(receivedStates, [.half]) |
| 1051 | + |
| 1052 | + // Move to .full |
| 1053 | + fpc.move(to: .full, animated: false) |
| 1054 | + XCTAssertEqual(fpc.state, .full) |
| 1055 | + XCTAssertEqual(receivedStates, [.half, .full]) |
| 1056 | + |
| 1057 | + // Move to .tip |
| 1058 | + fpc.move(to: .tip, animated: false) |
| 1059 | + XCTAssertEqual(fpc.state, .tip) |
| 1060 | + XCTAssertEqual(receivedStates, [.half, .full, .tip]) |
| 1061 | + |
| 1062 | + // Move back to .half |
| 1063 | + fpc.move(to: .half, animated: false) |
| 1064 | + XCTAssertEqual(fpc.state, .half) |
| 1065 | + XCTAssertEqual(receivedStates, [.half, .full, .tip, .half]) |
| 1066 | + } |
1025 | 1067 | } |
1026 | 1068 |
|
1027 | 1069 | private class FloatingPanelLayout3Positions: FloatingPanelTestLayout { |
|
0 commit comments