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 {ScrollingModule} from '@angular/cdk/scrolling'; 17import {CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA} from '@angular/core'; 18import {ComponentFixture, ComponentFixtureAutoDetect, TestBed} from '@angular/core/testing'; 19import {MatDividerModule} from '@angular/material/divider'; 20import {PropertiesTreeGenerator} from 'viewers/common/properties_tree_generator'; 21import {UiData, UiDataEntry} from './ui_data'; 22import {ViewerTransactionsComponent} from './viewer_transactions_component'; 23 24describe('ViewerTransactionsComponent', () => { 25 let fixture: ComponentFixture<ViewerTransactionsComponent>; 26 let component: ViewerTransactionsComponent; 27 let htmlElement: HTMLElement; 28 29 beforeAll(async () => { 30 await TestBed.configureTestingModule({ 31 providers: [{provide: ComponentFixtureAutoDetect, useValue: true}], 32 imports: [MatDividerModule, ScrollingModule], 33 declarations: [ViewerTransactionsComponent], 34 schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA], 35 }).compileComponents(); 36 37 fixture = TestBed.createComponent(ViewerTransactionsComponent); 38 component = fixture.componentInstance; 39 htmlElement = fixture.nativeElement; 40 41 component.uiData = await makeUiData(); 42 fixture.detectChanges(); 43 }); 44 45 it('can be created', () => { 46 expect(component).toBeTruthy(); 47 }); 48 49 it('renders filters', () => { 50 expect(htmlElement.querySelector('.entries .filters .pid')).toBeTruthy(); 51 expect(htmlElement.querySelector('.entries .filters .uid')).toBeTruthy(); 52 expect(htmlElement.querySelector('.entries .filters .type')).toBeTruthy(); 53 expect(htmlElement.querySelector('.entries .filters .id')).toBeTruthy(); 54 }); 55 56 it('renders entries', () => { 57 expect(htmlElement.querySelector('.scroll')).toBeTruthy(); 58 59 const entry = htmlElement.querySelector('.scroll .entry'); 60 expect(entry).toBeTruthy(); 61 expect(entry!.innerHTML).toContain('TIME_VALUE'); 62 expect(entry!.innerHTML).toContain('-111'); 63 expect(entry!.innerHTML).toContain('PID_VALUE'); 64 expect(entry!.innerHTML).toContain('UID_VALUE'); 65 expect(entry!.innerHTML).toContain('TYPE_VALUE'); 66 expect(entry!.innerHTML).toContain('ID_VALUE'); 67 expect(entry!.innerHTML).toContain('flag1 | flag2 | ...'); 68 }); 69 70 it('renders properties', () => { 71 expect(htmlElement.querySelector('.properties-tree')).toBeTruthy(); 72 }); 73}); 74 75async function makeUiData(): Promise<UiData> { 76 const propertiesTree = new PropertiesTreeGenerator().generate('ROOT', {KEY: 'VALUE'}); 77 78 const entry = new UiDataEntry( 79 0, 80 'TIME_VALUE', 81 -111, 82 'PID_VALUE', 83 'UID_VALUE', 84 'TYPE_VALUE', 85 'LAYER_OR_DISPLAY_ID_VALUE', 86 'TRANSACTION_ID_VALUE', 87 'flag1 | flag2 | ...', 88 propertiesTree 89 ); 90 91 return new UiData([], [], [], [], [], [], [entry], 0, 0, 0, propertiesTree); 92} 93