/*! * VisualEditor ContentEditable TextState tests. * * @copyright See AUTHORS.txt */ QUnit.module( 've.ce.TextState' ); /* Tests */ QUnit.test( 'getChangeTransaction', ( assert ) => { const underlineHash = ve.dm.example.underlineHash, boldHash = ve.dm.example.boldHash, annHash = ve.dm.example.annHash; const cases = [ { msg: 'Clear bold', oldRawHtml: '
foo bar baz
', oldInnerHtml: 'foo bar baz', newInnerHtml: 'foo bar baz', operations: [ { type: 'retain', length: 5 }, { type: 'replace', remove: [ [ 'b', [ annHash( 'b' ) ] ], [ 'a', [ annHash( 'b' ) ] ], [ 'r', [ annHash( 'b' ) ] ] ], insert: [ ...'bar' ] }, { type: 'retain', length: 7 } ] }, { msg: 'Extend bold', oldRawHtml: 'foo ba baz
', oldInnerHtml: 'foo ba baz', newInnerHtml: 'foo bar baz', operations: [ { type: 'retain', length: 7 }, { type: 'replace', remove: [], insert: [ [ 'r', [ annHash( 'b' ) ] ] ] }, { type: 'retain', length: 7 } ] }, { msg: 'Set bold', oldRawHtml: 'foo bar baz
', oldInnerHtml: 'foo bar baz', newInnerHtml: 'foo bar baz', operations: [ { type: 'retain', length: 5 }, { type: 'replace', remove: [ ...'bar' ], insert: [ [ 'b', [ boldHash ] ], [ 'a', [ boldHash ] ], [ 'r', [ boldHash ] ] ] }, { type: 'retain', length: 7 } ] }, { msg: 'Insert at start of bold', oldRawHtml: 'wxy', oldInnerHtml: 'wxy', newInnerHtml: 'wxzy', operations: [ { type: 'retain', length: 3 }, { type: 'replace', remove: [], insert: [ [ 'z', [ annHash( 'b' ) ] ] ] }, { type: 'retain', length: 4 } ] }, { msg: 'Insert before start of bold', oldRawHtml: 'wxy', oldInnerHtml: 'wxy', newInnerHtml: 'wxzy', operations: [ { type: 'retain', length: 3 }, { type: 'replace', remove: [], insert: [ 'z' ] }, { type: 'retain', length: 4 } ] }, { msg: 'Insert into insertion annotation', willFail: true, oldRawHtml: 'wxz', oldInnerHtml: 'wxz', newInnerHtml: 'wxyz', operations: [ { type: 'retain', length: 3 }, { type: 'replace', remove: [], insert: [ [ 'y', [ 'anything' ] ] ] }, { type: 'retain', length: 4 } ] }, { msg: 'Set bold underline before underline', oldRawHtml: 'foo barbaz', oldInnerHtml: 'foo barbaz', newInnerHtml: 'foo barbaz', operations: [ { type: 'retain', length: 5 }, { type: 'replace', remove: [ ...'bar' ], insert: [ [ 'b', [ annHash( 'u' ), boldHash ] ], [ 'a', [ annHash( 'u' ), boldHash ] ], [ 'r', [ annHash( 'u' ), boldHash ] ] ] }, { type: 'retain', length: 6 } ] }, { msg: 'Clear bold in italic', oldRawHtml: 'foo bar baz
', oldInnerHtml: 'foo bar baz', newInnerHtml: 'foo bar baz', operations: [ { type: 'retain', length: 5 }, { type: 'replace', remove: [ [ 'b', [ annHash( 'i' ), annHash( 'b' ) ] ], [ 'a', [ annHash( 'i' ), annHash( 'b' ) ] ], [ 'r', [ annHash( 'i' ), annHash( 'b' ) ] ] ], insert: [ [ 'b', [ annHash( 'i' ) ] ], [ 'a', [ annHash( 'i' ) ] ], [ 'r', [ annHash( 'i' ) ] ] ] }, { type: 'retain', length: 7 } ] }, { msg: 'Extend bold in italic', oldRawHtml: 'foo ba baz
', oldInnerHtml: 'foo ba baz', newInnerHtml: 'foo bar baz', operations: [ { type: 'retain', length: 7 }, { type: 'replace', remove: [], insert: [ [ 'r', [ annHash( 'i' ), annHash( 'b' ) ] ] ] }, { type: 'retain', length: 7 } ] }, { msg: 'Set bold in italic', oldRawHtml: 'foo bar baz
', oldInnerHtml: 'foo bar baz', newInnerHtml: 'foo bar baz', operations: [ { type: 'retain', length: 5 }, { type: 'replace', remove: [ [ 'b', [ annHash( 'i' ) ] ], [ 'a', [ annHash( 'i' ) ] ], [ 'r', [ annHash( 'i' ) ] ] ], insert: [ [ 'b', [ annHash( 'i' ), boldHash ] ], [ 'a', [ annHash( 'i' ), boldHash ] ], [ 'r', [ annHash( 'i' ), boldHash ] ] ] }, { type: 'retain', length: 7 } ] }, { msg: 'Insert at start of bold in italic', oldRawHtml: 'wxy', oldInnerHtml: 'wxy', newInnerHtml: 'wxzy', operations: [ { type: 'retain', length: 3 }, { type: 'replace', remove: [], insert: [ [ 'z', [ annHash( 'i' ), annHash( 'b' ) ] ] ] }, { type: 'retain', length: 4 } ] }, { msg: 'Insert before start of bold in italic', oldRawHtml: 'wxy', oldInnerHtml: 'wxy', newInnerHtml: 'wxzy', operations: [ { type: 'retain', length: 3 }, { type: 'replace', remove: [], insert: [ [ 'z', [ annHash( 'i' ) ] ] ] }, { type: 'retain', length: 4 } ] }, { msg: 'Insert into insertion annotation in italic', willFail: true, oldRawHtml: 'wxz', oldInnerHtml: 'wx