From 64857557e6ef0d98af7f501a818dea8420bedd60 Mon Sep 17 00:00:00 2001 From: michael starke Date: Wed, 5 Aug 2015 10:47:55 +0200 Subject: [PATCH] implemented test for undo/redo create entry Signed-off-by: michael starke --- MacPassTests/KPKTestUndo.m | 92 +++++++++++++++++++++++++++++++------- 1 file changed, 77 insertions(+), 15 deletions(-) diff --git a/MacPassTests/KPKTestUndo.m b/MacPassTests/KPKTestUndo.m index 14a31312..2377d5c7 100644 --- a/MacPassTests/KPKTestUndo.m +++ b/MacPassTests/KPKTestUndo.m @@ -16,7 +16,7 @@ @interface KPKTestUndo : XCTestCase { NSUndoManager *_undoManager; KPKTree *_tree; - KPKGroup *_groupA, *_groupB; + KPKGroup *_root, *_groupA, *_groupB; KPKEntry *_entryA, *_entryB; } @end @@ -33,36 +33,98 @@ _tree = [[KPKTree alloc] init]; _tree.delegate = self; - _groupA = [[KPKGroup alloc] init]; - _groupB = [[KPKGroup alloc] init]; - _entryA = [[KPKEntry alloc] init]; - _entryB = [[KPKEntry alloc] init]; - + /* Disable undo registration in the setup to have a clean test environment */ [_undoManager disableUndoRegistration]; + + _root = [[KPKGroup alloc] init]; + + _tree.root = _root; + + _groupA = [[KPKGroup alloc] init]; + _groupA.title = @"Group A"; + _groupB = [[KPKGroup alloc] init]; + _groupB.title = @"Group B"; + + [_root addGroup:_groupA]; + [_root addGroup:_groupB]; + + _entryA = [[KPKEntry alloc] init]; + _entryA.title = @"Entry A"; + _entryA.username = @"Username A"; + _entryA.url = @"http://www.a.com"; + + [_groupA addEntry:_entryA]; + + _entryB = [[KPKEntry alloc] init]; + _entryB.title = @"Entry B"; + _entryB.username = @"Username B"; + _entryB.url = @"http://www.b.com"; + + [_groupB addEntry:_entryB]; + + /* Enable undo registration for the tests */ [_undoManager enableUndoRegistration]; } - (void)tearDown { + _entryA = nil; + _entryB = nil; + _groupB = nil; + _groupA = nil; + _tree = nil; _undoManager = nil; [super tearDown]; } - (void)testUndoRedoCreateEntry { - XCTFail(@"Missing Test"); + + XCTAssertFalse(_undoManager.canUndo, @"Undo stack is empty"); + XCTAssertFalse(_undoManager.canRedo, @"Redo stack is empty"); + KPKEntry *entry = [_tree createEntry:_groupA]; + [_groupA addEntry:entry]; + + + XCTAssertEqual(_groupA.entries.count, 2, @"Group A has two entries"); + XCTAssertTrue([_groupA.entries containsObject:entry], @"Created entry is in group A"); + + XCTAssertEqual(_groupB.entries.count, 1, @"Group B has one entry"); + XCTAssertFalse([_groupB.entries containsObject:entry], @"Created entry is not in group B"); + + XCTAssertEqual(_root.entries.count, 0, @"Root has no entries"); + XCTAssertFalse([_root.entries containsObject:entry], @"Created entry is not in root group"); + + XCTAssertTrue(_undoManager.canUndo, @"Undomanager can undo"); + + [_undoManager undo]; + + XCTAssertEqual(_groupA.entries.count, 1, @"Group A has one entry after undo"); + XCTAssertFalse([_groupA.entries containsObject:entry], @"Created enty is not in group A"); + + XCTAssertEqual(_groupB.entries.count, 1, @"Group B has one entry"); + XCTAssertFalse([_groupB.entries containsObject:entry], @"Created enty is not in group A"); + + XCTAssertEqual(_root.entries.count, 0, @"Root has no entries"); + XCTAssertFalse([_root.entries containsObject:entry], @"Created enty is not in group A"); + + XCTAssertFalse(_undoManager.canUndo, @"Undomanager cannot undo anymore"); + XCTAssertTrue(_undoManager.canRedo, @"Undomanger can redo executed undo"); + + [_undoManager redo]; + + XCTAssertEqual(_groupA.entries.count, 2, @"Group A has two entries"); + XCTAssertTrue([_groupA.entries containsObject:entry], @"Created entry is in group A"); + + XCTAssertEqual(_groupB.entries.count, 1, @"Group B has one entry"); + XCTAssertFalse([_groupB.entries containsObject:entry], @"Created entry is not in group B"); + + XCTAssertEqual(_root.entries.count, 0, @"Root has no entries"); + XCTAssertFalse([_root.entries containsObject:entry], @"Created entry is not in root group"); } - (void)testUndoRedoCreateGroup { XCTFail(@"Missing Test"); } -- (void)testUndoRedoCopyEntry { - XCTFail(@"Missing Test"); -} - -- (void)testUndoRedoCopyGroup { - XCTFail(@"Missing Test"); -} - - (void)testUndoRedoMoveEntry { XCTFail(@"Missing Test"); }