Skip to content

Commit f238507

Browse files
committed
Merge pull request #92 from neilpa/datepicker
Disable broken UIDatePicker test
2 parents 4d193b2 + e15714d commit f238507

File tree

3 files changed

+89
-4
lines changed

3 files changed

+89
-4
lines changed

Rex.xcodeproj/project.pbxproj

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
8295FD871B87309F007C9000 /* UIControlTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8295FD851B873081007C9000 /* UIControlTests.swift */; };
1616
8295FD8A1B87352D007C9000 /* UIButtonTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8295FD881B873490007C9000 /* UIButtonTests.swift */; };
1717
8295FD8D1B87374A007C9000 /* UIBarButtonItemTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8295FD8B1B873748007C9000 /* UIBarButtonItemTests.swift */; };
18+
9DA915A41CA6301C003723B9 /* UIDatePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DA915A31CA6301C003723B9 /* UIDatePicker.swift */; };
19+
9DA915A61CA63046003723B9 /* UIDatePickerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9DA915A51CA63046003723B9 /* UIDatePickerTests.swift */; };
1820
C7932E831C4B3F3000086F3C /* UITextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7932E811C4B3EDB00086F3C /* UITextField.swift */; };
1921
C7932E841C4B41E100086F3C /* UITextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7932E811C4B3EDB00086F3C /* UITextField.swift */; };
2022
C7932E871C4B42F500086F3C /* UITextFieldTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7932E851C4B420A00086F3C /* UITextFieldTests.swift */; };
@@ -178,6 +180,8 @@
178180
8295FD851B873081007C9000 /* UIControlTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIControlTests.swift; sourceTree = "<group>"; };
179181
8295FD881B873490007C9000 /* UIButtonTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIButtonTests.swift; sourceTree = "<group>"; };
180182
8295FD8B1B873748007C9000 /* UIBarButtonItemTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIBarButtonItemTests.swift; sourceTree = "<group>"; };
183+
9DA915A31CA6301C003723B9 /* UIDatePicker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIDatePicker.swift; sourceTree = "<group>"; };
184+
9DA915A51CA63046003723B9 /* UIDatePickerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIDatePickerTests.swift; sourceTree = "<group>"; };
181185
C7932E811C4B3EDB00086F3C /* UITextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITextField.swift; sourceTree = "<group>"; };
182186
C7932E851C4B420A00086F3C /* UITextFieldTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITextFieldTests.swift; sourceTree = "<group>"; };
183187
D8003E921AFEC3D400D7D3C5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -386,10 +390,11 @@
386390
5173EBC51B625A2600C9B48E /* UIBarItem.swift */,
387391
D86FFBDC1B34B691001A89B3 /* UIButton.swift */,
388392
D86FFBD41B34B0FE001A89B3 /* UIControl.swift */,
389-
D86FFBD71B34B242001A89B3 /* UILabel.swift */,
393+
9DA915A31CA6301C003723B9 /* UIDatePicker.swift */,
390394
8289A2E21BD7EF740097FB60 /* UIImageView.swift */,
391-
8289A2E41BD7F6DD0097FB60 /* UIView.swift */,
395+
D86FFBD71B34B242001A89B3 /* UILabel.swift */,
392396
C7932E811C4B3EDB00086F3C /* UITextField.swift */,
397+
8289A2E41BD7F6DD0097FB60 /* UIView.swift */,
393398
);
394399
path = UIKit;
395400
sourceTree = "<group>";
@@ -421,10 +426,11 @@
421426
8295FD8B1B873748007C9000 /* UIBarButtonItemTests.swift */,
422427
8295FD881B873490007C9000 /* UIButtonTests.swift */,
423428
8295FD851B873081007C9000 /* UIControlTests.swift */,
424-
D8F073141B861B3A0047D546 /* UILabelTests.swift */,
429+
9DA915A51CA63046003723B9 /* UIDatePickerTests.swift */,
425430
8289A2E01BD7EF1F0097FB60 /* UIImageViewTests.swift */,
426-
8289A2E61BD7F7730097FB60 /* UIViewTests.swift */,
431+
D8F073141B861B3A0047D546 /* UILabelTests.swift */,
427432
C7932E851C4B420A00086F3C /* UITextFieldTests.swift */,
433+
8289A2E61BD7F7730097FB60 /* UIViewTests.swift */,
428434
);
429435
path = UIKit;
430436
sourceTree = "<group>";
@@ -755,6 +761,7 @@
755761
isa = PBXSourcesBuildPhase;
756762
buildActionMask = 2147483647;
757763
files = (
764+
9DA915A41CA6301C003723B9 /* UIDatePicker.swift in Sources */,
758765
D86FFBD81B34B242001A89B3 /* UILabel.swift in Sources */,
759766
D86FFBDB1B34B3F0001A89B3 /* Action.swift in Sources */,
760767
D86FFBD21B34AD7A001A89B3 /* Association.swift in Sources */,
@@ -785,6 +792,7 @@
785792
C7932E871C4B42F500086F3C /* UITextFieldTests.swift in Sources */,
786793
8295FD8A1B87352D007C9000 /* UIButtonTests.swift in Sources */,
787794
D8A4540A1BD2772700C9E790 /* PropertyTests.swift in Sources */,
795+
9DA915A61CA63046003723B9 /* UIDatePickerTests.swift in Sources */,
788796
D83457301AFEE45E0070616A /* SignalProducerTests.swift in Sources */,
789797
D83457411AFEE6050070616A /* SignalTests.swift in Sources */,
790798
8295FD8D1B87374A007C9000 /* UIBarButtonItemTests.swift in Sources */,

Source/UIKit/UIDatePicker.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// UIDatePicker.swift
3+
// Rex
4+
//
5+
// Created by Guido Marucci Blas on 3/25/16.
6+
// Copyright © 2016 Neil Pankey. All rights reserved.
7+
//
8+
import UIKit
9+
import ReactiveCocoa
10+
11+
extension UIDatePicker {
12+
13+
public var rex_date: MutableProperty<NSDate> {
14+
let initial = { (picker: UIDatePicker) -> NSDate in
15+
picker.addTarget(self, action: "rex_changedDate", forControlEvents: .ValueChanged)
16+
return picker.date
17+
}
18+
return associatedProperty(self, key: &dateKey, initial: initial) { $0.date = $1 }
19+
}
20+
21+
@objc
22+
private func rex_changedDate() {
23+
rex_date.value = date
24+
}
25+
26+
}
27+
28+
private var dateKey: UInt8 = 0
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// UIDatePickerTests.swift
3+
// Rex
4+
//
5+
// Created by Guido Marucci Blas on 3/25/16.
6+
// Copyright © 2016 Neil Pankey. All rights reserved.
7+
//
8+
9+
import ReactiveCocoa
10+
import UIKit
11+
import XCTest
12+
import Rex
13+
14+
class UIDatePickerTests: XCTestCase {
15+
16+
var date: NSDate!
17+
var picker: UIDatePicker!
18+
19+
override func setUp() {
20+
let formatter = NSDateFormatter()
21+
formatter.dateFormat = "MM/dd/YYYY"
22+
date = formatter.dateFromString("11/29/1988")!
23+
24+
picker = UIDatePicker(frame: CGRectZero)
25+
}
26+
27+
func testUpdatePickerFromProperty() {
28+
picker.rex_date.value = date
29+
30+
XCTAssertEqual(picker.date, date)
31+
}
32+
33+
// FIXME Can this actually be made to work inside XCTest?
34+
func _testUpdatePropertyFromPicker() {
35+
let expectation = self.expectationWithDescription("Expected rex_date to send an event when picker's date value is changed by a UI event")
36+
defer { self.waitForExpectationsWithTimeout(2, handler: nil) }
37+
38+
picker.rex_date.signal.observeNext { changedDate in
39+
XCTAssertEqual(changedDate, self.date)
40+
expectation.fulfill()
41+
}
42+
43+
picker.date = date
44+
picker.enabled = true
45+
picker.userInteractionEnabled = true
46+
picker.sendActionsForControlEvents(.ValueChanged)
47+
}
48+
49+
}

0 commit comments

Comments
 (0)