| /******************************************************************************** |
| * 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 {async, ComponentFixture, TestBed} from "@angular/core/testing"; |
| import {BrowserAnimationsModule} from "@angular/platform-browser/animations"; |
| import {Store} from "@ngrx/store"; |
| import {provideMockStore} from "@ngrx/store/testing"; |
| import {I18nModule} from "../../../../../core/i18n"; |
| import {taskSelector} from "../../../../../store/process/selectors"; |
| import { |
| compileStatementArrangementAction, |
| submitStatementEditorFormAction, |
| validateStatementArrangementAction |
| } from "../../../../../store/statements/actions"; |
| import {StatementEditorModule} from "../../statement-editor.module"; |
| import {StatementEditorFormComponent} from "./statement-editor-form.component"; |
| |
| describe("StatementEditorFormComponent", () => { |
| let store: Store; |
| let component: StatementEditorFormComponent; |
| let fixture: ComponentFixture<StatementEditorFormComponent>; |
| |
| beforeEach(async(() => { |
| TestBed.configureTestingModule({ |
| imports: [ |
| StatementEditorModule, |
| BrowserAnimationsModule, |
| I18nModule |
| ], |
| providers: [ |
| provideMockStore({ |
| initialState: {}, |
| selectors: [ |
| { |
| selector: taskSelector, |
| value: { |
| taskId: "taskId", |
| statementId: 1 |
| } |
| } |
| ] |
| }) |
| ] |
| }).compileComponents(); |
| })); |
| |
| beforeEach(() => { |
| fixture = TestBed.createComponent(StatementEditorFormComponent); |
| component = fixture.componentInstance; |
| fixture.detectChanges(); |
| store = fixture.componentRef.injector.get(Store); |
| }); |
| |
| it("should create", () => { |
| expect(component).toBeTruthy(); |
| }); |
| |
| it("should dispatch validateStatementArrangementAction on validate", async () => { |
| const dispatchSpy = spyOn(store, "dispatch"); |
| await component.validate(); |
| expect(dispatchSpy).toHaveBeenCalledWith( |
| validateStatementArrangementAction({statementId: 1, taskId: "taskId", arrangement: []})); |
| }); |
| |
| it("should dispatch compileStatementArrangementAction on compile", async () => { |
| const dispatchSpy = spyOn(store, "dispatch"); |
| await component.compile(); |
| expect(dispatchSpy).toHaveBeenCalledWith( |
| compileStatementArrangementAction({statementId: 1, taskId: "taskId", arrangement: []})); |
| }); |
| |
| it("should dispatch submitStatementEditorFormAction on submit", async () => { |
| const dispatchSpy = spyOn(store, "dispatch"); |
| await component.submit(); |
| expect(dispatchSpy).toHaveBeenCalledWith( |
| submitStatementEditorFormAction( |
| {statementId: 1, taskId: "taskId", value: {arrangement: [], attachments: {edit: [], add: []}}})); |
| }); |
| }); |