1/* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16import {Component, NO_ERRORS_SCHEMA, ViewChild} from '@angular/core'; 17import {ComponentFixture, ComponentFixtureAutoDetect, TestBed} from '@angular/core/testing'; 18import {PersistentStore} from 'common/persistent_store'; 19import {UiTreeNode} from 'viewers/common/ui_tree_utils'; 20import {TreeComponent} from './tree_component'; 21 22describe('TreeComponent', () => { 23 let fixture: ComponentFixture<TestHostComponent>; 24 let component: TestHostComponent; 25 let htmlElement: HTMLElement; 26 27 beforeAll(async () => { 28 await TestBed.configureTestingModule({ 29 providers: [{provide: ComponentFixtureAutoDetect, useValue: true}], 30 declarations: [TreeComponent, TestHostComponent], 31 schemas: [NO_ERRORS_SCHEMA], 32 }).compileComponents(); 33 }); 34 35 beforeEach(() => { 36 fixture = TestBed.createComponent(TestHostComponent); 37 component = fixture.componentInstance; 38 htmlElement = fixture.nativeElement; 39 }); 40 41 it('can be created', () => { 42 fixture.detectChanges(); 43 expect(component).toBeTruthy(); 44 }); 45 46 @Component({ 47 selector: 'host-component', 48 template: ` 49 <tree-view 50 [item]="item" 51 [store]="store" 52 [isFlattened]="isFlattened" 53 [diffClass]="diffClass" 54 [isHighlighted]="isHighlighted" 55 [hasChildren]="hasChildren"></tree-view> 56 `, 57 }) 58 class TestHostComponent { 59 isFlattened = true; 60 item: UiTreeNode = { 61 simplifyNames: false, 62 kind: 'entry', 63 name: 'LayerTraceEntry', 64 shortName: 'LTE', 65 chips: [], 66 children: [{kind: '3', stableId: '3', name: 'Child1'}], 67 }; 68 store = new PersistentStore(); 69 diffClass = jasmine.createSpy().and.returnValue('none'); 70 isHighlighted = jasmine.createSpy().and.returnValue(false); 71 hasChildren = jasmine.createSpy().and.returnValue(true); 72 73 @ViewChild(TreeComponent) 74 treeComponent!: TreeComponent; 75 } 76}); 77