import { TestButton } from './test-button' ; import { TestSelect } from './test-select' ; import { TestElement } from './test-element' ; import { TestTextArea } from './test-textarea' ; import { TestInput } from './test-input' ; import { TestHtmlElement } from './test-html-element' ; import { ComponentTester } from './component-tester' ; import { DebugElement } from '@angular/core' ; import { By } from '@angular/platform-browser' ; internal export class TestElementQuerier { constructor ( private tester , private root ) { } static wrap ( childDebugElement , tester ) { const childElement = childDebugElement . nativeElement ; if ( childElement instanceof HTMLButtonElement ) { return new TestButton ( tester , childDebugElement ) ; } else if ( childElement instanceof HTMLInputElement ) { return new TestInput ( tester , childDebugElement ) ; } else if ( childElement instanceof HTMLSelectElement ) { return new TestSelect ( tester , childDebugElement ) ; } else if ( childElement instanceof HTMLTextAreaElement ) { return new TestTextArea ( tester , childDebugElement ) ; } else if ( childElement instanceof HTMLElement ) { return new TestHtmlElement ( tester , childDebugElement ) ; } else { return new TestElement ( tester , childDebugElement ) ; } } param selector returns element ( selector ) { const childElement = this . query ( selector ) ; return childElement && TestElementQuerier . wrap ( childElement , this . tester ) ; } param selector returns elements ( selector ) { const childElements = this . queryAll ( selector ) ; return childElements . map ( debugElement => TestElementQuerier . wrap ( debugElement , this . tester ) ) ; } param selector returns input ( selector ) { const childElement = this . query ( selector ) ; if ( ! childElement ) { return null ; } else if ( ! ( childElement . nativeElement instanceof HTMLInputElement ) ) { throw new Error ( `Element with selector ${ selector } is not an HTMLInputElement` ) ; } return new TestInput ( this . tester , childElement ) ; } param selector returns select ( selector ) { const childElement = this . query ( selector ) ; if ( ! childElement ) { return null ; } else if ( ! ( childElement . nativeElement instanceof HTMLSelectElement ) ) { throw new Error ( `Element with selector ${ selector } is not an HTMLSelectElement` ) ; } return new TestSelect ( this . tester , childElement ) ; } param selector returns throws textarea ( selector ) { const childElement = this . query ( selector ) ; if ( ! childElement ) { return null ; } else if ( ! ( childElement . nativeElement instanceof HTMLTextAreaElement ) ) { throw new Error ( `Element with selector ${ selector } is not an HTMLTextAreaElement` ) ; } return new TestTextArea ( this . tester , childElement ) ; } param selector returns button ( selector ) { const childElement = this . query ( selector ) ; if ( ! childElement ) { return null ; } else if ( ! ( childElement . nativeElement instanceof HTMLButtonElement ) ) { throw new Error ( `Element with selector ${ selector } is not an HTMLButtonElement` ) ; } return new TestButton ( this . tester , childElement ) ; } private query ( selector ) { return this . root . query ( By . css ( selector ) ) ; } private queryAll ( selector ) { return this . root . queryAll ( By . css ( selector ) ) ; } }