MockAutocompleterEnvironment helper = new MockAutocompleterEnvironment();
// TODO: vars in the global scope are not registered by CM.
String text = "function a() { var abba, apple, arrow; a";
helper.setup(new PathUtil("foo.js"), text, 0, text.length(), true);
final MockAutocompleter autocompleter = helper.autocompleter;
assertFalse("initially popup is not shown", helper.popup.isShowing());
final JsonArray<Scheduler.ScheduledCommand> scheduled = JsonCollections.createArray();
// We want to click ctrl-space.
Runnable ctrlSpaceClicker = new Runnable() {
@Override
public void run() {
autocompleter.pressKey(CTRL_SPACE);
}
};
// Collect deferred tasks in array.
TestSchedulerImpl.AngryScheduler scheduler = new TestSchedulerImpl.AngryScheduler() {
@Override
public void scheduleDeferred(ScheduledCommand scheduledCommand) {
scheduled.add(scheduledCommand);
}
};
// Now, if we hit ctrl-space - popup will appear with 3 variables.
TestSchedulerImpl.runWithSpecificScheduler(ctrlSpaceClicker, scheduler);
assertEquals("actual autocompletion is deferred", 1, scheduled.size());
// Now autocompletion acts.
scheduled.get(0).execute();
assertTrue("popup appeared", helper.popup.isShowing());
assertEquals("variables are proposed", 4, helper.popup.proposals.size());
// Now, if we type " " autocompletion popup should disappear.
autocompleter.pressKey(new SignalEventEssence(' '));
assertFalse("popup disappeared", helper.popup.isShowing());
}