@pie-lib/mask-markup 3.0.4-next.33 → 3.0.4-next.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/CHANGELOG.json +17 -0
  2. package/CHANGELOG.md +1256 -0
  3. package/LICENSE.md +5 -0
  4. package/lib/choices/choice.js +116 -0
  5. package/lib/choices/choice.js.map +1 -0
  6. package/lib/choices/index.js +103 -0
  7. package/lib/choices/index.js.map +1 -0
  8. package/lib/componentize.js +21 -0
  9. package/lib/componentize.js.map +1 -0
  10. package/lib/components/blank.js +371 -0
  11. package/lib/components/blank.js.map +1 -0
  12. package/lib/components/correct-input.js +94 -0
  13. package/lib/components/correct-input.js.map +1 -0
  14. package/lib/components/dropdown.js +483 -0
  15. package/lib/components/dropdown.js.map +1 -0
  16. package/lib/components/input.js +50 -0
  17. package/lib/components/input.js.map +1 -0
  18. package/lib/constructed-response.js +101 -0
  19. package/lib/constructed-response.js.map +1 -0
  20. package/lib/customizable.js +42 -0
  21. package/lib/customizable.js.map +1 -0
  22. package/lib/drag-in-the-blank.js +254 -0
  23. package/lib/drag-in-the-blank.js.map +1 -0
  24. package/lib/index.js +55 -0
  25. package/lib/index.js.map +1 -0
  26. package/lib/inline-dropdown.js +40 -0
  27. package/lib/inline-dropdown.js.map +1 -0
  28. package/lib/mask.js +198 -0
  29. package/lib/mask.js.map +1 -0
  30. package/lib/serialization.js +261 -0
  31. package/lib/serialization.js.map +1 -0
  32. package/lib/with-mask.js +97 -0
  33. package/lib/with-mask.js.map +1 -0
  34. package/package.json +20 -39
  35. package/src/__tests__/drag-in-the-blank.test.js +111 -0
  36. package/src/__tests__/index.test.js +38 -0
  37. package/src/__tests__/mask.test.js +381 -0
  38. package/src/__tests__/serialization.test.js +54 -0
  39. package/src/__tests__/utils.js +1 -0
  40. package/src/__tests__/with-mask.test.js +76 -0
  41. package/src/choices/__tests__/index.test.js +75 -0
  42. package/src/choices/choice.jsx +97 -0
  43. package/src/choices/index.jsx +64 -0
  44. package/src/componentize.js +13 -0
  45. package/src/components/__tests__/blank.test.js +199 -0
  46. package/src/components/__tests__/correct-input.test.js +90 -0
  47. package/src/components/__tests__/dropdown.test.js +129 -0
  48. package/src/components/__tests__/input.test.js +102 -0
  49. package/src/components/blank.jsx +386 -0
  50. package/src/components/correct-input.jsx +82 -0
  51. package/src/components/dropdown.jsx +423 -0
  52. package/src/components/input.jsx +48 -0
  53. package/src/constructed-response.jsx +87 -0
  54. package/src/customizable.jsx +34 -0
  55. package/src/drag-in-the-blank.jsx +241 -0
  56. package/src/index.js +16 -0
  57. package/src/inline-dropdown.jsx +29 -0
  58. package/src/mask.jsx +172 -0
  59. package/src/serialization.js +260 -0
  60. package/src/with-mask.jsx +75 -0
  61. package/dist/_virtual/_rolldown/runtime.js +0 -4
  62. package/dist/choices/choice.d.ts +0 -24
  63. package/dist/choices/choice.js +0 -77
  64. package/dist/choices/index.d.ts +0 -25
  65. package/dist/choices/index.js +0 -49
  66. package/dist/componentize.d.ts +0 -12
  67. package/dist/componentize.js +0 -4
  68. package/dist/components/blank.d.ts +0 -39
  69. package/dist/components/blank.js +0 -240
  70. package/dist/components/correct-input.d.ts +0 -11
  71. package/dist/components/dropdown.d.ts +0 -37
  72. package/dist/components/dropdown.js +0 -320
  73. package/dist/components/input.d.ts +0 -37
  74. package/dist/constructed-response.d.ts +0 -44
  75. package/dist/constructed-response.js +0 -55
  76. package/dist/customizable.d.ts +0 -43
  77. package/dist/customizable.js +0 -8
  78. package/dist/drag-in-the-blank.d.ts +0 -37
  79. package/dist/drag-in-the-blank.js +0 -164
  80. package/dist/index.d.ts +0 -15
  81. package/dist/index.js +0 -7
  82. package/dist/inline-dropdown.d.ts +0 -44
  83. package/dist/inline-dropdown.js +0 -24
  84. package/dist/mask.d.ts +0 -30
  85. package/dist/mask.js +0 -99
  86. package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +0 -16
  87. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/index.js +0 -17
  88. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssPrefix.js +0 -9
  89. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/cssUnitless.js +0 -26
  90. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/hasOwn.js +0 -11
  91. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isFunction.js +0 -11
  92. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/isObject.js +0 -11
  93. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixInfo.js +0 -24
  94. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixProperties.js +0 -32
  95. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/prefixer.js +0 -29
  96. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/camelize.js +0 -14
  97. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenRe.js +0 -8
  98. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/hyphenate.js +0 -12
  99. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/separate.js +0 -11
  100. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toLowerFirst.js +0 -10
  101. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/stringUtils/toUpperFirst.js +0 -10
  102. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleObject.js +0 -55
  103. package/dist/node_modules/.bun/to-style@1.3.3/node_modules/to-style/src/toStyleString.js +0 -16
  104. package/dist/serialization.d.ts +0 -34
  105. package/dist/serialization.js +0 -132
  106. package/dist/with-mask.d.ts +0 -55
  107. package/dist/with-mask.js +0 -45
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.withMask = exports.buildLayoutFromMarkup = void 0;
8
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
11
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
12
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
13
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
+ var _react = _interopRequireDefault(require("react"));
15
+ var _propTypes = _interopRequireDefault(require("prop-types"));
16
+ var _mask = _interopRequireDefault(require("./mask"));
17
+ var _componentize2 = _interopRequireDefault(require("./componentize"));
18
+ var _serialization = require("./serialization");
19
+ function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
20
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
21
+ var buildLayoutFromMarkup = exports.buildLayoutFromMarkup = function buildLayoutFromMarkup(markup, type) {
22
+ var _componentize = (0, _componentize2["default"])(markup, type),
23
+ processed = _componentize.markup;
24
+ var value = (0, _serialization.deserialize)(processed);
25
+ return value.document;
26
+ };
27
+ var withMask = exports.withMask = function withMask(type, renderChildren) {
28
+ var _WithMask;
29
+ return _WithMask = /*#__PURE__*/function (_React$Component) {
30
+ function WithMask(props) {
31
+ var _this;
32
+ (0, _classCallCheck2["default"])(this, WithMask);
33
+ _this = _callSuper(this, WithMask, [props]);
34
+ _this.containerRef = /*#__PURE__*/_react["default"].createRef();
35
+ return _this;
36
+ }
37
+ (0, _inherits2["default"])(WithMask, _React$Component);
38
+ return (0, _createClass2["default"])(WithMask, [{
39
+ key: "componentDidUpdate",
40
+ value: function componentDidUpdate(prevProps) {
41
+ if (this.props.markup !== prevProps.markup) {
42
+ var domNode = this.containerRef.current;
43
+ var mathElements = domNode && domNode.querySelectorAll('[data-latex][data-math-handled="true"]');
44
+
45
+ // Clean up for fresh MathJax processing
46
+ (mathElements || []).forEach(function (el) {
47
+ // Remove the MathJax container to allow for clean updates
48
+ var mjxContainer = el.querySelector('mjx-container');
49
+ if (mjxContainer) {
50
+ el.removeChild(mjxContainer);
51
+ }
52
+
53
+ // Update the innerHTML to match the raw LaTeX data, ensuring it is reprocessed correctly
54
+ var latexCode = el.getAttribute('data-raw');
55
+ el.innerHTML = latexCode;
56
+
57
+ // Remove the attribute to signal that MathJax should reprocess this element
58
+ el.removeAttribute('data-math-handled');
59
+ });
60
+ }
61
+ }
62
+ }, {
63
+ key: "render",
64
+ value: function render() {
65
+ var _this$props = this.props,
66
+ markup = _this$props.markup,
67
+ layout = _this$props.layout,
68
+ value = _this$props.value,
69
+ onChange = _this$props.onChange,
70
+ elementType = _this$props.elementType;
71
+ var maskLayout = layout ? layout : buildLayoutFromMarkup(markup, type);
72
+ return /*#__PURE__*/_react["default"].createElement(_mask["default"], {
73
+ containerRef: this.containerRef,
74
+ elementType: elementType,
75
+ layout: maskLayout,
76
+ value: value,
77
+ onChange: onChange,
78
+ renderChildren: renderChildren(this.props)
79
+ });
80
+ }
81
+ }]);
82
+ }(_react["default"].Component), (0, _defineProperty2["default"])(_WithMask, "propTypes", {
83
+ /**
84
+ * At the start we'll probably work with markup
85
+ */
86
+ markup: _propTypes["default"].string,
87
+ /**
88
+ * Once we start authoring, it may make sense for use to us layout, which will be a simple js object that maps to `slate.Value`.
89
+ */
90
+ layout: _propTypes["default"].object,
91
+ value: _propTypes["default"].object,
92
+ onChange: _propTypes["default"].func,
93
+ customMarkMarkupComponent: _propTypes["default"].func,
94
+ elementType: _propTypes["default"].string
95
+ }), _WithMask;
96
+ };
97
+ //# sourceMappingURL=with-mask.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-mask.js","names":["_react","_interopRequireDefault","require","_propTypes","_mask","_componentize2","_serialization","_callSuper","t","o","e","_getPrototypeOf2","_possibleConstructorReturn2","_isNativeReflectConstruct","Reflect","construct","constructor","apply","Boolean","prototype","valueOf","call","buildLayoutFromMarkup","exports","markup","type","_componentize","componentize","processed","value","deserialize","document","withMask","renderChildren","_WithMask","_React$Component","WithMask","props","_this","_classCallCheck2","containerRef","React","createRef","_inherits2","_createClass2","key","componentDidUpdate","prevProps","domNode","current","mathElements","querySelectorAll","forEach","el","mjxContainer","querySelector","removeChild","latexCode","getAttribute","innerHTML","removeAttribute","render","_this$props","layout","onChange","elementType","maskLayout","createElement","Component","_defineProperty2","PropTypes","string","object","func","customMarkMarkupComponent"],"sources":["../src/with-mask.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport Mask from './mask';\nimport componentize from './componentize';\nimport { deserialize } from './serialization';\n\nexport const buildLayoutFromMarkup = (markup, type) => {\n const { markup: processed } = componentize(markup, type);\n const value = deserialize(processed);\n return value.document;\n};\n\nexport const withMask = (type, renderChildren) => {\n return class WithMask extends React.Component {\n static propTypes = {\n /**\n * At the start we'll probably work with markup\n */\n markup: PropTypes.string,\n /**\n * Once we start authoring, it may make sense for use to us layout, which will be a simple js object that maps to `slate.Value`.\n */\n layout: PropTypes.object,\n value: PropTypes.object,\n onChange: PropTypes.func,\n customMarkMarkupComponent: PropTypes.func,\n elementType: PropTypes.string,\n };\n\n constructor(props) {\n super(props);\n this.containerRef = React.createRef();\n }\n\n componentDidUpdate(prevProps) {\n if (this.props.markup !== prevProps.markup) {\n const domNode = this.containerRef.current;\n const mathElements = domNode && domNode.querySelectorAll('[data-latex][data-math-handled=\"true\"]');\n\n // Clean up for fresh MathJax processing\n (mathElements || []).forEach((el) => {\n // Remove the MathJax container to allow for clean updates\n const mjxContainer = el.querySelector('mjx-container');\n\n if (mjxContainer) {\n el.removeChild(mjxContainer);\n }\n\n // Update the innerHTML to match the raw LaTeX data, ensuring it is reprocessed correctly\n const latexCode = el.getAttribute('data-raw');\n el.innerHTML = latexCode;\n\n // Remove the attribute to signal that MathJax should reprocess this element\n el.removeAttribute('data-math-handled');\n });\n }\n }\n\n render() {\n const { markup, layout, value, onChange, elementType } = this.props;\n\n const maskLayout = layout ? layout : buildLayoutFromMarkup(markup, type);\n return (\n <Mask\n containerRef={this.containerRef}\n elementType={elementType}\n layout={maskLayout}\n value={value}\n onChange={onChange}\n renderChildren={renderChildren(this.props)}\n />\n );\n }\n };\n};\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,KAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,cAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AAA8C,SAAAK,WAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,WAAAD,CAAA,OAAAE,gBAAA,aAAAF,CAAA,OAAAG,2BAAA,aAAAJ,CAAA,EAAAK,yBAAA,KAAAC,OAAA,CAAAC,SAAA,CAAAN,CAAA,EAAAC,CAAA,YAAAC,gBAAA,aAAAH,CAAA,EAAAQ,WAAA,IAAAP,CAAA,CAAAQ,KAAA,CAAAT,CAAA,EAAAE,CAAA;AAAA,SAAAG,0BAAA,cAAAL,CAAA,IAAAU,OAAA,CAAAC,SAAA,CAAAC,OAAA,CAAAC,IAAA,CAAAP,OAAA,CAAAC,SAAA,CAAAG,OAAA,iCAAAV,CAAA,aAAAK,yBAAA,YAAAA,0BAAA,aAAAL,CAAA;AAEvC,IAAMc,qBAAqB,GAAAC,OAA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W,EAAEK,qBAAS,CAACC;EACzB,CAAC,GAAArC,SAAA;AA+CL,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,51 +1,32 @@
1
1
  {
2
2
  "name": "@pie-lib/mask-markup",
3
- "version": "3.0.4-next.33",
3
+ "version": "3.0.4-next.34+e93c7b3c1",
4
4
  "description": "",
5
+ "main": "lib/index.js",
6
+ "module": "src/index.js",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": "pie-framework/pie-lib",
5
11
  "dependencies": {
6
12
  "@emotion/react": "^11.14.0",
7
13
  "@emotion/style": "^0.8.0",
8
14
  "@mui/icons-material": "^7.3.4",
9
15
  "@mui/material": "^7.3.4",
10
- "@pie-lib/drag": "4.0.3-next.38",
11
- "@pie-lib/editable-html-tip-tap": "2.1.2-next.31",
12
- "@pie-lib/render-ui": "6.1.1-next.38",
16
+ "@pie-lib/drag": "^4.0.2",
17
+ "@pie-lib/editable-html-tip-tap": "^2.1.2-next.34+e93c7b3c1",
18
+ "@pie-lib/math-rendering": "^5.0.2",
19
+ "@pie-lib/render-ui": "^6.1.0",
20
+ "classnames": "^2.2.6",
13
21
  "debug": "^4.1.1",
22
+ "lodash-es": "^4.17.23",
14
23
  "prop-types": "^15.7.2",
15
- "to-style": "^1.3.3",
16
- "@dnd-kit/core": "^6.3.1",
17
- "@pie-element/shared-math-rendering-mathjax": "0.1.1-next.0",
18
- "@pie-element/shared-lodash": "0.1.1-next.1",
19
- "@dnd-kit/utilities": "^3.2.2",
20
- "clsx": "^2.1.1"
21
- },
22
- "type": "module",
23
- "main": "./dist/index.js",
24
- "types": "./dist/index.d.ts",
25
- "exports": {
26
- ".": {
27
- "types": "./dist/index.d.ts",
28
- "default": "./dist/index.js"
29
- }
30
- },
31
- "files": [
32
- "dist"
33
- ],
34
- "sideEffects": false,
35
- "scripts": {
36
- "build": "bun x vite build && bun x tsc --emitDeclarationOnly",
37
- "dev": "bun x vite",
38
- "test": "bun x vitest run"
39
- },
40
- "devDependencies": {
41
- "vite": "^8.0.1",
42
- "typescript": "^5.9.3",
43
- "@vitejs/plugin-react": "^6.0.1",
44
- "@types/react": "^18.2.0",
45
- "@types/react-dom": "^18.2.0"
24
+ "react": "^18.2.0",
25
+ "react-dom": "^18.2.0",
26
+ "to-style": "^1.3.3"
46
27
  },
47
- "peerDependencies": {
48
- "react": "^18.0.0",
49
- "react-dom": "^18.0.0"
50
- }
28
+ "keywords": [],
29
+ "author": "",
30
+ "license": "ISC",
31
+ "gitHead": "e93c7b3c148030395e15f085bb5f4c903a00554e"
51
32
  }
@@ -0,0 +1,111 @@
1
+ import * as React from 'react';
2
+ import { render, screen } from '@testing-library/react';
3
+ import DragInTheBlank from '../drag-in-the-blank';
4
+
5
+ const markup = `<div>
6
+ <img src="https://image.shutterstock.com/image-vector/cow-jumped-over-moon-traditional-260nw-1152899330.jpg"></img>
7
+ <h5>Hey Diddle Diddle <i>by ?</i></h5>
8
+ <p>1: Hey, diddle, diddle,</p>
9
+ <p>2: The cat and the fiddle,</p>
10
+ <p>3: The cow {{0}} over the moon;</p>
11
+ <p>4: The little dog {{1}},</p>
12
+ <p>5: To see such sport,</p>
13
+ <p>6: And the dish ran away with the {{2}}.</p>
14
+ </div>`;
15
+ const choice = (v, id) => ({ value: v, id });
16
+
17
+ // Mock DragProvider and DragDroppablePlaceholder to avoid DndContext requirement
18
+ jest.mock('@pie-lib/drag', () => ({
19
+ DragProvider: ({ children, onDragStart, onDragEnd }) => {
20
+ // Simple wrapper that doesn't require DndContext
21
+ return <div data-testid="drag-provider">{children}</div>;
22
+ },
23
+ DragDroppablePlaceholder: ({ children, disabled, instanceId }) => {
24
+ // Simple wrapper that doesn't require useDroppable
25
+ return <div data-testid="drag-droppable-placeholder">{children}</div>;
26
+ },
27
+ }));
28
+
29
+ // Mock @dnd-kit/core components and hooks used by DragInTheBlank and child components
30
+ jest.mock('@dnd-kit/core', () => ({
31
+ DragOverlay: ({ children }) => <div data-testid="drag-overlay">{children}</div>,
32
+ closestCenter: jest.fn(),
33
+ useDraggable: jest.fn(() => ({
34
+ attributes: {},
35
+ listeners: {},
36
+ setNodeRef: jest.fn(),
37
+ transform: null,
38
+ isDragging: false,
39
+ })),
40
+ useDroppable: jest.fn(() => ({
41
+ setNodeRef: jest.fn(),
42
+ isOver: false,
43
+ active: null,
44
+ })),
45
+ }));
46
+
47
+ jest.mock('@dnd-kit/utilities', () => ({
48
+ CSS: {
49
+ Translate: {
50
+ toString: jest.fn(() => 'translate3d(0, 0, 0)'),
51
+ },
52
+ },
53
+ }));
54
+
55
+ describe('DragInTheBlank', () => {
56
+ const defaultProps = {
57
+ disabled: false,
58
+ feedback: {},
59
+ markup,
60
+ choices: [
61
+ choice('Jumped', '0'),
62
+ choice('Laughed', '1'),
63
+ choice('Spoon', '2'),
64
+ choice('Fork', '3'),
65
+ choice('Bumped', '4'),
66
+ choice('Smiled', '5'),
67
+ ],
68
+
69
+ value: {
70
+ 0: undefined,
71
+ },
72
+ };
73
+
74
+ describe('render', () => {
75
+ it('renders correctly with default props', () => {
76
+ const { container } = render(<DragInTheBlank {...defaultProps} />);
77
+ expect(container.firstChild).toBeInTheDocument();
78
+ // Check that markup content is rendered
79
+ expect(screen.getByText(/Hey Diddle Diddle/)).toBeInTheDocument();
80
+ expect(screen.getByText(/Hey, diddle, diddle,/)).toBeInTheDocument();
81
+ });
82
+
83
+ it('renders correctly with disabled prop as true', () => {
84
+ const { container } = render(<DragInTheBlank {...defaultProps} disabled={true} />);
85
+ expect(container.firstChild).toBeInTheDocument();
86
+ });
87
+
88
+ it('renders correctly with feedback', () => {
89
+ const { container } = render(
90
+ <DragInTheBlank
91
+ {...defaultProps}
92
+ feedback={{
93
+ 0: {
94
+ value: 'Jumped',
95
+ correct: 'Jumped',
96
+ },
97
+ 1: {
98
+ value: 'Laughed',
99
+ correct: 'Laughed',
100
+ },
101
+ 2: {
102
+ value: 'Spoon',
103
+ correct: 'Spoon',
104
+ },
105
+ }}
106
+ />,
107
+ );
108
+ expect(container.firstChild).toBeInTheDocument();
109
+ });
110
+ });
111
+ });
@@ -0,0 +1,38 @@
1
+ import componentize from '../componentize';
2
+ import { deserialize } from '../serialization';
3
+
4
+ describe('index', () => {
5
+ describe('componentize', () => {
6
+ it('should return an array with the appropriate markup', () => {
7
+ const dropDownMarkup = componentize('{{0}} foo {{1}}', 'dropdown');
8
+
9
+ expect(dropDownMarkup).toEqual({
10
+ markup:
11
+ '<span data-component="dropdown" data-id="0"></span> foo <span data-component="dropdown" data-id="1"></span>',
12
+ });
13
+ });
14
+ });
15
+
16
+ describe('serialization', () => {
17
+ it('should have default node a span', () => {
18
+ expect(deserialize('something')).toEqual(
19
+ expect.objectContaining({
20
+ object: 'value',
21
+ document: {
22
+ object: 'document',
23
+ data: {},
24
+ nodes: [
25
+ {
26
+ object: 'block',
27
+ data: {},
28
+ isVoid: false,
29
+ type: 'span',
30
+ nodes: [{ object: 'text', leaves: [{ text: 'something' }] }],
31
+ },
32
+ ],
33
+ },
34
+ }),
35
+ );
36
+ });
37
+ });
38
+ });