blob: 0cfd30c0ebd713151159ddcd22c5f45c75379007 [file] [log] [blame]
/********************************************************************************
* Copyright (c) 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
import {Component, ElementRef, ViewChild} from "@angular/core";
import {ComponentFixture, TestBed} from "@angular/core/testing";
import {MatIconModule} from "@angular/material/icon";
import {By} from "@angular/platform-browser";
import {RouterTestingModule} from "@angular/router/testing";
import {I18nModule} from "../../../core/i18n";
import {IStatementTableEntry} from "./IStatementTableEntry";
import {StatementTableComponent} from "./statement-table.component";
import {StatementTableModule} from "./statement-table.module";
@Component({
selector: `app-host-component`,
template: `
<div style="height: 200px;">
<app-statement-table #predecessors [appEntries]="appData"></app-statement-table>
</div>
`
})
class TestHostComponent {
public appData: Array<IStatementTableEntry>;
@ViewChild("history", {read: ElementRef}) history: ElementRef;
public constructor() {
this.appData = (new Array(40)).fill({
isPredecessor: true,
id: 1,
title: "ein Titel",
type: "Bauvorhaben",
receiptDate: "2007-08-31T16:47+00:00",
city: "Stadt",
district: "Ortsteil"
});
}
}
describe("StatementTableComponent", () => {
let component: TestHostComponent;
let fixture: ComponentFixture<TestHostComponent>;
let childComponent: StatementTableComponent;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [StatementTableComponent, TestHostComponent],
imports: [
StatementTableModule,
I18nModule,
MatIconModule,
RouterTestingModule
],
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(TestHostComponent);
component = fixture.componentInstance;
const childDebugElement = fixture.debugElement.query(By.directive(StatementTableComponent));
childComponent = childDebugElement.componentInstance;
fixture.detectChanges();
});
it("should create", () => {
expect(component).toBeTruthy();
});
it("should emit appToggleSelect with the id and corresponding checked value", () => {
spyOn(childComponent.appToggleSelect, "emit").and.callThrough();
childComponent.select(1);
expect(childComponent.appToggleSelect.emit).toHaveBeenCalledWith({id: 1, value: true});
childComponent.deselect(1);
expect(childComponent.appToggleSelect.emit).toHaveBeenCalledWith({id: 1, value: false});
});
});