7 #import <OCMock/OCMock.h>
8 #import <XCTest/XCTest.h>
22 - (instancetype)initWithUndoManager:(NSUndoManager*)undoManager
23 activeTextInputView:(UIView<UITextInput>*)activeTextInputView;
29 - (instancetype)initWithUndoManager:(NSUndoManager*)undoManager
30 activeTextInputView:(UIView<UITextInput>*)activeTextInputView {
39 - (void)handleUndoWithDirection:(FlutterUndoRedoDirection)direction {
40 if (direction == FlutterUndoRedoDirectionUndo) {
61 self.
undoManager = OCMClassMock([NSUndoManager
class]);
64 self.undoManagerDelegate =
66 activeTextInputView:self.activeTextInputView];
68 self.undoManagerPlugin =
72 - (void)testSetUndoState {
73 __block
int registerUndoCount = 0;
74 __block void (^undoHandler)(
id target);
76 .andDo(^(NSInvocation* invocation) {
78 __weak void (^handler)(
id target);
79 [invocation retainArguments];
80 [invocation getArgument:&handler atIndex:3];
81 undoHandler = handler;
83 __block
int removeAllActionsCount = 0;
85 .andDo(^(NSInvocation* invocation) {
86 removeAllActionsCount++;
89 OCMStub([
self.
undoManager undo]).andDo(^(NSInvocation* invocation) {
97 arguments:@{@"canUndo" : @NO, @"canRedo" : @NO}];
98 [
self.undoManagerPlugin handleMethodCall:setUndoStateCall
99 result:^(id _Nullable result){
101 XCTAssertEqual(1, removeAllActionsCount);
102 XCTAssertEqual(0, registerUndoCount);
107 arguments:@{@"canUndo" : @YES, @"canRedo" : @NO}];
108 [
self.undoManagerPlugin handleMethodCall:setUndoStateCall
109 result:^(id _Nullable result){
111 XCTAssertEqual(2, removeAllActionsCount);
112 XCTAssertEqual(1, registerUndoCount);
118 XCTAssertEqual(2, registerUndoCount);
124 XCTAssertEqual(3, registerUndoCount);
129 arguments:@{@"canUndo" : @NO, @"canRedo" : @YES}];
130 [
self.undoManagerPlugin handleMethodCall:setUndoStateCall
131 result:^(id _Nullable result){
133 XCTAssertEqual(3, removeAllActionsCount);
134 XCTAssertEqual(5, registerUndoCount);
143 - (void)testSetUndoStateDoesInteractWithInputDelegate {
147 arguments:@{@"canUndo" : @NO, @"canRedo" : @NO}];
148 [
self.undoManagerPlugin handleMethodCall:setUndoStateCall
149 result:^(id _Nullable result){
155 - (void)testDeallocRemovesAllUndoManagerActions {
158 NSUndoManager*
undoManager = [[NSUndoManager alloc] init];
164 activeTextInputView:activeTextInputView];
172 arguments:@{@"canUndo" : @YES, @"canRedo" : @YES}];
174 result:^(id _Nullable result){
182 XCTAssertNil(weakUndoManagerPlugin);