core-graphics
Version:
A core library for creating shape-based graphic editors
176 lines (111 loc) • 6.67 kB
JavaScript
'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _tap = require('tap');
var _editorStateReducer9 = require('../editor-state-reducer');
var _editorStateReducer10 = _interopRequireDefault(_editorStateReducer9);
var _editorAction = require('../../editor-state/editor-action');
var _historyEvent = require('../../history/history-event');
var _editorEvents = require('../editor-events');
var _editorState = require('../editor-state');
var _testHistorySpec = require('./test-history.spec.js');
var _testHistorySpec2 = _interopRequireDefault(_testHistorySpec);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var ALICE_STATE = (0, _editorStateReducer10.default)((0, _editorState.getInitialEditorState)({ shapesDeclarations: {}, author: _testHistorySpec.ALICE }), (0, _editorEvents.updateHistory)(_testHistorySpec2.default));
var BOB_STATE = (0, _editorStateReducer10.default)((0, _editorState.getInitialEditorState)({ shapesDeclarations: {}, author: _testHistorySpec.BOB }), (0, _editorEvents.updateHistory)(_testHistorySpec2.default));
var EVE_STATE = (0, _editorStateReducer10.default)((0, _editorState.getInitialEditorState)({ shapesDeclarations: {}, author: _testHistorySpec.EVE }), (0, _editorEvents.updateHistory)(_testHistorySpec2.default));
// TODO de-duplicate
(0, _tap.test)('updateHistory 1', function (t) {
var ev = (0, _editorEvents.updateHistory)(_testHistorySpec2.default);
var persistedScene = ALICE_STATE.persistedScene;
var _editorStateReducer = (0, _editorStateReducer10.default)(ALICE_STATE, ev);
var newPersistedHistory = _editorStateReducer.persistedHistory;
var newPersistedScene = _editorStateReducer.persistedScene;
t.deepEqual(newPersistedHistory, _testHistorySpec2.default);
t.notEqual(newPersistedScene, persistedScene);
t.end();
});
(0, _tap.test)('updateHistory 2', function (t) {
var history = [_testHistorySpec2.default[0]];
var ev = (0, _editorEvents.updateHistory)(history);
var expectedScene = {
shapes: _defineProperty({}, _testHistorySpec.ALICE_LINE.id, _testHistorySpec.ALICE_LINE),
shapesOrder: [_testHistorySpec.ALICE_LINE.id]
};
var _editorStateReducer2 = (0, _editorStateReducer10.default)(ALICE_STATE, ev);
var newPersistedHistory = _editorStateReducer2.persistedHistory;
var newPersistedScene = _editorStateReducer2.persistedScene;
var newScene = _editorStateReducer2.scene;
t.deepEqual(newPersistedHistory, history);
t.deepEqual(newPersistedScene, expectedScene);
t.deepEqual(newScene, expectedScene);
t.end();
});
(0, _tap.test)('undoHistory 1', function (t) {
var ev = (0, _editorEvents.undoHistory)();
var expectedHistoryAction = (0, _editorAction.updateHistoryEventAction)('3', _extends({}, _testHistorySpec2.default[3], { applied: false }));
var _editorStateReducer3 = (0, _editorStateReducer10.default)(ALICE_STATE, ev);
var editorActionsQueue = _editorStateReducer3.editorActionsQueue;
t.equal(editorActionsQueue.length, 1);
var action = editorActionsQueue[0];
t.assert((0, _editorAction.isUpdateHistoryEventAction)(action));
t.deepEqual(action, expectedHistoryAction);
t.end();
});
(0, _tap.test)('undoHistory 2', function (t) {
var ev = (0, _editorEvents.undoHistory)();
var _editorStateReducer4 = (0, _editorStateReducer10.default)(BOB_STATE, ev);
var editorActionsQueue = _editorStateReducer4.editorActionsQueue;
t.equal(editorActionsQueue.length, 0);
t.end();
});
(0, _tap.test)('undoHistory 3', function (t) {
var ev = (0, _editorEvents.undoHistory)();
var expectedHistoryAction = (0, _editorAction.updateHistoryEventAction)('6', _extends({}, _testHistorySpec2.default[6], { applied: false }));
var _editorStateReducer5 = (0, _editorStateReducer10.default)(EVE_STATE, ev);
var editorActionsQueue = _editorStateReducer5.editorActionsQueue;
t.equal(editorActionsQueue.length, 1);
var action = editorActionsQueue[0];
t.assert((0, _editorAction.isUpdateHistoryEventAction)(action));
t.deepEqual(action, expectedHistoryAction);
t.end();
});
(0, _tap.test)('redoHistory 1', function (t) {
var ev = (0, _editorEvents.redoHistory)();
var expectedHistoryAction = (0, _editorAction.updateHistoryEventAction)('4', _extends({}, _testHistorySpec2.default[4], { applied: true }));
var _editorStateReducer6 = (0, _editorStateReducer10.default)(ALICE_STATE, ev);
var editorActionsQueue = _editorStateReducer6.editorActionsQueue;
t.equal(editorActionsQueue.length, 1);
var action = editorActionsQueue[0];
t.assert((0, _editorAction.isUpdateHistoryEventAction)(action));
t.deepEqual(action, expectedHistoryAction);
t.end();
});
(0, _tap.test)('redoHistory 2', function (t) {
var ev = (0, _editorEvents.redoHistory)();
var expectedHistoryAction = (0, _editorAction.updateHistoryEventAction)('1', _extends({}, _testHistorySpec2.default[1], { applied: true }));
var _editorStateReducer7 = (0, _editorStateReducer10.default)(BOB_STATE, ev);
var editorActionsQueue = _editorStateReducer7.editorActionsQueue;
t.equal(editorActionsQueue.length, 1);
var action = editorActionsQueue[0];
t.assert((0, _editorAction.isUpdateHistoryEventAction)(action));
t.deepEqual(action, expectedHistoryAction);
t.end();
});
(0, _tap.test)('redoHistory 3', function (t) {
var ev = (0, _editorEvents.redoHistory)();
var _editorStateReducer8 = (0, _editorStateReducer10.default)(EVE_STATE, ev);
var editorActionsQueue = _editorStateReducer8.editorActionsQueue;
t.equal(editorActionsQueue.length, 0);
t.end();
});
(0, _tap.test)('events after undone', function (t) {
var evs = [(0, _editorEvents.removeShapes)([_testHistorySpec.ALICE_LINE.id])];
var initialState = BOB_STATE;
var expectedHistoryActions = [(0, _editorAction.deleteHistoryEventAction)('1'), (0, _editorAction.deleteHistoryEventAction)('2'), (0, _editorAction.pushHistoryEventAction)((0, _historyEvent.shapeRemoveEvent)(_testHistorySpec.ALICE_LINE.id))];
var _evs$reduce = evs.reduce(_editorStateReducer10.default, initialState);
var editorActionsQueue = _evs$reduce.editorActionsQueue;
t.equal(editorActionsQueue.length, 3);
t.deepEqual(editorActionsQueue, expectedHistoryActions);
t.end();
});