Flutter Engine
The Flutter Engine
Instance Methods | Properties | List of all members
FlutterUndoManagerPluginTest Class Reference
Inheritance diagram for FlutterUndoManagerPluginTest:

Instance Methods

(void) - setUp [implementation]
 
(void) - testSetUndoState [implementation]
 
(void) - testSetUndoStateDoesInteractWithInputDelegate [implementation]
 

Properties

FakeFlutterUndoManagerDelegateundoManagerDelegate
 
FlutterUndoManagerPluginundoManagerPlugin
 
TextInputViewTestactiveTextInputView
 
NSUndoManager * undoManager
 

Detailed Description

Definition at line 61 of file FlutterUndoManagerPluginTest.mm.

Method Documentation

◆ setUp

- (void) setUp
implementation

Definition at line 65 of file FlutterUndoManagerPluginTest.mm.

70 {
71 [super setUp];
72
73 self.undoManager = OCMClassMock([NSUndoManager class]);
74 self.activeTextInputView = OCMClassMock([TextInputViewTest class]);
75
76 self.undoManagerDelegate =
77 [[FakeFlutterUndoManagerDelegate alloc] initWithUndoManager:self.undoManager
78 activeTextInputView:self.activeTextInputView];
79
80 self.undoManagerPlugin =
81 [[FlutterUndoManagerPlugin alloc] initWithDelegate:self.undoManagerDelegate];
82}

◆ testSetUndoState

- (void) testSetUndoState
implementation

Definition at line 65 of file FlutterUndoManagerPluginTest.mm.

84 {
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) {
89 registerUndoCount++;
90 __weak void (^handler)(id target);
91 [invocation retainArguments];
92 [invocation getArgument:&handler atIndex:3];
93 undoHandler = handler;
94 });
95 __block int removeAllActionsCount = 0;
96 OCMStub([self.undoManager removeAllActionsWithTarget:self.undoManagerPlugin])
97 .andDo(^(NSInvocation* invocation) {
98 removeAllActionsCount++;
99 });
100 __block int undoCount = 0;
101 OCMStub([self.undoManager undo]).andDo(^(NSInvocation* invocation) {
102 undoCount++;
103 undoHandler(self.undoManagerPlugin);
104 });
105
106 // If canUndo and canRedo are false, only removeAllActionsWithTarget is called.
107 FlutterMethodCall* setUndoStateCall =
108 [FlutterMethodCall methodCallWithMethodName:@"UndoManager.setUndoState"
109 arguments:@{@"canUndo" : @NO, @"canRedo" : @NO}];
110 [self.undoManagerPlugin handleMethodCall:setUndoStateCall
111 result:^(id _Nullable result){
112 }];
113 XCTAssertEqual(1, removeAllActionsCount);
114 XCTAssertEqual(0, registerUndoCount);
115
116 // If canUndo is true, an undo will be registered.
117 setUndoStateCall =
118 [FlutterMethodCall methodCallWithMethodName:@"UndoManager.setUndoState"
119 arguments:@{@"canUndo" : @YES, @"canRedo" : @NO}];
120 [self.undoManagerPlugin handleMethodCall:setUndoStateCall
121 result:^(id _Nullable result){
122 }];
123 XCTAssertEqual(2, removeAllActionsCount);
124 XCTAssertEqual(1, registerUndoCount);
125
126 // Invoking the undo handler will invoke the handleUndo delegate method with "undo".
127 undoHandler(self.undoManagerPlugin);
128 XCTAssertEqual(1UL, self.undoManagerDelegate.undoCount);
129 XCTAssertEqual(0UL, self.undoManagerDelegate.redoCount);
130 XCTAssertEqual(2, registerUndoCount);
131
132 // Invoking the redo handler will invoke the handleUndo delegate method with "redo".
133 undoHandler(self.undoManagerPlugin);
134 XCTAssertEqual(1UL, self.undoManagerDelegate.undoCount);
135 XCTAssertEqual(1UL, self.undoManagerDelegate.redoCount);
136 XCTAssertEqual(3, registerUndoCount);
137
138 // If canRedo is true, an undo will be registered and undo will be called.
139 setUndoStateCall =
140 [FlutterMethodCall methodCallWithMethodName:@"UndoManager.setUndoState"
141 arguments:@{@"canUndo" : @NO, @"canRedo" : @YES}];
142 [self.undoManagerPlugin handleMethodCall:setUndoStateCall
143 result:^(id _Nullable result){
144 }];
145 XCTAssertEqual(3, removeAllActionsCount);
146 XCTAssertEqual(5, registerUndoCount);
147 XCTAssertEqual(1, undoCount);
148
149 // Invoking the redo handler will invoke the handleUndo delegate method with "redo".
150 undoHandler(self.undoManagerPlugin);
151 XCTAssertEqual(1UL, self.undoManagerDelegate.undoCount);
152 XCTAssertEqual(2UL, self.undoManagerDelegate.redoCount);
153}
uint32_t * target
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)
FakeFlutterUndoManagerDelegate * undoManagerDelegate
FlutterUndoManagerPlugin * undoManagerPlugin
SIT bool any(const Vec< 1, T > &x)
Definition: SkVx.h:530

◆ testSetUndoStateDoesInteractWithInputDelegate

- (void) testSetUndoStateDoesInteractWithInputDelegate
implementation

Definition at line 65 of file FlutterUndoManagerPluginTest.mm.

155 {
156 // Regression test for https://github.com/flutter/flutter/issues/133424
157 FlutterMethodCall* setUndoStateCall =
158 [FlutterMethodCall methodCallWithMethodName:@"UndoManager.setUndoState"
159 arguments:@{@"canUndo" : @NO, @"canRedo" : @NO}];
160 [self.undoManagerPlugin handleMethodCall:setUndoStateCall
161 result:^(id _Nullable result){
162 }];
163
164 OCMVerify(never(), [self.activeTextInputView inputDelegate]);
165}
id< UITextInputDelegate > inputDelegate

Property Documentation

◆ activeTextInputView

- (TextInputViewTest*) activeTextInputView
readwritenonatomicassign

Definition at line 64 of file FlutterUndoManagerPluginTest.mm.

◆ undoManager

- (NSUndoManager*) undoManager
readwritenonatomicassign

Definition at line 65 of file FlutterUndoManagerPluginTest.mm.

◆ undoManagerDelegate

- (FakeFlutterUndoManagerDelegate*) undoManagerDelegate
readwritenonatomicassign

Definition at line 62 of file FlutterUndoManagerPluginTest.mm.

◆ undoManagerPlugin

- (FlutterUndoManagerPlugin*) undoManagerPlugin
readwritenonatomicassign

Definition at line 63 of file FlutterUndoManagerPluginTest.mm.


The documentation for this class was generated from the following file: