Skip to content

Commit dbb69be

Browse files
committed
KeyboardFrameObserver: Add failing test for unexpected notifications
1 parent 928c230 commit dbb69be

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

WooCommerce/WooCommerceTests/ViewRelated/Keyboard/KeyboardFrameObserverTests.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,31 @@ final class KeyboardFrameObserverTests: XCTestCase {
101101
waitForExpectations(timeout: 0.1)
102102
}
103103

104+
func testItWillNotEmitNewEventsWhenItIsDeallocated() {
105+
// Arrange
106+
let notificationCenter = NotificationCenter()
107+
108+
var eventsLogged = 0
109+
var keyboardFrameObserver: KeyboardFrameObserver? = KeyboardFrameObserver(notificationCenter: notificationCenter) { _ in
110+
eventsLogged += 1
111+
}
112+
113+
keyboardFrameObserver?.startObservingKeyboardFrame()
114+
115+
// These should be logged
116+
notificationCenter.postKeyboardWillShowNotification(keyboardFrame: CGRect(x: 1, y: 1, width: 1, height: 1))
117+
notificationCenter.postKeyboardWillShowNotification(keyboardFrame: CGRect(x: 2, y: 2, width: 2, height: 2))
118+
119+
// Act
120+
keyboardFrameObserver = nil
121+
122+
// This should not be logged anymore
123+
notificationCenter.postKeyboardWillShowNotification(keyboardFrame: CGRect(x: 3, y: 3, width: 3, height: 3))
124+
125+
// Assert
126+
XCTAssertEqual(eventsLogged, 2)
127+
}
128+
104129
func testItCanSendInitialEvents() {
105130
// Arrange
106131
let expectedKeyboardState = KeyboardState(

0 commit comments

Comments
 (0)