Resolved issues with undo/redo not working properly on create/remove entry

This commit is contained in:
michael starke
2016-06-16 19:20:49 +02:00
parent 0c2733d928
commit f3f0d27a3f
5 changed files with 125 additions and 12 deletions

View File

@@ -0,0 +1,79 @@
//
// MPTestNodeDelegate.m
// MacPass
//
// Created by Michael Starke on 13/06/16.
// Copyright © 2016 HicknHack Software GmbH. All rights reserved.
//
#import <XCTest/XCTest.h>
#import <KeePassKit/KeePassKit.h>
@interface MPDummyDelegate : NSObject <KPKModificationDelegate>
@property (strong) NSMutableSet<NSUUID *> *uuids;
@end
@implementation MPDummyDelegate
- (instancetype)init {
self = [super init];
if(self) {
self.uuids = [[NSMutableSet alloc] init];
}
return self;
}
- (void)willModifyNode:(KPKNode *)node {
if(node.asGroup || ! node.asEntry) {
NSLog(@"Node is no entry, no need to do anything!");
return;
}
KPKEntry *entry = node.asEntry;
if(![self.uuids containsObject:entry.uuid]) {
[self.uuids addObject:entry.uuid];
NSLog(@"First mutation for %@ detected. Pushin history", entry);
[entry pushHistory];
}
}
@end
@interface MPTestNodeDelegate : XCTestCase
@property (strong) KPKEntry *entry;
@property (strong) MPDummyDelegate *delegate;
@end
@implementation MPTestNodeDelegate
- (void)setUp {
[super setUp];
self.entry = [[KPKEntry alloc] init];
self.entry.title = @"Entry Title";
self.entry.url = @"http://www.internet.com";
self.entry.password = @"1234";
self.entry.username = @"Entry Username";
self.entry.autotype.defaultKeystrokeSequence = @"{TAB 3}";
self.delegate = [[MPDummyDelegate alloc] init];
self.entry.delegate = self.delegate;
}
- (void)tearDown {
[super tearDown];
}
- (void)testModificationDetection {
XCTAssertTrue(self.entry.history.count == 0, @"No History entry is present on newly created entry!");
self.entry.password = @"New Password";
XCTAssertEqualObjects(self.entry.password, @"New Password", @"Password is set on entry!");
XCTAssertTrue(self.entry.history.count == 1, @"Changin the password creates a history entry!");
KPKEntry *historyEntry = self.entry.history.firstObject;
XCTAssertEqualObjects(historyEntry.password, @"1234", @"Password on history entry did not change!");
}
@end