Skip to content

Commit 411276d

Browse files
committed
Add CoreTests.test_statePublisher
1 parent c5da510 commit 411276d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

Tests/CoreTests.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Copyright 2018 the FloatingPanel authors. All rights reserved. MIT license.
22

33
import XCTest
4+
#if canImport(Combine)
5+
import Combine
6+
#endif
47
@testable import FloatingPanel
58

69
class CoreTests: XCTestCase {
@@ -1022,6 +1025,45 @@ class CoreTests: XCTestCase {
10221025
XCTAssertEqual(fpc.surfaceLocation(for: .full).y, fpc.surfaceLocation.y)
10231026
XCTAssertEqual(delegate.willAttract, false)
10241027
}
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+
}
10251067
}
10261068

10271069
private class FloatingPanelLayout3Positions: FloatingPanelTestLayout {

0 commit comments

Comments
 (0)