• 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 */
16
17import {ComponentFixture, TestBed} from '@angular/core/testing';
18import {MatButtonModule} from '@angular/material/button';
19import {MatIconModule} from '@angular/material/icon';
20import {assertDefined} from 'common/assert_utils';
21import {CollapsibleSectionTitleComponent} from './collapsible_section_title_component';
22
23describe('CollapsibleSectionTitleComponent', () => {
24  let fixture: ComponentFixture<CollapsibleSectionTitleComponent>;
25  let component: CollapsibleSectionTitleComponent;
26  let htmlElement: HTMLElement;
27
28  beforeEach(async () => {
29    await TestBed.configureTestingModule({
30      imports: [MatButtonModule, MatIconModule],
31      declarations: [CollapsibleSectionTitleComponent],
32    }).compileComponents();
33    fixture = TestBed.createComponent(CollapsibleSectionTitleComponent);
34    component = fixture.componentInstance;
35    htmlElement = fixture.nativeElement;
36    component.title = 'collapsible section';
37    fixture.detectChanges();
38  });
39
40  it('can be created', () => {
41    expect(component).toBeTruthy();
42  });
43
44  it('displays button and title', () => {
45    assertDefined(htmlElement.querySelector('button'));
46    const title = assertDefined(htmlElement.querySelector('.mat-title'));
47    expect(title.textContent).toContain('COLLAPSIBLE SECTION');
48  });
49
50  it('emits collapseButtonClicked event', () => {
51    const spy = spyOn(component.collapseButtonClicked, 'emit');
52    const collapseButton = assertDefined(
53      htmlElement.querySelector('button'),
54    ) as HTMLElement;
55    collapseButton.click();
56    fixture.detectChanges();
57    expect(spy).toHaveBeenCalledTimes(1);
58  });
59});
60