Skip to content

Commit 4906ba7

Browse files
committed
test: add completion tests for language service with signal inputs (#53808)
Given that the TCB output changes with signal inputs, and one of our important considerations was auto-completion, we need some unit tests that verify and guarantee proper completion with signal inputs being bound in templates. This commit adds these. PR Close #53808
1 parent 81379ef commit 4906ba7

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

packages/language-service/test/completions_spec.ts

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,67 @@ describe('completions', () => {
281281
});
282282
});
283283

284+
describe('signal inputs', () => {
285+
const signalInputDirectiveWithUnionType = {
286+
'Dir': `
287+
@Directive({
288+
selector: '[dir]',
289+
})
290+
export class Dir {
291+
myInput = input<'foo'|42|null>();
292+
}
293+
`
294+
};
295+
296+
it('should return property access completions', () => {
297+
const {templateFile} =
298+
setup(`<input dir [myInput]="'foo'.">`, '', signalInputDirectiveWithUnionType);
299+
templateFile.moveCursorToText(`dir [myInput]="'foo'.¦">`);
300+
301+
const completions = templateFile.getCompletionsAtPosition();
302+
expectContain(
303+
completions, ts.ScriptElementKind.memberFunctionElement,
304+
[`charAt`, 'toLowerCase', /* etc. */]);
305+
});
306+
307+
it('should return completions of string literals, number literals, `true`, ' +
308+
'`false`, `null` and `undefined`',
309+
() => {
310+
const {templateFile} =
311+
setup(`<input dir [myInput]="">`, '', signalInputDirectiveWithUnionType);
312+
templateFile.moveCursorToText('dir [myInput]="¦">');
313+
314+
const completions = templateFile.getCompletionsAtPosition();
315+
expectContain(completions, ts.ScriptElementKind.string, [`'foo'`, '42']);
316+
expectContain(completions, ts.ScriptElementKind.keyword, ['null']);
317+
expectContain(completions, ts.ScriptElementKind.variableElement, ['undefined']);
318+
expectDoesNotContain(completions, ts.ScriptElementKind.parameterElement, ['ctx']);
319+
});
320+
321+
it('should return completions of string literals, number literals, `true`, `false`, ' +
322+
'`null` and `undefined` when the user tries to modify the symbol',
323+
() => {
324+
const {templateFile} =
325+
setup(`<input dir [myInput]="a">`, '', signalInputDirectiveWithUnionType);
326+
templateFile.moveCursorToText('dir [myInput]="a¦">');
327+
328+
const completions = templateFile.getCompletionsAtPosition();
329+
expectContain(completions, ts.ScriptElementKind.string, [`'foo'`, '42']);
330+
expectContain(completions, ts.ScriptElementKind.keyword, ['null']);
331+
expectContain(completions, ts.ScriptElementKind.variableElement, ['undefined']);
332+
expectDoesNotContain(completions, ts.ScriptElementKind.parameterElement, ['ctx']);
333+
});
334+
335+
it('should complete a string union types in binding without brackets', () => {
336+
const {templateFile} =
337+
setup(`<input dir myInput="foo">`, '', signalInputDirectiveWithUnionType);
338+
templateFile.moveCursorToText('myInput="foo¦"');
339+
const completions = templateFile.getCompletionsAtPosition();
340+
expectContain(completions, ts.ScriptElementKind.string, ['foo']);
341+
expectReplacementText(completions, templateFile.contents, 'foo');
342+
});
343+
});
344+
284345
describe('for blocks', () => {
285346
const completionPrefixes = ['@', '@i'];
286347

@@ -1573,7 +1634,7 @@ function setup(
15731634
const env = LanguageServiceTestEnv.setup();
15741635
const project = env.addProject('test', {
15751636
'test.ts': `
1576-
import {Component, Directive, NgModule, Pipe, TemplateRef} from '@angular/core';
1637+
import {Component, input, Directive, NgModule, Pipe, TemplateRef} from '@angular/core';
15771638
15781639
${functionDeclarations}
15791640

0 commit comments

Comments
 (0)