Files
cappuccino/Tests/AppKit/CPTableViewTableColumnTest.j
T
Alexandre Wilhelm 6fe9dae3d6 Fixed: AppKit unit-tests are not standalone
Previously, every AppKit tests used the same sharedApplication. Due to this implementation, a could not pass because a previous test made failed the current test. For instance, a test could fail because the window of the previous test resigned (just imagine a new window is the key window in the current test), and this resign could raise an error. The error was displayed for the current test thought this test was perfect !

We now instead of using sharedApplication create a new CPApplication per unit-test file in the class method setUp.
2015-07-07 14:12:19 -07:00

74 lines
2.1 KiB
Plaintext

@import <AppKit/AppKit.j>
@implementation CPTableViewTableColumnTest : OJTestCase
{
CPWindow theWindow;
CPTableView tableView;
}
+ (void)setUp
{
// This will init the global var CPApp which are used internally in the AppKit
[[CPApplication alloc] init];
}
- (void)setUp
{
// setup a reasonable table
theWindow = [[CPWindow alloc] initWithContentRect:CGRectMake(0.0, 0.0, 1024.0, 768.0)
styleMask:CPWindowNotSizable];
tableView = [[CPTableView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[tableView setDataSource:self];
var itemIndex = 0,
items = [@"Colonne1", @"Colonne2", @"Colonne3", @"Colonne4"];
for (itemIndex ; itemIndex < [items count]; itemIndex++)
{
var item = [items objectAtIndex:itemIndex],
column = [[CPTableColumn alloc] initWithIdentifier:item];
[column setEditable:YES];
[column setMinWidth:50];
[[column headerView] setStringValue:item];
[tableView addTableColumn:column];
}
[[theWindow contentView] addSubview:tableView];
[tableView reloadData];
}
- (void)testRemoveTableColumn
{
[self assertTrue:([[tableView tableColumns] count] == 4)];
[tableView removeTableColumn:[[tableView tableColumns] firstObject]];
[self assertTrue:([[tableView tableColumns] count] == 3)];
[tableView removeTableColumn:[[tableView tableColumns] firstObject]];
[self assertTrue:([[tableView tableColumns] count] == 2)];
var enumerateViewsInRowsCall = 0;
[tableView enumerateAvailableViewsUsingBlock:function(view, row, column, stop)
{
var tableColumn = [[tableView tableColumns] objectAtIndex:column];
[self assert:("COLUMN_" + [tableColumn identifier] + "ROW_" + row) equals:[view objectValue]];
enumerateViewsInRowsCall++;
}];
[self assert:enumerateViewsInRowsCall equals:30];
}
- (int)numberOfRowsInTableView:(CPTableView)aTableView
{
return 15;
}
- (id)tableView:(CPTableView)aTableView objectValueForTableColumn:(CPTableColumn)aColumn row:(int)aRowIndex
{
return "COLUMN_" + [aColumn identifier] + "ROW_" + aRowIndex;
}
@end