test(language-service): Move pipe tests to TEST_TEMPLATE (#36407)

This commit simplifies the completion tests for pipes by moving them to TEST_TEMPLATE.

PR Close #36407
This commit is contained in:
Keen Yee Liau 2020-04-02 21:48:16 -07:00 committed by Kara Erickson
parent 8660806ddc
commit eb8c6c7eff
5 changed files with 18 additions and 31 deletions

View File

@ -469,21 +469,24 @@ describe('completions', () => {
describe('for pipes', () => { describe('for pipes', () => {
it('should be able to get a list of pipe values', () => { it('should be able to get a list of pipe values', () => {
for (const location of ['before-pipe', 'in-pipe', 'after-pipe']) { // TODO(kyliau): does not work for case {{ title | ~{cursor} }}
const marker = mockHost.getLocationMarkerFor(PARSING_CASES, location); // space before and after pipe ^^^
const completions = ngLS.getCompletionsAtPosition(PARSING_CASES, marker.start); mockHost.override(TEST_TEMPLATE, `{{ title|~{cursor} }}`);
const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
const completions = ngLS.getCompletionsAtPosition(TEST_TEMPLATE, marker.start);
expectContain(completions, CompletionKind.PIPE, [ expectContain(completions, CompletionKind.PIPE, [
'async', 'async',
'uppercase',
'lowercase', 'lowercase',
'slice',
'titlecase', 'titlecase',
'uppercase',
]); ]);
}
}); });
it('should be able to resolve lowercase', () => { it('should be able to resolve lowercase', () => {
const marker = mockHost.getLocationMarkerFor(EXPRESSION_CASES, 'string-pipe'); mockHost.override(TEST_TEMPLATE, `{{ (title | lowercase).~{cursor} }}`);
const completions = ngLS.getCompletionsAtPosition(EXPRESSION_CASES, marker.start); const marker = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'cursor');
const completions = ngLS.getCompletionsAtPosition(TEST_TEMPLATE, marker.start);
expectContain(completions, CompletionKind.METHOD, [ expectContain(completions, CompletionKind.METHOD, [
'charAt', 'charAt',
'replace', 'replace',

View File

@ -39,10 +39,3 @@ export class PrivateReference {
}) })
export class ExpectNumericType { export class ExpectNumericType {
} }
@Component({
template: '{{ (name | lowercase).~{string-pipe}substring }}',
})
export class LowercasePipe {
name: string = 'name';
}

View File

@ -21,7 +21,6 @@ import * as ParsingCases from './parsing-cases';
declarations: [ declarations: [
AppComponent, AppComponent,
ExpressionCases.ExpectNumericType, ExpressionCases.ExpectNumericType,
ExpressionCases.LowercasePipe,
ExpressionCases.PrivateReference, ExpressionCases.PrivateReference,
ExpressionCases.WrongFieldReference, ExpressionCases.WrongFieldReference,
ExpressionCases.WrongSubFieldReference, ExpressionCases.WrongSubFieldReference,
@ -38,7 +37,6 @@ import * as ParsingCases from './parsing-cases';
ParsingCases.HintModel, ParsingCases.HintModel,
ParsingCases.NoValueAttribute, ParsingCases.NoValueAttribute,
ParsingCases.NumberModel, ParsingCases.NumberModel,
ParsingCases.Pipes,
ParsingCases.References, ParsingCases.References,
ParsingCases.StringModel, ParsingCases.StringModel,
ParsingCases.TemplateReference, ParsingCases.TemplateReference,

View File

@ -31,13 +31,6 @@ export class CaseMissingClosing {
export class CaseUnknown { export class CaseUnknown {
} }
@Component({
template: '<h1>{{data | ~{before-pipe}lowe~{in-pipe}rcase~{after-pipe} }}',
})
export class Pipes {
data = 'Some string';
}
@Component({ @Component({
template: '<h1 h~{no-value-attribute}></h1>', template: '<h1 h~{no-value-attribute}></h1>',
}) })

View File

@ -94,7 +94,7 @@ describe('TypeScriptServiceHost', () => {
const tsLS = ts.createLanguageService(tsLSHost); const tsLS = ts.createLanguageService(tsLSHost);
const ngLSHost = new TypeScriptServiceHost(tsLSHost, tsLS); const ngLSHost = new TypeScriptServiceHost(tsLSHost, tsLS);
const templates = ngLSHost.getTemplates('/app/parsing-cases.ts'); const templates = ngLSHost.getTemplates('/app/parsing-cases.ts');
expect(templates.length).toBe(9); expect(templates.length).toBe(8);
}); });
it('should be able to find external template', () => { it('should be able to find external template', () => {