• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2023 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 */
16
17import {ScrollingModule} from '@angular/cdk/scrolling';
18import {CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA} from '@angular/core';
19import {ComponentFixture, ComponentFixtureAutoDetect, TestBed} from '@angular/core/testing';
20import {MatDividerModule} from '@angular/material/divider';
21import {
22  CrossPlatform,
23  ShellTransitionData,
24  Transition,
25  TransitionChange,
26  TransitionType,
27  WmTransitionData,
28} from 'trace/flickerlib/common';
29import {TimestampType} from 'trace/timestamp';
30import {UiData} from './ui_data';
31import {ViewerTransitionsComponent} from './viewer_transitions_component';
32
33describe('ViewerTransitionsComponent', () => {
34  let fixture: ComponentFixture<ViewerTransitionsComponent>;
35  let component: ViewerTransitionsComponent;
36  let htmlElement: HTMLElement;
37
38  beforeAll(async () => {
39    await TestBed.configureTestingModule({
40      providers: [{provide: ComponentFixtureAutoDetect, useValue: true}],
41      imports: [MatDividerModule, ScrollingModule],
42      declarations: [ViewerTransitionsComponent],
43      schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
44    }).compileComponents();
45
46    fixture = TestBed.createComponent(ViewerTransitionsComponent);
47    component = fixture.componentInstance;
48    htmlElement = fixture.nativeElement;
49
50    component.uiData = makeUiData();
51    fixture.detectChanges();
52  });
53
54  it('can be created', () => {
55    expect(component).toBeTruthy();
56  });
57
58  it('renders entries', () => {
59    expect(htmlElement.querySelector('.scroll')).toBeTruthy();
60
61    const entry = htmlElement.querySelector('.scroll .entry');
62    expect(entry).toBeTruthy();
63    expect(entry!.innerHTML).toContain('TO_FRONT');
64    expect(entry!.innerHTML).toContain('10ns');
65  });
66
67  it('shows message when no transition is selected', () => {
68    expect(htmlElement.querySelector('.container-properties')?.innerHTML).toContain(
69      'No selected transition'
70    );
71  });
72});
73
74function makeUiData(): UiData {
75  const transitions = [
76    createMockTransition(10, 20, 30),
77    createMockTransition(40, 42, 50),
78    createMockTransition(45, 46, 49),
79    createMockTransition(55, 58, 70),
80  ];
81
82  const selectedTransition = undefined;
83  const selectedTransitionPropertiesTree = undefined;
84  const timestampType = TimestampType.REAL;
85
86  return new UiData(
87    transitions,
88    selectedTransition,
89    timestampType,
90    selectedTransitionPropertiesTree
91  );
92}
93
94function createMockTransition(
95  createTimeNanos: number,
96  sendTimeNanos: number,
97  finishTimeNanos: number
98): Transition {
99  const createTime = CrossPlatform.timestamp.fromString(createTimeNanos.toString(), null, null);
100  const sendTime = CrossPlatform.timestamp.fromString(sendTimeNanos.toString(), null, null);
101  const abortTime = null;
102  const finishTime = CrossPlatform.timestamp.fromString(finishTimeNanos.toString(), null, null);
103
104  const startTransactionId = '-1';
105  const finishTransactionId = '-1';
106  const type = TransitionType.TO_FRONT;
107  const changes: TransitionChange[] = [];
108
109  return new Transition(
110    id++,
111    new WmTransitionData(
112      createTime,
113      sendTime,
114      abortTime,
115      finishTime,
116      startTransactionId,
117      finishTransactionId,
118      type,
119      changes
120    ),
121    new ShellTransitionData()
122  );
123}
124
125let id = 0;
126