Add an integration test for aborting the completions on Escape

This commit is contained in:
MareStare 2025-03-19 01:37:52 +00:00
parent dd7ee44e36
commit 96d32d863d
2 changed files with 34 additions and 0 deletions

View file

@ -0,0 +1,34 @@
import { init } from './context';
it('ignores the autocompletion results if Escape was pressed', async () => {
const ctx = await init();
await Promise.all([ctx.setInput('mar'), ctx.keyDown('Escape')]);
// The input must be empty because the user typed `mar` and pressed `Escape` right after that
ctx.expectUi().toMatchInlineSnapshot(`
{
"input": "mar<>",
"suggestions": [],
}
`);
// First request for the local autocomplete index.
expect(fetch).toHaveBeenCalledTimes(1);
await ctx.setInput('mar');
ctx.expectUi().toMatchInlineSnapshot(`
{
"input": "mar<>",
"suggestions": [
"marvelous → beautiful 30",
"mare 20",
"market 10",
],
}
`);
// Second request for the server-side suggestions.
expect(fetch).toHaveBeenCalledTimes(2);
});