| /******************************************************************************** |
| * 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 {SimpleChange} from "@angular/core"; |
| import {async, ComponentFixture, TestBed} from "@angular/core/testing"; |
| import {EAPIProcessTaskDefinitionKey, EAPIUserRoles, IAPIProcessTask} from "../../../../core"; |
| import {StatementDetailsModule} from "../../statement-details.module"; |
| import {StatementDetailsSideMenuComponent} from "./statement-details-side-menu.component"; |
| |
| describe("StatementDetailsSideMenuComponent", () => { |
| let component: StatementDetailsSideMenuComponent; |
| let fixture: ComponentFixture<StatementDetailsSideMenuComponent>; |
| |
| beforeEach(async(() => { |
| TestBed.configureTestingModule({ |
| imports: [StatementDetailsModule] |
| }).compileComponents(); |
| })); |
| |
| beforeEach(() => { |
| fixture = TestBed.createComponent(StatementDetailsSideMenuComponent); |
| component = fixture.componentInstance; |
| fixture.detectChanges(); |
| }); |
| |
| it("should create", () => { |
| expect(component).toBeTruthy(); |
| }); |
| |
| it("should call update on input changes", () => { |
| const updateSpy = spyOn(component, "update"); |
| const keys: Array<keyof StatementDetailsSideMenuComponent> = ["appUserRoles", "appTasks"]; |
| updateSpy.calls.reset(); |
| |
| component.ngOnChanges({}); |
| expect(updateSpy).not.toHaveBeenCalled(); |
| |
| keys.map((_) => ({[_]: new SimpleChange(0, 1, false)})) |
| .forEach((changes) => { |
| component.ngOnChanges(changes); |
| expect(updateSpy).toHaveBeenCalledWith(); |
| }); |
| }); |
| |
| it("should update add buttons based upon current user roles and tasks", () => { |
| component.update(); |
| expect(component.buttonLayout).toEqual([]); |
| |
| component.appUserRoles = [EAPIUserRoles.SPA_OFFICIAL_IN_CHARGE]; |
| component.appTasks = [{ |
| ...{} as IAPIProcessTask, |
| statementId: 19, |
| taskId: "abcde", |
| taskDefinitionKey: EAPIProcessTaskDefinitionKey.ADD_BASIC_INFO_DATA |
| }]; |
| component.update(); |
| expect(component.buttonLayout.length).toEqual(2); |
| }); |
| }); |