136 {
137 self.partialMockPlugin = OCMPartialMock(
self.
plugin);
139 id textCheckerClassMock = OCMClassMock([UITextChecker class]);
140 [[[textCheckerClassMock stub] andReturn:@[ @"en" ]] availableLanguages];
141 NSArray* suggestions1 = @[ @"suggestion 1", @"suggestion 2" ];
142 NSArray* suggestions2 = @[ @"suggestion 3", @"suggestion 4" ];
143
144 [self mockUITextCheckerWithExpectedMisspelledWordRange:NSMakeRange(0, 5)
145 startingIndex:0
146 suggestions:suggestions1];
147
148 [self mockUITextCheckerWithExpectedMisspelledWordRange:NSMakeRange(5, 5)
149 startingIndex:5
150 suggestions:suggestions2];
151
152 [self mockUITextCheckerWithExpectedMisspelledWordRange:NSMakeRange(NSNotFound, 0)
153 startingIndex:10
154 suggestions:@[]];
155 __block NSArray* capturedResult;
156 [self.mockMethodChannel invokeMethod:@"SpellCheck.initiateSpellCheck"
157 arguments:@[ @"en", @"ksajlkdf aslkdfl kasdf asdfjk" ]
158 result:^(id _Nullable result) {
159 capturedResult = result;
160 }];
161 XCTAssertTrue(capturedResult.count == 2);
162 NSDictionary* suggestionsJSON1 = capturedResult.firstObject;
163 XCTAssertEqualObjects(suggestionsJSON1[@"startIndex"], @0);
164 XCTAssertEqualObjects(suggestionsJSON1[@"endIndex"], @5);
165 XCTAssertEqualObjects(suggestionsJSON1[@"suggestions"], suggestions1);
166 NSDictionary* suggestionsJSON2 = capturedResult[1];
167 XCTAssertEqualObjects(suggestionsJSON2[@"startIndex"], @5);
168 XCTAssertEqualObjects(suggestionsJSON2[@"endIndex"], @10);
169 XCTAssertEqualObjects(suggestionsJSON2[@"suggestions"], suggestions2);
170 [self.mockTextChecker reset];
171 [textCheckerClassMock stopMocking];
172}