Skip to content

Commit

Permalink
feat(htmleditor): Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marker dao ® committed Oct 15, 2024
1 parent bb4879d commit fee8d1f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,57 @@ testModule('API', moduleConfig, () => {
assert.strictEqual(secondConverter.toHtml.callCount, 1);
assert.strictEqual(secondConverter.fromHtml.callCount, 1);
});

test('The converter methods get the correct parameters', function(assert) {
const converter = {
toHtml: (value) => {
assert.strictEqual(value, 'new value');

return value;
},
fromHtml: (value) => {
assert.strictEqual(value, '<p>new value</p>');

return value;
},
};

this.options = { converter };

this.createEditor();

this.instance.option('value', 'new value');
});

test('toHtml changed value correctly', function(assert) {
const converter = {
toHtml: () => {
return '<p>NEW VALUE</p>';
},
};
this.options = { converter };

this.createEditor();

this.instance.option('value', 'new value');

assert.strictEqual(this.instance.option('value'), '<p>NEW VALUE</p>');
});

test('fromHtml changed value correctly', function(assert) {
const converter = {
fromHtml: () => {
return '**NEW VALUE**';
},
};
this.options = { converter };

this.createEditor();

this.instance.option('value', 'new value');

assert.strictEqual(this.instance.option('value'), '**NEW VALUE**');
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,4 +649,20 @@ export default function() {
});
});
});

testModule('converter option', () => {
test('value from toHtml must match the markup value', function(assert) {
const instance = $('#htmlEditor').dxHtmlEditor({
converter: {
toHtml: () => '<h1>Hi!</h1><p>Test</p>',
},
}).dxHtmlEditor('instance');

instance.option('value', 'new value');

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

assert.strictEqual(markup, '<h1>Hi!</h1><p>Test</p>');
});
});
}

0 comments on commit fee8d1f

Please sign in to comment.