blob: 153f7257be58b0eb3d85a2100421acf3d66353ca [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 {Action} from "@ngrx/store";
import {createAttachmentFileMock} from "../../../../test";
import {addAttachmentErrorAction, clearFileCacheAction} from "../../actions";
import {IAttachmentsStoreState} from "../../model";
import {statementFileCacheReducer} from "./statement-file-cache.reducer";
describe("statementFileCacheReducer", () => {
const file = createAttachmentFileMock("test.pdf");
const initialState: IAttachmentsStoreState["statementFileCache"] = {
1919: [file]
};
it("should set file cache on add attachment errors", () => {
const action = addAttachmentErrorAction({
statementId: 1919,
taskId: "1919",
addError: [
{
attachment: createAttachmentFileMock("File 0.pdf"),
error: new Error("")
},
{
attachment: createAttachmentFileMock("File 0.pdf"),
error: new Error("")
}
],
removeError: []
});
const state = statementFileCacheReducer(initialState, action);
expect(state).toEqual({
1919: action.addError.map((_) => _.attachment)
});
});
it("should clear file cache", () => {
const action: Action = clearFileCacheAction({
statementId: 1919
});
const state = statementFileCacheReducer(initialState, action);
expect(state).toEqual({});
});
});