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) {
52@property(nonatomic) UIView<UITextInput>* activeTextInputView;
53@property(nonatomic) NSUndoManager* undoManager;
64 self.undoManagerDelegate =
66 activeTextInputView:self.activeTextInputView];
68 self.undoManagerPlugin =
72- (void)testSetUndoState {
73 __block
int registerUndoCount = 0;
74 __block void (^undoHandler)(
id target);
75 OCMStub([
self.undoManager registerUndoWithTarget:
self.undoManagerPlugin
handler:[OCMArg any]])
76 .andDo(^(NSInvocation* invocation) {
79 [invocation retainArguments];
80 [invocation getArgument:&handler atIndex:3];
83 __block
int removeAllActionsCount = 0;
84 OCMStub([
self.undoManager removeAllActionsWithTarget:
self.undoManagerPlugin])
85 .andDo(^(NSInvocation* invocation) {
86 removeAllActionsCount++;
88 __block
int undoCount = 0;
89 OCMStub([
self.undoManager undo]).andDo(^(NSInvocation* invocation) {
91 undoHandler(
self.undoManagerPlugin);
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);
115 undoHandler(
self.undoManagerPlugin);
116 XCTAssertEqual(1UL,
self.undoManagerDelegate.undoCount);
117 XCTAssertEqual(0UL,
self.undoManagerDelegate.redoCount);
118 XCTAssertEqual(2, registerUndoCount);
121 undoHandler(
self.undoManagerPlugin);
122 XCTAssertEqual(1UL,
self.undoManagerDelegate.undoCount);
123 XCTAssertEqual(1UL,
self.undoManagerDelegate.redoCount);
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);
135 XCTAssertEqual(1, undoCount);
138 undoHandler(
self.undoManagerPlugin);
139 XCTAssertEqual(1UL,
self.undoManagerDelegate.undoCount);
140 XCTAssertEqual(2UL,
self.undoManagerDelegate.redoCount);
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];
168 weakUndoManagerPlugin = undoManagerPlugin;
172 arguments:@{@"canUndo" : @YES, @"canRedo" : @YES}];
174 result:^(id _Nullable result){
176 XCTAssertTrue(undoManager.canUndo);
177 XCTAssertTrue(undoManager.canRedo);
182 XCTAssertNil(weakUndoManagerPlugin);
185 XCTAssertFalse(undoManager.canUndo);
186 XCTAssertFalse(undoManager.canRedo);
const gchar FlBinaryMessengerMessageHandler handler
UIView< UITextInput > * activeTextInputView
NSUndoManager * undoManager
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)
void handleMethodCall:result:(FlutterMethodCall *call,[result] FlutterResult result)
NSUndoManager * undoManager
id< UITextInputDelegate > inputDelegate