Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement DocumentModel initialization #39

Merged
merged 11 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"stryker-cli": "^1.0.2",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
"typescript": "^5.2.2"
}
}
103 changes: 103 additions & 0 deletions src/entities/BlockNode/BlockNode.integration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { BlockNode, createDataKey } from './index';
import { BlockChildType } from './types';
import { NODE_TYPE_HIDDEN_PROP } from './consts';

describe('BlockNode integration tests', () => {
it('should create ValueNode by primitive value', () => {
const value = 'value';
const newValue = 'updated value';
const node = new BlockNode({
name: 'blockNode',
data: {
value,
},
});

node.updateValue(createDataKey('value'), newValue);

expect(node.serialized.data)
.toEqual({
value: newValue,
});
});

it('should create ValueNode by object marked as value and update its value', () => {
const value = {
[NODE_TYPE_HIDDEN_PROP]: BlockChildType.Value,
value: 'value',
};
const newValue = {
value: 'updated value',
};
const node = new BlockNode({
name: 'blockNode',
data: {
value,
},
});

node.updateValue(createDataKey('value'), newValue);

expect(node.serialized.data)
.toEqual({
value: {
...newValue,
[NODE_TYPE_HIDDEN_PROP]: BlockChildType.Value,
},
});
});

it('should create TextNode by passed text node data and insert new text into it', () => {
const text = {
value: 'Editor.js is a block-styled editor',
[NODE_TYPE_HIDDEN_PROP]: BlockChildType.Text,
};
const addedText = ' for rich media web content';
const node = new BlockNode({
name: 'blockNode',
data: {
text,
},
});

node.insertText(createDataKey('text'), addedText);

expect(node.serialized.data).toEqual({
text: {
value: `${text.value}${addedText}`,
fragments: [],
[NODE_TYPE_HIDDEN_PROP]: BlockChildType.Text,
},
});
});

it('should create relevant nodes from the array and update their values', () => {
const value = 'value';
const updatedValue = 'updated value';
const text = {
value: 'Editor.js is a block-styled editor',
[NODE_TYPE_HIDDEN_PROP]: BlockChildType.Text,
};
const addedText = ' for rich media web content';
const node = new BlockNode({
name: 'blockNode',
data: {
array: [value, text],
},
});

node.updateValue(createDataKey('array.0'), updatedValue);
node.insertText(createDataKey('array.1'), addedText);

expect(node.serialized.data).toEqual({
array: [
updatedValue,
{
value: `${text.value}${addedText}`,
fragments: [],
[NODE_TYPE_HIDDEN_PROP]: BlockChildType.Text,
},
],
});
});
});
Loading
Loading