diff --git a/Tests/Foundation/CPUndoManagerTest.j b/Tests/Foundation/CPUndoManagerTest.j index 857794eba..67ef6308c 100644 --- a/Tests/Foundation/CPUndoManagerTest.j +++ b/Tests/Foundation/CPUndoManagerTest.j @@ -3,12 +3,16 @@ @implementation CPUndoManagerTest : OJTestCase { - CPUndoManager undoManager; + CPArray receivedNotifications; + CPUndoManager undoManager; + BOOL itIsDone; } - (void)setUp { undoManager = [[CPUndoManager alloc] init]; + itIsDone = NO; + receivedNotifications = [CPMutableArray array]; } - (void)testUndoMenuTitleForUndoActionName @@ -35,4 +39,46 @@ [self assert:[undoManager redoMenuTitleForUndoActionName:"STRING"] equals:@"Redo STRING"]; } +- (void)testNotifications +{ + + [[CPNotificationCenter defaultCenter] addObserver:self + selector:@selector(receiveNotification:) + name:CPUndoManagerDidCloseUndoGroupNotification + object:undoManager]; + + [self doIt]; + + // The default run loop undo grouping won't be closed until the next run loop cycle. + [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; + + CPLog.error("receivedNotifications: %@", receivedNotifications); + [self assert:CPUndoManagerDidCloseUndoGroupNotification equals:[receivedNotifications[0] name]]; + + [[CPNotificationCenter defaultCenter] removeObserver:self]; +} + +- (void)receiveNotification:(CPNotification)aNotification +{ + [receivedNotifications addObject:aNotification]; +} + +- (void)doIt +{ + [undoManager registerUndoWithTarget:self + selector:@selector(undoIt) + object:nil]; + + itIsDone = YES; +} + +- (void)undoIt +{ + [undoManager registerUndoWithTarget:self + selector:@selector(doit) + object:nil]; + + itIsDone = NO; +} + @end