#import <UnitKit/UnitKit.h>
#import "GanttTask.h"
#import "GanttView.h"
#import "GanttController.h"

@interface GanttViewTests : NSObject <UKTest>
{
    GanttController *document1;
    GanttTask *task1;
    GanttTask *task2;
    GanttTask *task3;
    GanttTask *task4;
}

@end

@implementation GanttViewTests

- (id)init
{
    if ((self = [super init]))
    {
        document1 = [[GanttController alloc] init];
        GanttModel *m = [document1 tasks];
        task1 = [document1 newTask];
        [m addTask:task1];
        task2 = [document1 newTask];
        [m addTask:task2];
        task3 = [document1 newTask];
        [m addTask:task3];
        task4 = [document1 newTask];
        [m addTask:task4];
    }
    return self;
}

- (void)testFlat
{
    GanttView *view = [[GanttView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
    UKIntsEqual(4, [view visibleTasks]);
    UKIntsEqual([task2 tag], [[view taskAtIndex:1] tag]);
    [view release];
}

- (void)testTree
{
    GanttView *view = [[GanttView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
    NSOutlineView *outline = [[NSOutlineView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
    [view setTableView:outline];
    GanttModel *m = [document1 tasks];
    GanttTask *t = [m taskAtIndex:2];
    GanttTask *newTask = [document1 newTask];
    [m addChild:newTask toTaskWithTag:[t tag]];
    UKIntsEqual(4, [view visibleTasks]);
    NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
    [nc postNotificationName:NSOutlineViewItemDidExpandNotification 
        object:outline 
        userInfo:[NSDictionary dictionaryWithObject:t forKey:@"NSObject"]];
    UKIntsEqual(5, [view visibleTasks]);
    UKIntsEqual([newTask tag], [[view taskAtIndex:3] tag]);
    UKIntsEqual([task4 tag], [[view taskAtIndex:4] tag]);
}

- (void)dealloc
{
    DESTROY(document1);
    [super dealloc];
}

@end
