5#import "flutter/shell/platform/darwin/ios/framework/Source/FlutterUndoManagerPlugin.h"
7#import <OCMock/OCMock.h>
8#import <XCTest/XCTest.h>
10#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.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 =
85 __block
int registerUndoCount = 0;
86 __block void (^undoHandler)(
id target);
87 OCMStub([
self.undoManager registerUndoWithTarget:
self.undoManagerPlugin handler:[OCMArg
any]])
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;
96 OCMStub([
self.undoManager removeAllActionsWithTarget:
self.undoManagerPlugin])
97 .andDo(^(NSInvocation* invocation) {
98 removeAllActionsCount++;
100 __block
int undoCount = 0;
101 OCMStub([
self.undoManager undo]).andDo(^(NSInvocation* invocation) {
103 undoHandler(
self.undoManagerPlugin);
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);
127 undoHandler(
self.undoManagerPlugin);
128 XCTAssertEqual(1UL,
self.undoManagerDelegate.undoCount);
129 XCTAssertEqual(0
UL,
self.undoManagerDelegate.redoCount);
130 XCTAssertEqual(2, registerUndoCount);
133 undoHandler(
self.undoManagerPlugin);
134 XCTAssertEqual(1UL,
self.undoManagerDelegate.undoCount);
135 XCTAssertEqual(1UL,
self.undoManagerDelegate.redoCount);
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);
150 undoHandler(
self.undoManagerPlugin);
151 XCTAssertEqual(1UL,
self.undoManagerDelegate.undoCount);
152 XCTAssertEqual(2UL,
self.undoManagerDelegate.redoCount);
159 arguments:@{@"canUndo" : @NO, @"canRedo" : @NO}];
160 [
self.undoManagerPlugin handleMethodCall:setUndoStateCall
161 result:^(id _Nullable result){
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)
void testSetUndoStateDoesInteractWithInputDelegate()
id< UITextInputDelegate > inputDelegate
UITextInputAssistantItem * inputAssistantItem
SIT bool any(const Vec< 1, T > &x)
UIView< UITextInput > * activeTextInputView
NSUndoManager * undoManager