mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-12-04 20:05:03 +00:00
Tests: Add coverage for split views and split view controllers loaded from cibs
This commit is contained in:
1 parent
bce7f5d49b
commit
3611b503e1
2 files changed
+79
No files matched your search
@@ -570,6 +570,47 @@
|
||||
[self assertTrue:[[[items[0] viewController] view] isHidden] message:@"a decoded item collapses its view"];
|
||||
}
|
||||
|
||||
/*
|
||||
A xib holds a split view controller only as a view controller of class
|
||||
NSSplitViewController whose view outlet is a split view; it cannot hold items. nib2cib
|
||||
converts it to an archive of CPViewController decoded as CPSplitViewController. When the
|
||||
controller's view first loads, it adopts the split view, becomes its delegate, and shows
|
||||
the views of the items the application added in code.
|
||||
*/
|
||||
- (void)testAControllerFromACibAdoptsItsSplitViewAndShowsItemsAddedInCode
|
||||
{
|
||||
var cibSplitView = [[CPSplitView alloc] initWithFrame:CGRectMake(0, 0, 300, 100)],
|
||||
viewController = [[CPViewController alloc] init];
|
||||
|
||||
[cibSplitView setVertical:YES];
|
||||
[viewController setView:cibSplitView];
|
||||
|
||||
var unarchiver = [[CPKeyedUnarchiver alloc] initForReadingWithData:[CPKeyedArchiver archivedDataWithRootObject:viewController]];
|
||||
|
||||
[unarchiver setClass:CPSplitViewController forClassName:@"CPViewController"];
|
||||
|
||||
var cibController = [unarchiver decodeObjectForKey:@"root"];
|
||||
|
||||
[unarchiver finishDecoding];
|
||||
/*
|
||||
Cib loading instantiates the split view object directly; asking the controller for
|
||||
its view here would load the view before the items exist.
|
||||
*/
|
||||
[cibController._view _cibInstantiate];
|
||||
|
||||
[self assertTrue:[cibController isKindOfClass:CPSplitViewController] message:@"precondition: the archive decodes as a split view controller"];
|
||||
|
||||
[cibController addSplitViewItem:sidebarItem];
|
||||
[cibController addSplitViewItem:contentItem];
|
||||
|
||||
var splitView = [cibController view];
|
||||
|
||||
[self assertTrue:[splitView isKindOfClass:CPSplitView] message:@"the view is the split view"];
|
||||
[self assert:splitView equals:[cibController splitView] message:@"the controller adopts the split view"];
|
||||
[self assert:cibController equals:[splitView delegate] message:@"the controller is the delegate of the split view"];
|
||||
[self assert:[[sidebarChild view], [contentChild view]] equals:[splitView arrangedSubviews] message:@"the item views are arranged, in the order of the items"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation _CPSplitViewControllerTestChild : CPViewController
|
||||
|
||||
@@ -877,6 +877,44 @@
|
||||
[self assert:250 equals:[copy holdingPriorityForSubviewAtIndex:1] message:@"the second subview of the copy"];
|
||||
}
|
||||
|
||||
/*
|
||||
A split view converted by nib2cib holds its subviews from Interface Builder, but no
|
||||
arranged subviews, dividers or holding priorities: the plugin builds it so. When the cib
|
||||
loads, the split view arranges its subviews, adds the divider between them, gives each
|
||||
the default holding priority and tiles its bounds, as NSSplitView does with the
|
||||
subviews of a xib.
|
||||
*/
|
||||
- (void)testASplitViewFromACibArrangesItsSubviewsWhenTheCibLoads
|
||||
{
|
||||
var cibSplitView = [[CPSplitView alloc] initWithFrame:CGRectMake(0, 0, 300, 100)],
|
||||
left = [[CPView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)],
|
||||
right = [[CPView alloc] initWithFrame:CGRectMake(110, 0, 190, 100)];
|
||||
|
||||
[cibSplitView setVertical:YES];
|
||||
[cibSplitView setDividerStyle:CPSplitViewDividerStyleThin];
|
||||
|
||||
cibSplitView._subviewsManagementDisabled = YES;
|
||||
[cibSplitView addSubview:left];
|
||||
[cibSplitView addSubview:right];
|
||||
cibSplitView._subviewsManagementDisabled = NO;
|
||||
|
||||
[self assert:0 equals:[[cibSplitView arrangedSubviews] count] message:@"precondition: the converted split view has no arranged subviews"];
|
||||
|
||||
var copy = [CPKeyedUnarchiver unarchiveObjectWithData:[CPKeyedArchiver archivedDataWithRootObject:cibSplitView]];
|
||||
|
||||
[copy _cibInstantiate];
|
||||
|
||||
var arranged = [copy arrangedSubviews];
|
||||
|
||||
[self assert:2 equals:[arranged count] message:@"the subviews are arranged"];
|
||||
[self assert:[[copy subviews] objectAtIndex:0] equals:arranged[0] message:@"the first subview is the first arranged subview"];
|
||||
[self assert:250 equals:[copy holdingPriorityForSubviewAtIndex:0] message:@"the first holding priority"];
|
||||
[self assert:250 equals:[copy holdingPriorityForSubviewAtIndex:1] message:@"the second holding priority"];
|
||||
[self assert:300 equals:CGRectGetWidth([arranged[0] frame]) + [copy dividerThickness] + CGRectGetWidth([arranged[1] frame]) message:@"the subviews and the divider fill the width"];
|
||||
[self assert:0 equals:CGRectGetMinX([arranged[0] frame]) message:@"the first subview starts at the leading edge"];
|
||||
[self assert:CGRectGetMaxX([arranged[0] frame]) + [copy dividerThickness] equals:CGRectGetMinX([arranged[1] frame]) message:@"the second subview starts after the divider"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// MARK: -
|
||||
|
||||
Reference in new issue
Block a user