7 #import <OCMock/OCMock.h>
8 #import <XCTest/XCTest.h>
28 @property(readonly) NSUInteger undoCount;
29 @property(readonly) NSUInteger redoCount;
31 - (instancetype)initWithUndoManager:(NSUndoManager*)undoManager
41 - (instancetype)initWithUndoManager:(NSUndoManager*)undoManager
42 activeTextInputView:(UIView<UITextInput>*)activeTextInputView {
51 - (void)handleUndoWithDirection:(FlutterUndoRedoDirection)direction {
52 if (direction == FlutterUndoRedoDirectionUndo) {
65 @property(nonatomic) NSUndoManager* undoManager;
73 self.
undoManager = OCMClassMock([NSUndoManager
class]);
76 self.undoManagerDelegate =
78 activeTextInputView:self.activeTextInputView];
80 self.undoManagerPlugin =
84 - (void)testSetUndoState {
85 __block
int registerUndoCount = 0;
86 __block void (^undoHandler)(
id target);
88 .andDo(^(NSInvocation* invocation) {
90 __weak void (^handler)(
id target);
91 [invocation retainArguments];
92 [invocation getArgument:&handler atIndex:3];
93 undoHandler = handler;
95 __block
int removeAllActionsCount = 0;
97 .andDo(^(NSInvocation* invocation) {
98 removeAllActionsCount++;
100 __block
int undoCount = 0;
101 OCMStub([
self.
undoManager undo]).andDo(^(NSInvocation* invocation) {
109 arguments:@{@"canUndo" : @NO, @"canRedo" : @NO}];
110 [
self.undoManagerPlugin handleMethodCall:setUndoStateCall
111 result:^(id _Nullable result){
113 XCTAssertEqual(1, removeAllActionsCount);
114 XCTAssertEqual(0, registerUndoCount);
119 arguments:@{@"canUndo" : @YES, @"canRedo" : @NO}];
120 [
self.undoManagerPlugin handleMethodCall:setUndoStateCall
121 result:^(id _Nullable result){
123 XCTAssertEqual(2, removeAllActionsCount);
124 XCTAssertEqual(1, registerUndoCount);
130 XCTAssertEqual(2, registerUndoCount);
136 XCTAssertEqual(3, registerUndoCount);
141 arguments:@{@"canUndo" : @NO, @"canRedo" : @YES}];
142 [
self.undoManagerPlugin handleMethodCall:setUndoStateCall
143 result:^(id _Nullable result){
145 XCTAssertEqual(3, removeAllActionsCount);
146 XCTAssertEqual(5, registerUndoCount);
147 XCTAssertEqual(1, undoCount);
155 - (void)testSetUndoStateDoesInteractWithInputDelegate {
159 arguments:@{@"canUndo" : @NO, @"canRedo" : @NO}];
160 [
self.undoManagerPlugin handleMethodCall:setUndoStateCall
161 result:^(id _Nullable result){