restrictededitingediting.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  6. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  7. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  8. import Typing from '@ckeditor/ckeditor5-typing/src/typing';
  9. import Command from '@ckeditor/ckeditor5-core/src/command';
  10. import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  11. import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  12. import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';
  13. import RestrictedEditingEditing from './../src/restrictededitingediting';
  14. describe( 'RestrictedEditingEditing', () => {
  15. let editor;
  16. testUtils.createSinonSandbox();
  17. describe( 'plugin', () => {
  18. beforeEach( async () => {
  19. editor = await VirtualTestEditor.create( { plugins: [ RestrictedEditingEditing ] } );
  20. } );
  21. afterEach( async () => {
  22. await editor.destroy();
  23. } );
  24. it( 'should be named', () => {
  25. expect( RestrictedEditingEditing.pluginName ).to.equal( 'RestrictedEditingEditing' );
  26. } );
  27. it( 'should be loaded', () => {
  28. expect( editor.plugins.get( RestrictedEditingEditing ) ).to.be.instanceOf( RestrictedEditingEditing );
  29. } );
  30. } );
  31. describe( 'conversion', () => {
  32. let model;
  33. beforeEach( async () => {
  34. editor = await VirtualTestEditor.create( { plugins: [ Paragraph, RestrictedEditingEditing ] } );
  35. model = editor.model;
  36. } );
  37. afterEach( () => {
  38. return editor.destroy();
  39. } );
  40. describe( 'upcast', () => {
  41. it( 'should convert <span class="ck-restricted-editing-exception"> to marker', () => {
  42. editor.setData( '<p>foo <span class="ck-restricted-editing-exception">bar</span> baz</p>' );
  43. expect( model.markers.has( 'restricted-editing-exception:1' ) ).to.be.true;
  44. const marker = model.markers.get( 'restricted-editing-exception:1' );
  45. expect( marker.getStart().path ).to.deep.equal( [ 0, 4 ] );
  46. expect( marker.getEnd().path ).to.deep.equal( [ 0, 7 ] );
  47. } );
  48. it( 'should convert multiple <span class="ck-restricted-editing-exception">', () => {
  49. editor.setData(
  50. '<p>foo <span class="ck-restricted-editing-exception">bar</span> baz</p>' +
  51. '<p>ABCDEF<span class="ck-restricted-editing-exception">GHIJK</span>LMNOPQRST</p>'
  52. );
  53. expect( model.markers.has( 'restricted-editing-exception:1' ) ).to.be.true;
  54. expect( model.markers.has( 'restricted-editing-exception:2' ) ).to.be.true;
  55. // Data for the first marker is the same as in previous tests so no need to test it again.
  56. const secondMarker = model.markers.get( 'restricted-editing-exception:2' );
  57. expect( secondMarker.getStart().path ).to.deep.equal( [ 1, 6 ] );
  58. expect( secondMarker.getEnd().path ).to.deep.equal( [ 1, 11 ] );
  59. } );
  60. it( 'should not convert other <span> elements', () => {
  61. editor.setData( '<p>foo <span class="foo bar">bar</span> baz</p>' );
  62. expect( model.markers.has( 'restricted-editing-exception:1' ) ).to.be.false;
  63. } );
  64. } );
  65. describe( 'downcast', () => {
  66. it( 'should convert model marker to <span>', () => {
  67. setModelData( model, '<paragraph>foo bar baz</paragraph>' );
  68. const paragraph = model.document.getRoot().getChild( 0 );
  69. model.change( writer => {
  70. writer.addMarker( 'restricted-editing-exception:1', {
  71. range: writer.createRange( writer.createPositionAt( paragraph, 4 ), writer.createPositionAt( paragraph, 7 ) ),
  72. usingOperation: true,
  73. affectsData: true
  74. } );
  75. } );
  76. const expectedView = '<p>foo <span class="ck-restricted-editing-exception">bar</span> baz</p>';
  77. expect( editor.getData() ).to.equal( expectedView );
  78. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( expectedView );
  79. } );
  80. it( 'converted <span> should be the outermost attribute element', () => {
  81. editor.conversion.for( 'downcast' ).attributeToElement( { model: 'bold', view: 'b' } );
  82. setModelData( model, '<paragraph><$text bold="true">foo bar baz</$text></paragraph>' );
  83. const paragraph = model.document.getRoot().getChild( 0 );
  84. model.change( writer => {
  85. writer.addMarker( 'restricted-editing-exception:1', {
  86. range: writer.createRange( writer.createPositionAt( paragraph, 0 ), writer.createPositionAt( paragraph, 'end' ) ),
  87. usingOperation: true,
  88. affectsData: true
  89. } );
  90. } );
  91. const expectedView = '<p><span class="ck-restricted-editing-exception"><b>foo bar baz</b></span></p>';
  92. expect( editor.getData() ).to.equal( expectedView );
  93. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( expectedView );
  94. } );
  95. } );
  96. } );
  97. describe( 'editing behavior', () => {
  98. let model;
  99. beforeEach( async () => {
  100. editor = await VirtualTestEditor.create( { plugins: [ Paragraph, Typing, RestrictedEditingEditing ] } );
  101. model = editor.model;
  102. } );
  103. afterEach( async () => {
  104. await editor.destroy();
  105. } );
  106. it( 'should keep markers in the view when editable region is edited', () => {
  107. setModelData( model,
  108. '<paragraph>foo bar baz</paragraph>' +
  109. '<paragraph>xxx y[]yy zzz</paragraph>'
  110. );
  111. const firstParagraph = model.document.getRoot().getChild( 0 );
  112. const secondParagraph = model.document.getRoot().getChild( 1 );
  113. model.change( writer => {
  114. writer.addMarker( 'restricted-editing-exception:1', {
  115. range: writer.createRange( writer.createPositionAt( firstParagraph, 4 ), writer.createPositionAt( firstParagraph, 7 ) ),
  116. usingOperation: true,
  117. affectsData: true
  118. } );
  119. writer.addMarker( 'restricted-editing-exception:2', {
  120. range: writer.createRange(
  121. writer.createPositionAt( secondParagraph, 4 ),
  122. writer.createPositionAt( secondParagraph, 7 )
  123. ),
  124. usingOperation: true,
  125. affectsData: true
  126. } );
  127. } );
  128. model.change( writer => {
  129. model.insertContent( writer.createText( 'R', model.document.selection.getAttributes() ) );
  130. } );
  131. const expectedView = '<p>foo <span class="ck-restricted-editing-exception">bar</span> baz</p>' +
  132. '<p>xxx <span class="ck-restricted-editing-exception">yRyy</span> zzz</p>';
  133. expect( editor.getData() ).to.equal( expectedView );
  134. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( expectedView );
  135. } );
  136. it( 'should block user typing outside exception markers', () => {
  137. setModelData( model, '<paragraph>foo []bar baz</paragraph>' );
  138. editor.execute( 'input', { text: 'X' } );
  139. assertEqualMarkup( getModelData( model ), '<paragraph>foo []bar baz</paragraph>' );
  140. } );
  141. it( 'should not block user typing inside exception marker', () => {
  142. setModelData( model, '<paragraph>[]foo bar baz</paragraph>' );
  143. const firstParagraph = model.document.getRoot().getChild( 0 );
  144. model.change( writer => {
  145. writer.addMarker( 'restricted-editing-exception:1', {
  146. range: writer.createRange( writer.createPositionAt( firstParagraph, 4 ), writer.createPositionAt( firstParagraph, 7 ) ),
  147. usingOperation: true,
  148. affectsData: true
  149. } );
  150. } );
  151. model.change( writer => {
  152. writer.setSelection( firstParagraph, 5 );
  153. } );
  154. editor.execute( 'input', { text: 'X' } );
  155. assertEqualMarkup( getModelData( model ), '<paragraph>foo bX[]ar baz</paragraph>' );
  156. } );
  157. } );
  158. describe( 'commands integration', () => {
  159. let model, firstParagraph;
  160. beforeEach( async () => {
  161. editor = await VirtualTestEditor.create( { plugins: [ Paragraph, Typing, RestrictedEditingEditing ] } );
  162. model = editor.model;
  163. setModelData( model, '<paragraph>[]foo bar baz</paragraph>' );
  164. firstParagraph = model.document.getRoot().getChild( 0 );
  165. model.change( writer => {
  166. writer.addMarker( 'restricted-editing-exception:1', {
  167. range: writer.createRange(
  168. writer.createPositionAt( firstParagraph, 4 ),
  169. writer.createPositionAt( firstParagraph, 7 ) ),
  170. usingOperation: true,
  171. affectsData: true
  172. } );
  173. } );
  174. } );
  175. afterEach( async () => {
  176. await editor.destroy();
  177. } );
  178. describe( 'undo', () => {
  179. beforeEach( () => {
  180. editor.commands.add( 'undo', buildFakeCommand( editor ) );
  181. } );
  182. it( 'should be enabled outside exception marker', () => {
  183. model.change( writer => {
  184. writer.setSelection( firstParagraph, 1 );
  185. } );
  186. expect( editor.commands.get( 'undo' ).isEnabled ).to.be.true;
  187. } );
  188. it( 'should be enabled inside exception marker', () => {
  189. model.change( writer => {
  190. writer.setSelection( firstParagraph, 5 );
  191. } );
  192. expect( editor.commands.get( 'undo' ).isEnabled ).to.be.true;
  193. } );
  194. } );
  195. describe( 'redo', () => {
  196. beforeEach( () => {
  197. editor.commands.add( 'redo', buildFakeCommand( editor ) );
  198. } );
  199. it( 'should be enabled outside exception marker', () => {
  200. model.change( writer => {
  201. writer.setSelection( firstParagraph, 1 );
  202. } );
  203. expect( editor.commands.get( 'redo' ).isEnabled ).to.be.true;
  204. } );
  205. it( 'should be enabled inside exception marker', () => {
  206. model.change( writer => {
  207. writer.setSelection( firstParagraph, 5 );
  208. } );
  209. expect( editor.commands.get( 'redo' ).isEnabled ).to.be.true;
  210. } );
  211. } );
  212. const commandsEnabledOnWholeRange = [
  213. 'input', 'bold', 'link', 'italic'
  214. ];
  215. for ( const commandName of commandsEnabledOnWholeRange ) {
  216. describe( commandName, () => {
  217. beforeEach( () => {
  218. editor.commands.add( commandName, buildFakeCommand( editor ) );
  219. model.change( writer => {
  220. writer.setSelection( firstParagraph, 'end' );
  221. } );
  222. } );
  223. it( 'should be disabled when caret is outside exception marker', () => {
  224. model.change( writer => {
  225. writer.setSelection( firstParagraph, 1 );
  226. } );
  227. expect( editor.commands.get( commandName ).isEnabled ).to.be.false;
  228. } );
  229. it( 'should be enabled when caret is inside exception marker (not touching boundaries)', () => {
  230. model.change( writer => {
  231. writer.setSelection( firstParagraph, 5 );
  232. } );
  233. expect( editor.commands.get( commandName ).isEnabled ).to.be.true;
  234. } );
  235. it( 'should be enabled when caret is inside exception marker (start boundary)', () => {
  236. model.change( writer => {
  237. writer.setSelection( firstParagraph, 4 );
  238. } );
  239. expect( editor.commands.get( commandName ).isEnabled ).to.be.true;
  240. } );
  241. it( 'should be enabled when caret is inside exception marker (end boundary)', () => {
  242. model.change( writer => {
  243. writer.setSelection( firstParagraph, 7 );
  244. } );
  245. expect( editor.commands.get( commandName ).isEnabled ).to.be.true;
  246. } );
  247. it( 'should be disabled for non-collapsed selection that expands over exception marker', () => {
  248. model.change( writer => {
  249. writer.setSelection( writer.createRange(
  250. writer.createPositionAt( firstParagraph, 0 ),
  251. writer.createPositionAt( firstParagraph, 5 )
  252. ) );
  253. } );
  254. expect( editor.commands.get( commandName ).isEnabled ).to.be.false;
  255. } );
  256. it( 'should be enabled for non-collapsed selection that is fully contained inside exception marker', () => {
  257. model.change( writer => {
  258. writer.setSelection( writer.createRange(
  259. writer.createPositionAt( firstParagraph, 5 ),
  260. writer.createPositionAt( firstParagraph, 6 )
  261. ) );
  262. } );
  263. expect( editor.commands.get( commandName ).isEnabled ).to.be.true;
  264. } );
  265. it( 'should be enabled for non-collapsed selection inside exception marker (start position on marker boundary)', () => {
  266. model.change( writer => {
  267. writer.setSelection( writer.createRange(
  268. writer.createPositionAt( firstParagraph, 4 ),
  269. writer.createPositionAt( firstParagraph, 6 )
  270. ) );
  271. } );
  272. expect( editor.commands.get( commandName ).isEnabled ).to.be.true;
  273. } );
  274. it( 'should be enabled for non-collapsed selection inside exception marker (end position on marker boundary)', () => {
  275. model.change( writer => {
  276. writer.setSelection( writer.createRange(
  277. writer.createPositionAt( firstParagraph, 5 ),
  278. writer.createPositionAt( firstParagraph, 7 )
  279. ) );
  280. } );
  281. expect( editor.commands.get( commandName ).isEnabled ).to.be.true;
  282. } );
  283. it( 'should be enabled for non-collapsed selection is equal to exception marker', () => {
  284. model.change( writer => {
  285. writer.setSelection( writer.createRange(
  286. writer.createPositionAt( firstParagraph, 4 ),
  287. writer.createPositionAt( firstParagraph, 7 )
  288. ) );
  289. } );
  290. expect( editor.commands.get( commandName ).isEnabled ).to.be.true;
  291. } );
  292. } );
  293. }
  294. describe( 'delete', () => {
  295. beforeEach( () => {
  296. editor.commands.add( 'delete', buildFakeCommand( editor ) );
  297. model.change( writer => {
  298. writer.setSelection( firstParagraph, 'end' );
  299. } );
  300. } );
  301. it( 'should be disabled when caret is outside exception marker', () => {
  302. model.change( writer => {
  303. writer.setSelection( firstParagraph, 1 );
  304. } );
  305. expect( editor.commands.get( 'delete' ).isEnabled ).to.be.false;
  306. } );
  307. it( 'should be enabled when caret is inside exception marker (not touching boundaries)', () => {
  308. model.change( writer => {
  309. writer.setSelection( firstParagraph, 5 );
  310. } );
  311. expect( editor.commands.get( 'delete' ).isEnabled ).to.be.true;
  312. } );
  313. it( 'should be disabled when caret is inside exception marker (start boundary)', () => {
  314. model.change( writer => {
  315. writer.setSelection( firstParagraph, 4 );
  316. } );
  317. expect( editor.commands.get( 'delete' ).isEnabled ).to.be.false;
  318. } );
  319. it( 'should be enabled when caret is inside exception marker (end boundary)', () => {
  320. model.change( writer => {
  321. writer.setSelection( firstParagraph, 7 );
  322. } );
  323. expect( editor.commands.get( 'delete' ).isEnabled ).to.be.true;
  324. } );
  325. it( 'should be disabled for non-collapsed selection that expands over exception marker', () => {
  326. model.change( writer => {
  327. writer.setSelection( writer.createRange(
  328. writer.createPositionAt( firstParagraph, 0 ),
  329. writer.createPositionAt( firstParagraph, 5 )
  330. ) );
  331. } );
  332. expect( editor.commands.get( 'delete' ).isEnabled ).to.be.false;
  333. } );
  334. it( 'should be enabled for non-collapsed selection that is fully contained inside exception marker', () => {
  335. model.change( writer => {
  336. writer.setSelection( writer.createRange(
  337. writer.createPositionAt( firstParagraph, 5 ),
  338. writer.createPositionAt( firstParagraph, 6 )
  339. ) );
  340. } );
  341. expect( editor.commands.get( 'delete' ).isEnabled ).to.be.true;
  342. } );
  343. it( 'should be enabled for non-collapsed selection inside exception marker (start position on marker boundary)', () => {
  344. model.change( writer => {
  345. writer.setSelection( writer.createRange(
  346. writer.createPositionAt( firstParagraph, 4 ),
  347. writer.createPositionAt( firstParagraph, 6 )
  348. ) );
  349. } );
  350. expect( editor.commands.get( 'delete' ).isEnabled ).to.be.true;
  351. } );
  352. it( 'should be enabled for non-collapsed selection inside exception marker (end position on marker boundary)', () => {
  353. model.change( writer => {
  354. writer.setSelection( writer.createRange(
  355. writer.createPositionAt( firstParagraph, 5 ),
  356. writer.createPositionAt( firstParagraph, 7 )
  357. ) );
  358. } );
  359. expect( editor.commands.get( 'delete' ).isEnabled ).to.be.true;
  360. } );
  361. it( 'should be enabled for non-collapsed selection is equal to exception marker', () => {
  362. model.change( writer => {
  363. writer.setSelection( writer.createRange(
  364. writer.createPositionAt( firstParagraph, 4 ),
  365. writer.createPositionAt( firstParagraph, 7 )
  366. ) );
  367. } );
  368. expect( editor.commands.get( 'delete' ).isEnabled ).to.be.true;
  369. } );
  370. } );
  371. describe( 'forwardDelete', () => {
  372. beforeEach( () => {
  373. editor.commands.add( 'forwardDelete', buildFakeCommand( editor ) );
  374. model.change( writer => {
  375. writer.setSelection( firstParagraph, 'end' );
  376. } );
  377. } );
  378. it( 'should be disabled when caret is outside exception marker', () => {
  379. model.change( writer => {
  380. writer.setSelection( firstParagraph, 1 );
  381. } );
  382. expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.false;
  383. } );
  384. it( 'should be enabled when caret is inside exception marker (not touching boundaries)', () => {
  385. model.change( writer => {
  386. writer.setSelection( firstParagraph, 5 );
  387. } );
  388. expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.true;
  389. } );
  390. it( 'should be enabled when caret is inside exception marker (start boundary)', () => {
  391. model.change( writer => {
  392. writer.setSelection( firstParagraph, 4 );
  393. } );
  394. expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.true;
  395. } );
  396. it( 'should be disabled when caret is inside exception marker (end boundary)', () => {
  397. model.change( writer => {
  398. writer.setSelection( firstParagraph, 7 );
  399. } );
  400. expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.false;
  401. } );
  402. it( 'should be disabled for non-collapsed selection that expands over exception marker', () => {
  403. model.change( writer => {
  404. writer.setSelection( writer.createRange(
  405. writer.createPositionAt( firstParagraph, 0 ),
  406. writer.createPositionAt( firstParagraph, 5 )
  407. ) );
  408. } );
  409. expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.false;
  410. } );
  411. it( 'should be enabled for non-collapsed selection that is fully contained inside exception marker', () => {
  412. model.change( writer => {
  413. writer.setSelection( writer.createRange(
  414. writer.createPositionAt( firstParagraph, 5 ),
  415. writer.createPositionAt( firstParagraph, 6 )
  416. ) );
  417. } );
  418. expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.true;
  419. } );
  420. it( 'should be enabled for non-collapsed selection inside exception marker (start position on marker boundary)', () => {
  421. model.change( writer => {
  422. writer.setSelection( writer.createRange(
  423. writer.createPositionAt( firstParagraph, 4 ),
  424. writer.createPositionAt( firstParagraph, 6 )
  425. ) );
  426. } );
  427. expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.true;
  428. } );
  429. it( 'should be enabled for non-collapsed selection inside exception marker (end position on marker boundary)', () => {
  430. model.change( writer => {
  431. writer.setSelection( writer.createRange(
  432. writer.createPositionAt( firstParagraph, 5 ),
  433. writer.createPositionAt( firstParagraph, 7 )
  434. ) );
  435. } );
  436. expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.true;
  437. } );
  438. it( 'should be enabled for non-collapsed selection is equal to exception marker', () => {
  439. model.change( writer => {
  440. writer.setSelection( writer.createRange(
  441. writer.createPositionAt( firstParagraph, 4 ),
  442. writer.createPositionAt( firstParagraph, 7 )
  443. ) );
  444. } );
  445. expect( editor.commands.get( 'forwardDelete' ).isEnabled ).to.be.true;
  446. } );
  447. } );
  448. describe( 'other', () => {
  449. beforeEach( () => {
  450. editor.commands.add( 'other', buildFakeCommand( editor ) );
  451. model.change( writer => {
  452. writer.setSelection( firstParagraph, 'end' );
  453. } );
  454. } );
  455. it( 'should be disabled outside exception marker', () => {
  456. model.change( writer => {
  457. writer.setSelection( firstParagraph, 1 );
  458. } );
  459. expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;
  460. } );
  461. it( 'should be disabled inside exception marker', () => {
  462. model.change( writer => {
  463. writer.setSelection( firstParagraph, 1 );
  464. } );
  465. model.change( writer => {
  466. writer.setSelection( firstParagraph, 5 );
  467. } );
  468. expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;
  469. } );
  470. it( 'should be disabled when caret is inside exception marker (not touching boundaries)', () => {
  471. model.change( writer => {
  472. writer.setSelection( firstParagraph, 5 );
  473. } );
  474. expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;
  475. } );
  476. it( 'should be disabled when caret is inside exception marker (start boundary)', () => {
  477. model.change( writer => {
  478. writer.setSelection( firstParagraph, 4 );
  479. } );
  480. expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;
  481. } );
  482. it( 'should be disabled when caret is inside exception marker (end boundary)', () => {
  483. model.change( writer => {
  484. writer.setSelection( firstParagraph, 7 );
  485. } );
  486. expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;
  487. } );
  488. it( 'should be disabled for non-collapsed selection that expands over exception marker', () => {
  489. model.change( writer => {
  490. writer.setSelection( writer.createRange(
  491. writer.createPositionAt( firstParagraph, 0 ),
  492. writer.createPositionAt( firstParagraph, 5 )
  493. ) );
  494. } );
  495. expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;
  496. } );
  497. it( 'should be disabled for non-collapsed selection that is fully contained inside exception marker', () => {
  498. model.change( writer => {
  499. writer.setSelection( writer.createRange(
  500. writer.createPositionAt( firstParagraph, 5 ),
  501. writer.createPositionAt( firstParagraph, 6 )
  502. ) );
  503. } );
  504. expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;
  505. } );
  506. it( 'should be disabled for non-collapsed selection inside exception marker (start position on marker boundary)', () => {
  507. model.change( writer => {
  508. writer.setSelection( writer.createRange(
  509. writer.createPositionAt( firstParagraph, 4 ),
  510. writer.createPositionAt( firstParagraph, 6 )
  511. ) );
  512. } );
  513. expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;
  514. } );
  515. it( 'should be disabled for non-collapsed selection inside exception marker (end position on marker boundary)', () => {
  516. model.change( writer => {
  517. writer.setSelection( writer.createRange(
  518. writer.createPositionAt( firstParagraph, 5 ),
  519. writer.createPositionAt( firstParagraph, 7 )
  520. ) );
  521. } );
  522. expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;
  523. } );
  524. it( 'should be disabled for non-collapsed selection is equal to exception marker', () => {
  525. model.change( writer => {
  526. writer.setSelection( writer.createRange(
  527. writer.createPositionAt( firstParagraph, 4 ),
  528. writer.createPositionAt( firstParagraph, 7 )
  529. ) );
  530. } );
  531. expect( editor.commands.get( 'other' ).isEnabled ).to.be.false;
  532. } );
  533. } );
  534. } );
  535. class FakeCommand extends Command {
  536. refresh() {
  537. this.isEnabled = true;
  538. }
  539. }
  540. function buildFakeCommand( editor ) {
  541. return new FakeCommand( editor );
  542. }
  543. } );