8
0

buildviewconverter.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import buildViewConverter from '../../src/conversion/buildviewconverter';
  6. import ModelSchema from '../../src/model/schema';
  7. import ModelDocument from '../../src/model/document';
  8. import ModelElement from '../../src/model/element';
  9. import ModelTextProxy from '../../src/model/textproxy';
  10. import ModelRange from '../../src/model/range';
  11. import ModelWalker from '../../src/model/treewalker';
  12. import ViewDocumentFragment from '../../src/view/documentfragment';
  13. import ViewContainerElement from '../../src/view/containerelement';
  14. import ViewAttributeElement from '../../src/view/attributeelement';
  15. import ViewText from '../../src/view/text';
  16. import ViewMatcher from '../../src/view/matcher';
  17. import ViewConversionDispatcher from '../../src/conversion/viewconversiondispatcher';
  18. import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
  19. import { convertToModelFragment, convertText } from '../../src/conversion/view-to-model-converters';
  20. import { stringify } from '../../src/dev-utils/model';
  21. function modelAttributesToString( item ) {
  22. let result = '';
  23. for ( let attr of item.getAttributes() ) {
  24. result += ' ' + attr[ 0 ] + '="' + attr[ 1 ] + '"';
  25. }
  26. return result;
  27. }
  28. function modelToString( item ) {
  29. let result = '';
  30. if ( item instanceof ModelTextProxy ) {
  31. let attributes = modelAttributesToString( item );
  32. result = attributes ? '<$text' + attributes + '>' + item.data + '</$text>' : item.data;
  33. } else {
  34. let walker = new ModelWalker( { boundaries: ModelRange.createIn( item ), shallow: true } );
  35. for ( let value of walker ) {
  36. result += modelToString( value.item );
  37. }
  38. if ( item instanceof ModelElement ) {
  39. let attributes = modelAttributesToString( item );
  40. result = '<' + item.name + attributes + '>' + result + '</' + item.name + '>';
  41. }
  42. }
  43. return result;
  44. }
  45. const textAttributes = [ undefined, 'linkHref', 'linkTitle', 'bold', 'italic', 'style' ];
  46. const pAttributes = [ undefined, 'class', 'important', 'theme', 'decorated', 'size' ];
  47. describe( 'View converter builder', () => {
  48. let dispatcher, modelDoc, modelRoot, schema, objWithContext;
  49. beforeEach( () => {
  50. // `additionalData` parameter for `.convert` calls.
  51. objWithContext = { context: [ '$root' ] };
  52. schema = new ModelSchema();
  53. schema.registerItem( 'paragraph', '$block' );
  54. schema.registerItem( 'div', '$block' );
  55. schema.registerItem( 'customP', 'paragraph' );
  56. schema.registerItem( 'image', '$inline' );
  57. schema.registerItem( 'span', '$inline' );
  58. schema.registerItem( 'MEGATRON', '$inline' ); // Yes, folks, we are building MEGATRON.
  59. schema.registerItem( 'abcd', '$inline' );
  60. schema.allow( { name: '$inline', attributes: textAttributes, inside: '$root' } );
  61. schema.allow( { name: 'image', attributes: [ 'src' ], inside: '$root' } );
  62. schema.allow( { name: 'image', attributes: [ 'src' ], inside: '$block' } );
  63. schema.allow( { name: '$text', inside: '$inline' } );
  64. schema.allow( { name: '$text', attributes: textAttributes, inside: '$block' } );
  65. schema.allow( { name: '$text', attributes: textAttributes, inside: '$root' } );
  66. schema.allow( { name: 'paragraph', attributes: pAttributes, inside: '$root' } );
  67. schema.allow( { name: 'span', attributes: [ 'transformer' ], inside: '$root' } );
  68. schema.allow( { name: 'div', attributes: [ 'class' ], inside: '$root' } );
  69. dispatcher = new ViewConversionDispatcher( { schema } );
  70. dispatcher.on( 'text', convertText() );
  71. modelDoc = new ModelDocument();
  72. modelRoot = modelDoc.createRoot();
  73. } );
  74. it( 'should convert from view element to model element', () => {
  75. buildViewConverter().for( dispatcher ).fromElement( 'p' ).toElement( 'paragraph' );
  76. const conversionResult = dispatcher.convert( new ViewContainerElement( 'p', null, new ViewText( 'foo' ) ), objWithContext );
  77. modelRoot.appendChildren( conversionResult );
  78. expect( modelToString( conversionResult ) ).to.equal( '<paragraph>foo</paragraph>' );
  79. } );
  80. it( 'should convert from view element to model element using creator function', () => {
  81. buildViewConverter().for( dispatcher )
  82. .fromElement( 'img' )
  83. .toElement( ( viewElement ) => new ModelElement( 'image', { src: viewElement.getAttribute( 'src' ) } ) );
  84. const conversionResult = dispatcher.convert( new ViewContainerElement( 'img', { src: 'foo.jpg' } ), objWithContext );
  85. modelRoot.appendChildren( conversionResult );
  86. expect( modelToString( conversionResult ) ).to.equal( '<image src="foo.jpg"></image>' );
  87. } );
  88. it( 'should convert from view element to model attribute', () => {
  89. buildViewConverter().for( dispatcher ).fromElement( 'strong' ).toAttribute( 'bold', true );
  90. const conversionResult = dispatcher.convert(
  91. new ViewAttributeElement( 'strong', null, new ViewText( 'foo' ) ), objWithContext
  92. );
  93. modelRoot.appendChildren( conversionResult );
  94. // Have to check root because result is a ModelText.
  95. expect( modelToString( modelRoot ) ).to.equal( '<$root><$text bold="true">foo</$text></$root>' );
  96. } );
  97. it( 'should convert from view element to model attributes using creator function', () => {
  98. buildViewConverter().for( dispatcher )
  99. .fromElement( 'a' )
  100. .toAttribute( ( viewElement ) => ( { key: 'linkHref', value: viewElement.getAttribute( 'href' ) } ) );
  101. const conversionResult = dispatcher.convert(
  102. new ViewAttributeElement( 'a', { href: 'foo.html' }, new ViewText( 'foo' ) ), objWithContext
  103. );
  104. modelRoot.appendChildren( conversionResult );
  105. // Have to check root because result is a ModelText.
  106. expect( modelToString( modelRoot ) ).to.equal( '<$root><$text linkHref="foo.html">foo</$text></$root>' );
  107. } );
  108. it( 'should convert from view attribute to model attribute', () => {
  109. buildViewConverter().for( dispatcher ).fromElement( 'p' ).toElement( 'paragraph' );
  110. buildViewConverter().for( dispatcher )
  111. .fromAttribute( 'class' )
  112. .toAttribute( ( viewElement ) => ( { key: 'class', value: viewElement.getAttribute( 'class' ) } ) );
  113. const conversionResult = dispatcher.convert(
  114. new ViewContainerElement( 'p', { class: 'myClass' }, new ViewText( 'foo' ) ), objWithContext
  115. );
  116. modelRoot.appendChildren( conversionResult );
  117. expect( modelToString( conversionResult ) ).to.equal( '<paragraph class="myClass">foo</paragraph>' );
  118. } );
  119. it( 'should convert from view attribute and key to model attribute', () => {
  120. dispatcher.on( 'documentFragment', convertToModelFragment() );
  121. buildViewConverter().for( dispatcher ).fromElement( 'p' ).toElement( 'paragraph' );
  122. buildViewConverter().for( dispatcher ).fromAttribute( 'class', 'important' ).toAttribute( 'important', true );
  123. buildViewConverter().for( dispatcher ).fromAttribute( 'class', 'theme-nice' ).toAttribute( 'theme', 'nice' );
  124. const viewStructure = new ViewDocumentFragment( [
  125. new ViewContainerElement( 'p', { class: 'important' }, new ViewText( 'foo' ) ),
  126. new ViewContainerElement( 'p', { class: 'important theme-nice' }, new ViewText( 'bar' ) )
  127. ] );
  128. const conversionResult = dispatcher.convert( viewStructure, objWithContext );
  129. expect( modelToString( conversionResult ) )
  130. .to.equal( '<paragraph important="true">foo</paragraph><paragraph important="true" theme="nice">bar</paragraph>' );
  131. } );
  132. it( 'should convert from multiple view entities to model attribute', () => {
  133. buildViewConverter().for( dispatcher ).fromElement( 'p' ).toElement( 'paragraph' );
  134. buildViewConverter().for( dispatcher )
  135. .fromElement( 'strong' )
  136. .fromElement( 'b' )
  137. .fromAttribute( 'class', 'bold' )
  138. .fromAttribute( 'style', { 'font-weight': 'bold' } )
  139. .toAttribute( 'bold', true );
  140. const viewElement = new ViewContainerElement( 'p', null, [
  141. new ViewAttributeElement( 'strong', null, new ViewText( 'aaa' ) ),
  142. new ViewAttributeElement( 'b', null, new ViewText( 'bbb' ) ),
  143. new ViewContainerElement( 'span', { class: 'bold' }, new ViewText( 'ccc' ) ),
  144. new ViewContainerElement( 'span', { style: 'font-weight:bold; font-size:20px' }, new ViewText( 'ddd' ) )
  145. ] );
  146. const conversionResult = dispatcher.convert( viewElement, objWithContext );
  147. modelRoot.appendChildren( conversionResult );
  148. expect( modelToString( conversionResult ) ).to.equal( '<paragraph><$text bold="true">aaabbbcccddd</$text></paragraph>' );
  149. } );
  150. it( 'should convert from pattern to marker', () => {
  151. buildViewConverter().for( dispatcher ).fromElement( 'p' ).toElement( 'paragraph' );
  152. buildViewConverter().for( dispatcher ).from( { attribute: { 'data-name': 'search' } } ).toMarker();
  153. const viewElement = new ViewContainerElement( 'p', null, [
  154. new ViewText( 'Fo' ),
  155. new ViewAttributeElement( 'marker', { 'data-name': 'search' } ),
  156. new ViewText( 'o ba' ),
  157. new ViewAttributeElement( 'marker', { 'data-name': 'search' } ),
  158. new ViewText( 'r' )
  159. ] );
  160. const conversionResult = dispatcher.convert( viewElement, objWithContext );
  161. const markerSearch = conversionResult.markers.get( 'search' );
  162. expect( conversionResult.markers.size ).to.equal( 1 );
  163. expect( stringify( conversionResult, markerSearch ) ).to.equal( '<paragraph>Fo[o ba]r</paragraph>' );
  164. } );
  165. it( 'should convert from element to marker using creator function', () => {
  166. buildViewConverter().for( dispatcher ).fromElement( 'p' ).toElement( 'paragraph' );
  167. buildViewConverter().for( dispatcher ).fromElement( 'marker' ).toMarker( ( data ) => {
  168. return new ModelElement( '$marker', { 'data-name': data.getAttribute( 'class' ) } );
  169. } );
  170. const viewElement = new ViewContainerElement( 'p', null, [
  171. new ViewText( 'Fo' ),
  172. new ViewAttributeElement( 'marker', { 'class': 'search' } ),
  173. new ViewText( 'o ba' ),
  174. new ViewAttributeElement( 'marker', { 'class': 'search' } ),
  175. new ViewText( 'r' )
  176. ] );
  177. const conversionResult = dispatcher.convert( viewElement, objWithContext );
  178. const markerSearch = conversionResult.markers.get( 'search' );
  179. expect( conversionResult.markers.size ).to.equal( 1 );
  180. expect( stringify( conversionResult, markerSearch ) ).to.equal( '<paragraph>Fo[o ba]r</paragraph>' );
  181. } );
  182. it( 'should convert from multiple view entities to marker', () => {
  183. buildViewConverter().for( dispatcher ).fromElement( 'p' ).toElement( 'paragraph' );
  184. buildViewConverter().for( dispatcher )
  185. .from( { attribute: { 'foo': 'marker' } } )
  186. .from( { attribute: { 'bar': 'marker' } } )
  187. .from( { attribute: { 'foo': 'marker', 'bar': 'marker' } } )
  188. .toMarker();
  189. const viewElement = new ViewContainerElement( 'p', null, [
  190. new ViewText( 'Fo' ),
  191. new ViewAttributeElement( 'span', { 'foo': 'marker', 'data-name': 'marker1' } ),
  192. new ViewText( 'o b' ),
  193. new ViewAttributeElement( 'span', { 'bar': 'marker', 'data-name': 'marker2' } ),
  194. new ViewText( 'a' ),
  195. new ViewAttributeElement( 'span', { 'foo': 'marker', 'bar': 'marker', 'data-name': 'marker3' } ),
  196. new ViewText( 'r' )
  197. ] );
  198. const conversionResult = dispatcher.convert( viewElement, objWithContext );
  199. const marker1 = conversionResult.markers.get( 'marker1' );
  200. const marker2 = conversionResult.markers.get( 'marker2' );
  201. const marker3 = conversionResult.markers.get( 'marker3' );
  202. expect( conversionResult.markers.size ).to.equal( 3 );
  203. expect( stringify( conversionResult, marker1 ) ).to.equal( '<paragraph>Fo[]o bar</paragraph>' );
  204. expect( stringify( conversionResult, marker2 ) ).to.equal( '<paragraph>Foo b[]ar</paragraph>' );
  205. expect( stringify( conversionResult, marker3 ) ).to.equal( '<paragraph>Foo ba[]r</paragraph>' );
  206. } );
  207. it( 'should do nothing when there is no element matching to marker pattern', () => {
  208. buildViewConverter().for( dispatcher ).from( { class: 'color' } ).toMarker();
  209. const element = new ViewAttributeElement( 'span' );
  210. expect( dispatcher.convert( element, objWithContext ) ).to.null;
  211. } );
  212. it( 'should throw an error when view element in not valid to convert to marker', () => {
  213. buildViewConverter().for( dispatcher ).fromElement( 'marker' ).toMarker();
  214. const element = new ViewAttributeElement( 'marker', { class: 'search' } );
  215. expect( () => {
  216. dispatcher.convert( element, objWithContext );
  217. } ).to.throw( CKEditorError, /^build-view-converter-invalid-marker/ );
  218. } );
  219. it( 'should throw an error when model element returned by creator has not valid name', () => {
  220. buildViewConverter().for( dispatcher ).fromElement( 'marker' ).toMarker( () => {
  221. return new ModelElement( 'element', { 'data-name': 'search' } );
  222. } );
  223. const element = new ViewAttributeElement( 'marker', { 'data-name': 'search' } );
  224. expect( () => {
  225. dispatcher.convert( element, objWithContext );
  226. } ).to.throw( CKEditorError, /^build-view-converter-invalid-marker/ );
  227. } );
  228. it( 'should throw an error when model element returned by creator has not valid data-name attribute', () => {
  229. buildViewConverter().for( dispatcher ).fromElement( 'marker' ).toMarker( () => {
  230. return new ModelElement( '$marker', { 'foo': 'search' } );
  231. } );
  232. const element = new ViewAttributeElement( 'marker', { 'data-name': 'search' } );
  233. expect( () => {
  234. dispatcher.convert( element, objWithContext );
  235. } ).to.throw( CKEditorError, /^build-view-converter-invalid-marker/ );
  236. } );
  237. it( 'should convert from pattern to model element', () => {
  238. buildViewConverter().for( dispatcher ).from(
  239. { name: 'span', class: 'megatron', attribute: { head: 'megatron', body: 'megatron', legs: 'megatron' } }
  240. ).toElement( 'MEGATRON' );
  241. // Adding callbacks later so they are called later. MEGATRON callback is more important.
  242. buildViewConverter().for( dispatcher ).fromElement( 'span' ).toElement( 'span' );
  243. buildViewConverter().for( dispatcher ).fromElement( 'p' ).toElement( 'paragraph' );
  244. let result;
  245. // Not quite megatron.
  246. result = dispatcher.convert(
  247. new ViewContainerElement( 'span', { class: 'megatron' }, new ViewText( 'foo' ) ), objWithContext
  248. );
  249. modelRoot.appendChildren( result );
  250. expect( modelToString( result ) ).to.equal( '<span>foo</span>' );
  251. // Almost a megatron. Missing a head.
  252. result = dispatcher.convert(
  253. new ViewContainerElement( 'span', { class: 'megatron', body: 'megatron', legs: 'megatron' }, new ViewText( 'foo' ) ),
  254. objWithContext
  255. );
  256. modelRoot.appendChildren( result );
  257. expect( modelToString( result ) ).to.equal( '<span>foo</span>' );
  258. // This would be a megatron but is a paragraph.
  259. result = dispatcher.convert(
  260. new ViewContainerElement(
  261. 'p',
  262. { class: 'megatron', body: 'megatron', legs: 'megatron', head: 'megatron' },
  263. new ViewText( 'foo' )
  264. ),
  265. objWithContext
  266. );
  267. modelRoot.appendChildren( result );
  268. expect( modelToString( result ) ).to.equal( '<paragraph>foo</paragraph>' );
  269. // At last we have a megatron!
  270. result = dispatcher.convert(
  271. new ViewContainerElement(
  272. 'span',
  273. { class: 'megatron', body: 'megatron', legs: 'megatron', head: 'megatron' },
  274. new ViewText( 'foo' )
  275. ),
  276. objWithContext
  277. );
  278. modelRoot.appendChildren( result );
  279. expect( modelToString( result ) ).to.equal( '<MEGATRON>foo</MEGATRON>' );
  280. } );
  281. it( 'should convert from pattern to model attribute', () => {
  282. buildViewConverter().for( dispatcher ).fromElement( 'span' ).toElement( 'span' );
  283. // This time without name so default span converter will convert children.
  284. buildViewConverter().for( dispatcher )
  285. .from( { class: 'megatron', attribute: { head: 'megatron', body: 'megatron', legs: 'megatron' } } )
  286. .toAttribute( 'transformer', 'megatron' );
  287. let viewElement = new ViewContainerElement(
  288. 'span',
  289. { class: 'megatron', body: 'megatron', legs: 'megatron', head: 'megatron' },
  290. new ViewText( 'foo' )
  291. );
  292. let conversionResult = dispatcher.convert( viewElement, objWithContext );
  293. modelRoot.appendChildren( conversionResult );
  294. expect( modelToString( conversionResult ) ).to.equal( '<span transformer="megatron">foo</span>' );
  295. } );
  296. it( 'should set different priorities for `toElement` and `toAttribute` conversion', () => {
  297. buildViewConverter().for( dispatcher )
  298. .fromAttribute( 'class' )
  299. .toAttribute( ( viewElement ) => ( { key: 'class', value: viewElement.getAttribute( 'class' ) } ) );
  300. buildViewConverter().for( dispatcher ).fromElement( 'p' ).toElement( 'paragraph' );
  301. let conversionResult = dispatcher.convert(
  302. new ViewContainerElement( 'p', { class: 'myClass' }, new ViewText( 'foo' ) ), objWithContext
  303. );
  304. modelRoot.appendChildren( conversionResult );
  305. // Element converter was fired first even though attribute converter was added first.
  306. expect( modelToString( conversionResult ) ).to.equal( '<paragraph class="myClass">foo</paragraph>' );
  307. } );
  308. it( 'should overwrite default priorities for converters', () => {
  309. buildViewConverter().for( dispatcher ).fromElement( 'p' ).toElement( 'paragraph' );
  310. buildViewConverter().for( dispatcher )
  311. .fromAttribute( 'class' )
  312. .toAttribute( ( viewElement ) => ( { key: 'class', value: viewElement.getAttribute( 'class' ) } ) );
  313. let result;
  314. result = dispatcher.convert(
  315. new ViewContainerElement( 'p', { class: 'myClass' }, new ViewText( 'foo' ) ), objWithContext
  316. );
  317. modelRoot.appendChildren( result );
  318. expect( modelToString( result ) ).to.equal( '<paragraph class="myClass">foo</paragraph>' );
  319. buildViewConverter().for( dispatcher )
  320. .from( { name: 'p', class: 'myClass' } ).withPriority( 'high' )
  321. .toElement( 'customP' );
  322. result = dispatcher.convert(
  323. new ViewContainerElement( 'p', { class: 'myClass' }, new ViewText( 'foo' ) ), objWithContext
  324. );
  325. modelRoot.appendChildren( result );
  326. expect( modelToString( result ) ).to.equal( '<customP>foo</customP>' );
  327. } );
  328. it( 'should overwrite default consumed values', () => {
  329. // Converter (1).
  330. buildViewConverter().for( dispatcher ).fromElement( 'p' ).toElement( 'paragraph' );
  331. // Converter (2).
  332. buildViewConverter().for( dispatcher )
  333. .from( { name: 'p', class: 'decorated' } ).consuming( { class: 'decorated' } )
  334. .toAttribute( 'decorated', true );
  335. // Converter (3).
  336. buildViewConverter().for( dispatcher )
  337. .fromAttribute( 'class', 'small' ).consuming( { class: 'small' } )
  338. .toAttribute( 'size', 'small' );
  339. const viewElement = new ViewContainerElement( 'p', { class: 'decorated small' }, new ViewText( 'foo' ) );
  340. const conversionResult = dispatcher.convert( viewElement, objWithContext );
  341. modelRoot.appendChildren( conversionResult );
  342. // P element and it's children got converted by the converter (1) and the converter (1) got fired
  343. // because P name was not consumed in converter (2). Converter (3) could consume class="small" because
  344. // only class="decorated" was consumed in converter (2).
  345. expect( modelToString( conversionResult ) ).to.equal( '<paragraph decorated="true" size="small">foo</paragraph>' );
  346. } );
  347. it( 'should convert from matcher instance to model', () => {
  348. // Universal class converter, synonymous to .fromAttribute( 'class' ).
  349. buildViewConverter().for( dispatcher )
  350. .from( new ViewMatcher( { class: /.*/ } ) )
  351. .toAttribute( ( viewElement ) => ( { key: 'class', value: viewElement.getAttribute( 'class' ) } ) );
  352. // Universal element converter.
  353. buildViewConverter().for( dispatcher )
  354. .from( new ViewMatcher( { name: /.*/ } ) )
  355. .toElement( ( viewElement ) => new ModelElement( viewElement.name ) );
  356. let viewStructure = new ViewContainerElement( 'div', { class: 'myClass' }, [
  357. new ViewContainerElement( 'abcd', null, new ViewText( 'foo' ) )
  358. ] );
  359. let conversionResult = dispatcher.convert( viewStructure, objWithContext );
  360. modelRoot.appendChildren( conversionResult );
  361. expect( modelToString( conversionResult ) ).to.equal( '<div class="myClass"><abcd>foo</abcd></div>' );
  362. } );
  363. it( 'should filter out structure that is wrong with schema - elements', () => {
  364. buildViewConverter().for( dispatcher ).fromElement( 'div' ).toElement( 'div' );
  365. buildViewConverter().for( dispatcher ).fromElement( 'p' ).toElement( 'paragraph' );
  366. schema.disallow( { name: 'div', inside: '$root' } );
  367. dispatcher.on( 'element', convertToModelFragment(), { priority: 'lowest' } );
  368. let viewElement = new ViewContainerElement( 'div', null,
  369. new ViewContainerElement( 'p', null,
  370. new ViewText( 'foo' )
  371. )
  372. );
  373. let conversionResult = dispatcher.convert( viewElement, objWithContext );
  374. expect( modelToString( conversionResult ) ).to.equal( '<paragraph>foo</paragraph>' );
  375. } );
  376. it( 'should filter out structure that is wrong with schema - attributes', () => {
  377. buildViewConverter().for( dispatcher ).fromElement( 'p' ).toElement( 'paragraph' );
  378. buildViewConverter().for( dispatcher ).fromElement( 'strong' ).toAttribute( 'bold', true );
  379. schema.disallow( { name: '$text', attributes: 'bold', inside: 'paragraph' } );
  380. dispatcher.on( 'element', convertToModelFragment(), { priority: 'lowest' } );
  381. let viewElement = new ViewContainerElement( 'p', null,
  382. new ViewAttributeElement( 'strong', null,
  383. new ViewText( 'foo' )
  384. )
  385. );
  386. let conversionResult = dispatcher.convert( viewElement, objWithContext );
  387. expect( modelToString( conversionResult ) ).to.equal( '<paragraph>foo</paragraph>' );
  388. } );
  389. } );