7 #import <OCMock/OCMock.h>
8 #import <XCTest/XCTest.h>
28 @property(readonly) NSUInteger undoCount;
29 @property(readonly) NSUInteger redoCount;
30 @property(nonatomic, nullable) NSUndoManager* undoManager;
32 - (instancetype)initWithUndoManager:(NSUndoManager*)undoManager
42 - (instancetype)initWithUndoManager:(NSUndoManager*)undoManager
43 activeTextInputView:(UIView<UITextInput>*)activeTextInputView {
52 - (void)handleUndoWithDirection:(FlutterUndoRedoDirection)direction {
53 if (direction == FlutterUndoRedoDirectionUndo) {
66 @property(nonatomic) NSUndoManager* undoManager;
74 self.
undoManager = OCMClassMock([NSUndoManager
class]);
77 self.undoManagerDelegate =
79 activeTextInputView:self.activeTextInputView];
81 self.undoManagerPlugin =
85 - (void)testSetUndoState {
86 __block
int registerUndoCount = 0;
87 __block void (^undoHandler)(
id target);
89 .andDo(^(NSInvocation* invocation) {
91 __weak void (^handler)(
id target);
92 [invocation retainArguments];
93 [invocation getArgument:&handler atIndex:3];
94 undoHandler = handler;
96 __block
int removeAllActionsCount = 0;
98 .andDo(^(NSInvocation* invocation) {
99 removeAllActionsCount++;
101 __block
int undoCount = 0;
102 OCMStub([
self.
undoManager undo]).andDo(^(NSInvocation* invocation) {
110 arguments:@{@"canUndo" : @NO, @"canRedo" : @NO}];
111 [
self.undoManagerPlugin handleMethodCall:setUndoStateCall
112 result:^(id _Nullable result){
114 XCTAssertEqual(1, removeAllActionsCount);
115 XCTAssertEqual(0, registerUndoCount);
120 arguments:@{@"canUndo" : @YES, @"canRedo" : @NO}];
121 [
self.undoManagerPlugin handleMethodCall:setUndoStateCall
122 result:^(id _Nullable result){
124 XCTAssertEqual(2, removeAllActionsCount);
125 XCTAssertEqual(1, registerUndoCount);
131 XCTAssertEqual(2, registerUndoCount);
137 XCTAssertEqual(3, registerUndoCount);
142 arguments:@{@"canUndo" : @NO, @"canRedo" : @YES}];
143 [
self.undoManagerPlugin handleMethodCall:setUndoStateCall
144 result:^(id _Nullable result){
146 XCTAssertEqual(3, removeAllActionsCount);
147 XCTAssertEqual(5, registerUndoCount);
148 XCTAssertEqual(1, undoCount);
156 - (void)testSetUndoStateDoesInteractWithInputDelegate {
160 arguments:@{@"canUndo" : @NO, @"canRedo" : @NO}];
161 [
self.undoManagerPlugin handleMethodCall:setUndoStateCall
162 result:^(id _Nullable result){
168 - (void)testDeallocRemovesAllUndoManagerActions {
171 NSUndoManager*
undoManager = [[NSUndoManager alloc] init];
177 activeTextInputView:activeTextInputView];
185 arguments:@{@"canUndo" : @YES, @"canRedo" : @YES}];
187 result:^(id _Nullable result){
195 XCTAssertNil(weakUndoManagerPlugin);