7 #import <OCMock/OCMock.h>
8 #import <XCTest/XCTest.h>
31 @property(nonatomic, strong)
id engine;
47 self.undoManagerPlugin.viewController =
self.viewController;
49 self.undoManager = OCMClassMock([NSUndoManager
class]);
50 self.undoManagerPlugin.undoManager =
self.undoManager;
54 [
self.undoManager removeAllActionsWithTarget:self.undoManagerPlugin];
56 self.viewController = nil;
57 self.undoManager = nil;
61 - (void)testSetUndoState {
62 __block
int registerUndoCount = 0;
63 __block void (^undoHandler)(
id target);
64 OCMStub([
self.undoManager registerUndoWithTarget:
self.undoManagerPlugin handler:[OCMArg any]])
65 .andDo(^(NSInvocation* invocation) {
67 __weak void (^handler)(
id target);
68 [invocation retainArguments];
69 [invocation getArgument:&handler atIndex:3];
70 undoHandler = handler;
72 __block
int removeAllActionsCount = 0;
73 OCMStub([
self.undoManager removeAllActionsWithTarget:
self.undoManagerPlugin])
74 .andDo(^(NSInvocation* invocation) {
75 removeAllActionsCount++;
77 __block
int delegateUndoCount = 0;
78 OCMStub([
self.
engine flutterUndoManagerPlugin:[OCMArg any]
79 handleUndoWithDirection:FlutterUndoRedoDirectionUndo])
80 .andDo(^(NSInvocation* invocation) {
83 __block
int delegateRedoCount = 0;
84 OCMStub([
self.
engine flutterUndoManagerPlugin:[OCMArg any]
85 handleUndoWithDirection:FlutterUndoRedoDirectionRedo])
86 .andDo(^(NSInvocation* invocation) {
89 __block
int undoCount = 0;
90 OCMStub([
self.undoManager undo]).andDo(^(NSInvocation* invocation) {
92 undoHandler(
self.undoManagerPlugin);
98 arguments:@{@"canUndo" : @NO, @"canRedo" : @NO}];
99 [
self.undoManagerPlugin handleMethodCall:setUndoStateCall
100 result:^(id _Nullable result){
102 XCTAssertEqual(1, removeAllActionsCount);
103 XCTAssertEqual(0, registerUndoCount);
108 arguments:@{@"canUndo" : @YES, @"canRedo" : @NO}];
109 [
self.undoManagerPlugin handleMethodCall:setUndoStateCall
110 result:^(id _Nullable result){
112 XCTAssertEqual(2, removeAllActionsCount);
113 XCTAssertEqual(1, registerUndoCount);
116 undoHandler(
self.undoManagerPlugin);
117 XCTAssertEqual(1, delegateUndoCount);
118 XCTAssertEqual(0, delegateRedoCount);
119 XCTAssertEqual(2, registerUndoCount);
122 undoHandler(
self.undoManagerPlugin);
123 XCTAssertEqual(1, delegateUndoCount);
124 XCTAssertEqual(1, delegateRedoCount);
125 XCTAssertEqual(3, registerUndoCount);
130 arguments:@{@"canUndo" : @NO, @"canRedo" : @YES}];
131 [
self.undoManagerPlugin handleMethodCall:setUndoStateCall
132 result:^(id _Nullable result){
134 XCTAssertEqual(3, removeAllActionsCount);
135 XCTAssertEqual(5, registerUndoCount);
136 XCTAssertEqual(1, undoCount);
139 undoHandler(
self.undoManagerPlugin);
140 XCTAssertEqual(1, delegateUndoCount);
141 XCTAssertEqual(2, delegateRedoCount);
144 - (void)testSetUndoStateDoesInteractWithInputDelegate {
147 self.undoManagerPlugin.viewController =
self.viewController;
158 arguments:@{@"canUndo" : @NO, @"canRedo" : @NO}];
159 [
self.undoManagerPlugin handleMethodCall:setUndoStateCall
160 result:^(id _Nullable result){