Skip to content

Commit

Permalink
add delegate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DivineDominion authored and kzaher committed Jun 14, 2017
1 parent ea6c252 commit c0644c2
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Tests/RxCocoaTests/NSTextField+RxTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,47 @@ extension NSTextFieldTests {
let createView: () -> NSTextField = { NSTextField(frame: CGRect(x: 0, y: 0, width: 1, height: 1)) }
ensurePropertyDeallocated(createView, "a") { (view: NSTextField) in view.rx.text.orEmpty }
}

func testTextField_ControlTextDidChange_ForwardsToDelegates() {

var completed = false

autoreleasepool {
let textField = NSTextField()
let delegate = TextFieldDelegate()
textField.delegate = delegate
var rxDidChange = false

_ = textField.rx.text
.skip(1) // Initial value
.subscribe(onNext: { _ in
rxDidChange = true
}, onCompleted: {
completed = true
})

XCTAssertFalse(rxDidChange)
XCTAssertFalse(delegate.didChange)

let notification = Notification(
name: .NSControlTextDidChange,
object: textField,
userInfo: ["NSFieldEditor" : NSText()])
(textField.delegate as! NSObject).controlTextDidChange(notification)

XCTAssertTrue(rxDidChange)
XCTAssertTrue(delegate.didChange)
}

XCTAssertTrue(completed)
}

}

fileprivate final class TextFieldDelegate: NSObject, NSTextFieldDelegate {

var didChange = false
override func controlTextDidChange(_ notification: Notification) {
didChange = true
}
}

0 comments on commit c0644c2

Please sign in to comment.