/** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import * as ts from 'typescript'; import {createLanguageService} from '../src/language_service'; import {TypeScriptServiceHost} from '../src/typescript_host'; import {MockTypescriptHost} from './test_utils'; const TEST_TEMPLATE = '/app/test.ng'; describe('hover', () => { const mockHost = new MockTypescriptHost(['/app/main.ts']); const tsLS = ts.createLanguageService(mockHost); const ngLSHost = new TypeScriptServiceHost(mockHost, tsLS); const ngLS = createLanguageService(ngLSHost); beforeEach(() => { mockHost.reset(); }); it('should be able to find field in an interpolation', () => { const fileName = mockHost.addCode(` @Component({ template: '{{«name»}}' }) export class MyComponent { name: string; }`); const marker = mockHost.getReferenceMarkerFor(fileName, 'name'); const quickInfo = ngLS.getHoverAt(fileName, marker.start); expect(quickInfo).toBeTruthy(); const {textSpan, displayParts} = quickInfo !; expect(textSpan).toEqual(marker); expect(toText(displayParts)).toBe('(property) MyComponent.name'); }); it('should be able to find a field in a attribute reference', () => { const fileName = mockHost.addCode(` @Component({ template: '' }) export class MyComponent { name: string; }`); const marker = mockHost.getReferenceMarkerFor(fileName, 'name'); const quickInfo = ngLS.getHoverAt(fileName, marker.start); expect(quickInfo).toBeTruthy(); const {textSpan, displayParts} = quickInfo !; expect(textSpan).toEqual(marker); expect(toText(displayParts)).toBe('(property) MyComponent.name'); }); it('should be able to find a method from a call', () => { const fileName = mockHost.addCode(` @Component({ template: '
' }) export class MyComponent { myClick() { } }`); const marker = mockHost.getDefinitionMarkerFor(fileName, 'myClick'); const quickInfo = ngLS.getHoverAt(fileName, marker.start); expect(quickInfo).toBeTruthy(); const {textSpan, displayParts} = quickInfo !; expect(textSpan).toEqual(marker); expect(textSpan.length).toBe('myClick()'.length); expect(toText(displayParts)).toBe('(method) MyComponent.myClick'); }); it('should be able to find a field reference in an *ngIf', () => { const fileName = mockHost.addCode(` @Component({ template: '' }) export class MyComponent { include = true; }`); const marker = mockHost.getReferenceMarkerFor(fileName, 'include'); const quickInfo = ngLS.getHoverAt(fileName, marker.start); expect(quickInfo).toBeTruthy(); const {textSpan, displayParts} = quickInfo !; expect(textSpan).toEqual(marker); expect(toText(displayParts)).toBe('(property) MyComponent.include'); }); it('should be able to find a reference to a component', () => { const fileName = mockHost.addCode(` @Component({ template: '«<ᐱtestᐱ-comp>»' }) export class MyComponent { }`); const marker = mockHost.getDefinitionMarkerFor(fileName, 'test'); const quickInfo = ngLS.getHoverAt(fileName, marker.start); expect(quickInfo).toBeTruthy(); const {textSpan, displayParts} = quickInfo !; expect(textSpan).toEqual(marker); expect(toText(displayParts)).toBe('(component) AppModule.TestComponent: class'); }); it('should be able to find a reference to a directive', () => { const fileName = mockHost.addCode(` @Component({ template: '