Skip to content

Commit

Permalink
feat(converter): Add and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marker dao ® committed Nov 8, 2024
1 parent 9ce5626 commit a5b2db1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,25 @@ testModule('API', moduleConfig, () => {
});

testModule('converter option', () => {
['v', ''].forEach(initValue => {
test(`toHtml and fromHtml must be called the correct number of times on init if value is '${initValue}'`, function(assert) {
const converter = {
toHtml: sinon.stub(),
fromHtml: sinon.stub(),
};

this.options = {
converter,
value: initValue,
};

this.createEditor();

assert.strictEqual(this.options.converter.toHtml.callCount, initValue ? 1 : 0);
assert.strictEqual(this.options.converter.fromHtml.callCount, 0);
});
});

test('toHtml and fromHtml should be called once after value option changed', function(assert) {
const converter = {
toHtml: sinon.stub(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,20 @@ export default function() {
});

testModule('converter option', () => {
test('value from toHtml must match the markup value', function(assert) {
test('The content should be converted on init', function(assert) {
const instance = $('#htmlEditor').dxHtmlEditor({
converter: {
toHtml: () => '<h1>Html converted</h1><p>value</p>',
},
value: 'not html value'
}).dxHtmlEditor('instance');

const markup = instance.$element().find(`.${CONTENT_CLASS}`).html();

assert.strictEqual(markup, '<h1>Html converted</h1><p>value</p>');
});

test('value from toHtml must match the markup value if value is changed on runtime', function(assert) {
const instance = $('#htmlEditor').dxHtmlEditor({
converter: {
toHtml: () => '<h1>Hi!</h1><p>Test</p>',
Expand Down

0 comments on commit a5b2db1

Please sign in to comment.