UNPKG

core-graphics

Version:

A core library for creating shape-based graphic editors

77 lines (47 loc) 4.33 kB
'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 _initialStates = require('./initial-states'); var _testHistorySpec = require('./test-history.spec.js'); var _editorStateReducer4 = require('../editor-state-reducer'); var _editorStateReducer5 = _interopRequireDefault(_editorStateReducer4); var _editorAction = require('../../editor-state/editor-action'); var _historyEvent = require('../../history/history-event'); var _editorEvents = require('../editor-events'); 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; } (0, _tap.test)('setGraphicalContextData', function (t) { var newContext = { some: 'context' }; var ev = (0, _editorEvents.setGraphicalContextData)(newContext); var _editorStateReducer = (0, _editorStateReducer5.default)(_initialStates.EMPTY_INITIAL_STATE, ev); var graphicalContextData = _editorStateReducer.graphicalContextData; t.deepEqual(graphicalContextData, newContext); t.end(); }); (0, _tap.test)('setShapeGraphicalContextData', function (t) { var _newContext, _graphicalContextData; var shapeId = _testHistorySpec.ALICE_LINE.id; var newContext = (_newContext = {}, _defineProperty(_newContext, _testHistorySpec.STROKE_COLOR, '#111'), _defineProperty(_newContext, _testHistorySpec.STROKE_WIDTH, 4), _defineProperty(_newContext, 'someOtherContext', 'some'), _newContext); var ev = (0, _editorEvents.setShapeGraphicalContextData)(shapeId, newContext); var expectedShapeData = _extends({}, _testHistorySpec.ALICE_LINE, { graphicalContextData: (_graphicalContextData = {}, _defineProperty(_graphicalContextData, _testHistorySpec.STROKE_COLOR, '#111'), _defineProperty(_graphicalContextData, _testHistorySpec.STROKE_WIDTH, 4), _graphicalContextData) }); var expectedQueue = [(0, _editorAction.pushHistoryEventAction)((0, _historyEvent.shapeUpdateEvent)(shapeId, expectedShapeData))]; var _editorStateReducer2 = (0, _editorStateReducer5.default)(_testHistorySpec.ALICE_BOB_LINES_EDITOR_STATE, ev); var editorActionsQueue = _editorStateReducer2.editorActionsQueue; // editorActionsQueue is correct t.deepEqual(editorActionsQueue, expectedQueue); t.end(); }); (0, _tap.test)('mergeShapesGraphicalContextData', function (t) { var _ctx, _graphicalContextData2, _graphicalContextData3, _expectedShapesData; var shapeIds = [_testHistorySpec.ALICE_LINE.id, _testHistorySpec.BOB_LINE.id]; var ctx = (_ctx = {}, _defineProperty(_ctx, _testHistorySpec.STROKE_COLOR, '#111'), _defineProperty(_ctx, 'someOtherContext', 4), _ctx); var ev = (0, _editorEvents.mergeShapesGraphicalContextData)(shapeIds, ctx); var expectedShapesData = (_expectedShapesData = {}, _defineProperty(_expectedShapesData, _testHistorySpec.ALICE_LINE.id, _extends({}, _testHistorySpec.ALICE_LINE, { graphicalContextData: (_graphicalContextData2 = {}, _defineProperty(_graphicalContextData2, _testHistorySpec.STROKE_COLOR, '#111'), _defineProperty(_graphicalContextData2, _testHistorySpec.STROKE_WIDTH, 2), _graphicalContextData2) })), _defineProperty(_expectedShapesData, _testHistorySpec.BOB_LINE.id, _extends({}, _testHistorySpec.BOB_LINE, { graphicalContextData: (_graphicalContextData3 = {}, _defineProperty(_graphicalContextData3, _testHistorySpec.STROKE_COLOR, '#111'), _defineProperty(_graphicalContextData3, _testHistorySpec.STROKE_WIDTH, 4), _graphicalContextData3) })), _expectedShapesData); var expectedQueue = [(0, _editorAction.pushHistoryEventAction)((0, _historyEvent.historyEventsGroup)(shapeIds.map(function (id) { return (0, _historyEvent.shapeUpdateEvent)(id, expectedShapesData[id]); })))]; var _editorStateReducer3 = (0, _editorStateReducer5.default)(_testHistorySpec.ALICE_BOB_LINES_EDITOR_STATE, ev); var editorActionsQueue = _editorStateReducer3.editorActionsQueue; t.deepEqual(editorActionsQueue, expectedQueue); t.end(); });