UNPKG

@gorpacrate/core-graphics

Version:

A core library for creating shape-based graphic editors

115 lines 5.82 kB
"use strict"; exports.__esModule = true; var tslib_1 = require("tslib"); var tap_1 = require("tap"); var history_event_1 = require("../../history/history-event"); var editor_action_1 = require("../editor-action"); var editor_events_1 = require("../editor-events"); var editor_state_1 = require("../editor-state"); var editor_state_reducer_1 = require("../editor-state-reducer"); var test_history_spec_data_1 = require("./test-history.spec-data"); var ALICE_STATE = editor_state_reducer_1["default"](editor_state_1.getInitialEditorState({ shapesDeclarations: {}, author: test_history_spec_data_1.ALICE }), editor_events_1.updateHistory(test_history_spec_data_1["default"])); var BOB_STATE = editor_state_reducer_1["default"](editor_state_1.getInitialEditorState({ shapesDeclarations: {}, author: test_history_spec_data_1.BOB }), editor_events_1.updateHistory(test_history_spec_data_1["default"])); var EVE_STATE = editor_state_reducer_1["default"](editor_state_1.getInitialEditorState({ shapesDeclarations: {}, author: test_history_spec_data_1.EVE }), editor_events_1.updateHistory(test_history_spec_data_1["default"])); // TODO de-duplicate tap_1.test('updateHistory 1', function (t) { var ev = editor_events_1.updateHistory(test_history_spec_data_1["default"]); var persistedScene = ALICE_STATE.persistedScene; var _a = editor_state_reducer_1["default"](ALICE_STATE, ev), newPersistedHistory = _a.persistedHistory, newPersistedScene = _a.persistedScene; t.deepEqual(newPersistedHistory, test_history_spec_data_1["default"]); t.notEqual(newPersistedScene, persistedScene); t.end(); }); tap_1.test('updateHistory 2', function (t) { var _a; var history = [test_history_spec_data_1["default"][0]]; var ev = editor_events_1.updateHistory(history); var expectedScene = { shapes: (_a = {}, _a[test_history_spec_data_1.ALICE_LINE.id] = test_history_spec_data_1.ALICE_LINE, _a), shapesOrder: [test_history_spec_data_1.ALICE_LINE.id] }; var _b = editor_state_reducer_1["default"](ALICE_STATE, ev), newPersistedHistory = _b.persistedHistory, newPersistedScene = _b.persistedScene, newScene = _b.scene; t.deepEqual(newPersistedHistory, history); t.deepEqual(newPersistedScene, expectedScene); t.deepEqual(newScene, expectedScene); t.end(); }); tap_1.test('undoHistory 1', function (t) { var ev = editor_events_1.undoHistory(); var expectedHistoryAction = editor_action_1.updateHistoryEventAction('3', tslib_1.__assign({}, test_history_spec_data_1["default"][3], { applied: false })); var editorActionsQueue = editor_state_reducer_1["default"](ALICE_STATE, ev).editorActionsQueue; t.equal(editorActionsQueue.length, 1); var action = editorActionsQueue[0]; t.assert(editor_action_1.isUpdateHistoryEventAction(action)); t.deepEqual(action, expectedHistoryAction); t.end(); }); tap_1.test('undoHistory 2', function (t) { var ev = editor_events_1.undoHistory(); var editorActionsQueue = editor_state_reducer_1["default"](BOB_STATE, ev).editorActionsQueue; t.equal(editorActionsQueue.length, 0); t.end(); }); tap_1.test('undoHistory 3', function (t) { var ev = editor_events_1.undoHistory(); var expectedHistoryAction = editor_action_1.updateHistoryEventAction('6', tslib_1.__assign({}, test_history_spec_data_1["default"][6], { applied: false })); var editorActionsQueue = editor_state_reducer_1["default"](EVE_STATE, ev).editorActionsQueue; t.equal(editorActionsQueue.length, 1); var action = editorActionsQueue[0]; t.assert(editor_action_1.isUpdateHistoryEventAction(action)); t.deepEqual(action, expectedHistoryAction); t.end(); }); tap_1.test('redoHistory 1', function (t) { var ev = editor_events_1.redoHistory(); var expectedHistoryAction = editor_action_1.updateHistoryEventAction('4', tslib_1.__assign({}, test_history_spec_data_1["default"][4], { applied: true })); var editorActionsQueue = editor_state_reducer_1["default"](ALICE_STATE, ev).editorActionsQueue; t.equal(editorActionsQueue.length, 1); var action = editorActionsQueue[0]; t.assert(editor_action_1.isUpdateHistoryEventAction(action)); t.deepEqual(action, expectedHistoryAction); t.end(); }); tap_1.test('redoHistory 2', function (t) { var ev = editor_events_1.redoHistory(); var expectedHistoryAction = editor_action_1.updateHistoryEventAction('1', tslib_1.__assign({}, test_history_spec_data_1["default"][1], { applied: true })); var editorActionsQueue = editor_state_reducer_1["default"](BOB_STATE, ev).editorActionsQueue; t.equal(editorActionsQueue.length, 1); var action = editorActionsQueue[0]; t.assert(editor_action_1.isUpdateHistoryEventAction(action)); t.deepEqual(action, expectedHistoryAction); t.end(); }); tap_1.test('redoHistory 3', function (t) { var ev = editor_events_1.redoHistory(); var editorActionsQueue = editor_state_reducer_1["default"](EVE_STATE, ev).editorActionsQueue; t.equal(editorActionsQueue.length, 0); t.end(); }); tap_1.test('events after undone', function (t) { var evs = [ editor_events_1.removeShapes([test_history_spec_data_1.ALICE_LINE.id]) ]; var initialState = BOB_STATE; var expectedHistoryActions = [ editor_action_1.deleteHistoryEventAction('1'), editor_action_1.deleteHistoryEventAction('2'), editor_action_1.pushHistoryEventAction(history_event_1.shapeRemoveEvent(test_history_spec_data_1.ALICE_LINE.id)) ]; var editorActionsQueue = evs.reduce(editor_state_reducer_1["default"], initialState).editorActionsQueue; t.equal(editorActionsQueue.length, 3); t.deepEqual(editorActionsQueue, expectedHistoryActions); t.end(); }); //# sourceMappingURL=history.spec.js.map