From ec3af04f296c355d54cd7036dc3f76914c5c5a90 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Tue, 2 Dec 2014 16:38:17 -0800 Subject: [PATCH] Test: added tests for CPComboBox --- Tests/AppKit/CPComboBoxTest.j | 78 +++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Tests/AppKit/CPComboBoxTest.j diff --git a/Tests/AppKit/CPComboBoxTest.j b/Tests/AppKit/CPComboBoxTest.j new file mode 100644 index 000000000..3d12ed91c --- /dev/null +++ b/Tests/AppKit/CPComboBoxTest.j @@ -0,0 +1,78 @@ +@import +@import +@import + +@import "CPNotificationCenterHelper.j" + +[CPApplication sharedApplication]; + +@implementation CPComboBoxTest : OJTestCase +{ + CPComboBox comboBox; + BOOL wasClicked +} + +- (void)setUp +{ + comboBox = [[CPComboBox alloc] initWithFrame:CGRectMake(0, 0, 200, 30)]; +} + +- (void)testCanCreate +{ + [self assertTrue:!!comboBox]; +} + +- (void)testPublicAccessors +{ + [comboBox setHasVerticalScroller:YES]; + [comboBox setIntercellSpacing:CGSizeMakeZero()]; + [comboBox setButtonBordered:YES]; + [comboBox setItemHeight:30]; + [comboBox setNumberOfVisibleItems:10]; +} + +- (void)testPerformClick +{ + [comboBox setTarget:self]; + [comboBox setAction:@selector(clickMe:)]; + [comboBox performClick:nil]; + [self assertTrue:wasClicked]; +} + +- (void)clickMe:(id)sender +{ + wasClicked = YES; +} + +- (void)testNotificationsRegistered +{ + [self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:comboBox] equals:[] message:@"Notications registered for the CPComboBox in the notification center are wrong"]; + [comboBox setListDelegate:[[_CPPopUpList alloc] initWithDataSource:comboBox]]; + [self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:comboBox] equals:[] message:@"Notications registered for the CPComboBox in the notification center are wrong"]; + + var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 1024.0, 768.0) + styleMask:CPWindowNotSizable]; + + [[theWindow contentView] addSubview:comboBox]; + + var expectedNotifications = [@"_CPPopUpListWillPopUpNotification", @"_CPPopUpListWillDismissNotification", @"_CPPopUpListDidDismissNotification", @"_CPPopUpListItemWasClickedNotification", @"CPTableViewSelectionIsChangingNotification", @"CPTableViewSelectionDidChangeNotification"].sort(); + + [self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:comboBox] equals:expectedNotifications message:@"Notications registered for the CPComboBox in the notification center are wrong"]; + + [comboBox removeFromSuperview]; + [self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:comboBox] equals:[] message:@"Notications registered for the CPComboBox in the notification center are wrong"]; + + [[theWindow contentView] addSubview:comboBox]; + [self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:comboBox] equals:expectedNotifications message:@"Notications registered for the CPComboBox in the notification center are wrong"]; + + [[theWindow contentView] addSubview:comboBox]; + [self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:comboBox] equals:expectedNotifications message:@"Notications registered for the CPComboBox in the notification center are wrong"]; + + [comboBox setListDelegate:nil]; + [self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:comboBox] equals:[] message:@"Notications registered for the CPComboBox in the notification center are wrong"]; + + [comboBox setListDelegate:[[_CPPopUpList alloc] initWithDataSource:comboBox]]; + [self assert:[CPNotificationCenterHelper registeredNotificationsForObserver:comboBox] equals:expectedNotifications message:@"Notications registered for the CPComboBox in the notification center are wrong"]; +} + +@end \ No newline at end of file