• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2024 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 {HttpClientModule} from '@angular/common/http';
17import {ComponentFixture, TestBed} from '@angular/core/testing';
18import {MatDialogModule} from '@angular/material/dialog';
19import {MatIconModule} from '@angular/material/icon';
20import {ShortcutsComponent} from './shortcuts_component';
21
22describe('ShortcutsComponent', () => {
23  let fixture: ComponentFixture<ShortcutsComponent>;
24  let component: ShortcutsComponent;
25  let htmlElement: HTMLElement;
26
27  beforeEach(async () => {
28    await TestBed.configureTestingModule({
29      imports: [MatIconModule, HttpClientModule, MatDialogModule],
30      declarations: [ShortcutsComponent],
31    }).compileComponents();
32    fixture = TestBed.createComponent(ShortcutsComponent);
33    component = fixture.componentInstance;
34    htmlElement = fixture.nativeElement;
35    fixture.detectChanges();
36  });
37
38  it('can be created', () => {
39    expect(component).toBeTruthy();
40  });
41
42  it('renders key shortcuts', () => {
43    checkShortcuts('.key-shortcut', [
44      ['zoom in'],
45      ['zoom out'],
46      ['slider left'],
47      ['slider right'],
48      ['previous'],
49      ['next'],
50    ]);
51  });
52
53  it('renders pointer shortcuts', () => {
54    checkShortcuts('.pointer-shortcut', [
55      ['right click', 'bookmarks'],
56      ['vertical scroll', 'zoom'],
57      ['horizontal scroll', 'move slider'],
58      ['vertical scroll', 'zoom'],
59    ]);
60  });
61
62  function checkShortcuts(
63    shortcutsSelector: string,
64    expectedContent: string[][],
65  ) {
66    const shortcuts = htmlElement.querySelectorAll(shortcutsSelector);
67    expect(shortcuts.length).toEqual(expectedContent.length);
68
69    for (let i = 0; i < expectedContent.length; i++) {
70      expectedContent[i].forEach((s) => {
71        expect(shortcuts.item(i).textContent?.toLowerCase()).toContain(s);
72      });
73    }
74  }
75});
76