| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463 |
- /**
- * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
- */
- import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
- import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
- import Typing from '@ckeditor/ckeditor5-typing/src/typing';
- import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';
- import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
- import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
- import ListStyleEditing from '../src/liststyleediting';
- import TodoListEditing from '../src/todolistediting';
- import ListStyleCommand from '../src/liststylecommand';
- describe( 'ListStyleEditing', () => {
- let editor, model, view;
- beforeEach( () => {
- return VirtualTestEditor
- .create( {
- plugins: [ Paragraph, ListStyleEditing, UndoEditing ]
- } )
- .then( newEditor => {
- editor = newEditor;
- model = editor.model;
- view = editor.editing.view;
- } );
- } );
- afterEach( () => {
- return editor.destroy();
- } );
- it( 'should have pluginName', () => {
- expect( ListStyleEditing.pluginName ).to.equal( 'ListStyleEditing' );
- } );
- it( 'should be loaded', () => {
- expect( editor.plugins.get( ListStyleEditing ) ).to.be.instanceOf( ListStyleEditing );
- } );
- describe( 'schema rules', () => {
- it( 'should allow set `listStyle` on the `listItem`', () => {
- expect( model.schema.checkAttribute( [ '$root', 'listItem' ], 'listStyle' ) ).to.be.true;
- } );
- } );
- describe( 'command', () => {
- it( 'should register listStyle command', () => {
- const command = editor.commands.get( 'listStyle' );
- expect( command ).to.be.instanceOf( ListStyleCommand );
- } );
- } );
- describe( 'conversion in data pipeline', () => {
- describe( 'model to data', () => {
- it( 'should convert single list (type: bulleted)', () => {
- setModelData( model,
- '<listItem listIndent="0" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listType="bulleted">Bar</listItem>'
- );
- expect( editor.getData() ).to.equal( '<ul><li>Foo</li><li>Bar</li></ul>' );
- } );
- it( 'should convert single list (type: numbered)', () => {
- setModelData( model,
- '<listItem listIndent="0" listType="numbered">Foo</listItem>' +
- '<listItem listIndent="0" listType="numbered">Bar</listItem>'
- );
- expect( editor.getData() ).to.equal( '<ol><li>Foo</li><li>Bar</li></ol>' );
- } );
- it( 'should convert single list (type: bulleted, style: default)', () => {
- setModelData( model,
- '<listItem listIndent="0" listType="bulleted" listStyle="default">Foo</listItem>' +
- '<listItem listIndent="0" listType="bulleted" listStyle="default">Bar</listItem>'
- );
- expect( editor.getData() ).to.equal( '<ul><li>Foo</li><li>Bar</li></ul>' );
- } );
- it( 'should convert single list (type: numbered, style: default)', () => {
- setModelData( model,
- '<listItem listIndent="0" listType="numbered" listStyle="default">Foo</listItem>' +
- '<listItem listIndent="0" listType="numbered" listStyle="default">Bar</listItem>'
- );
- expect( editor.getData() ).to.equal( '<ol><li>Foo</li><li>Bar</li></ol>' );
- } );
- it( 'should convert single list (type: bulleted, style: circle)', () => {
- setModelData( model,
- '<listItem listIndent="0" listType="bulleted" listStyle="circle">Foo</listItem>' +
- '<listItem listIndent="0" listType="bulleted" listStyle="circle">Bar</listItem>'
- );
- expect( editor.getData() ).to.equal( '<ul style="list-style-type:circle;"><li>Foo</li><li>Bar</li></ul>' );
- } );
- it( 'should convert single list (type: numbered, style: upper-alpha)', () => {
- setModelData( model,
- '<listItem listIndent="0" listType="numbered" listStyle="upper-alpha">Foo</listItem>' +
- '<listItem listIndent="0" listType="numbered" listStyle="upper-alpha">Bar</listItem>'
- );
- expect( editor.getData() ).to.equal( '<ol style="list-style-type:upper-alpha;"><li>Foo</li><li>Bar</li></ol>' );
- } );
- it( 'should convert nested bulleted lists (main: circle, nested: disc)', () => {
- setModelData( model,
- '<listItem listIndent="0" listType="bulleted" listStyle="circle">Foo 1</listItem>' +
- '<listItem listIndent="1" listType="bulleted" listStyle="disc">Bar 1</listItem>' +
- '<listItem listIndent="1" listType="bulleted" listStyle="disc">Bar 2</listItem>' +
- '<listItem listIndent="0" listType="bulleted" listStyle="circle">Foo 2</listItem>' +
- '<listItem listIndent="0" listType="bulleted" listStyle="circle">Foo 3</listItem>'
- );
- expect( editor.getData() ).to.equal(
- '<ul style="list-style-type:circle;">' +
- '<li>Foo 1' +
- '<ul style="list-style-type:disc;">' +
- '<li>Bar 1</li>' +
- '<li>Bar 2</li>' +
- '</ul>' +
- '</li>' +
- '<li>Foo 2</li>' +
- '<li>Foo 3</li>' +
- '</ul>'
- );
- } );
- it( 'should convert nested numbered lists (main: decimal-leading-zero, nested: lower-latin)', () => {
- setModelData( model,
- '<listItem listIndent="0" listType="numbered" listStyle="decimal-leading-zero">Foo 1</listItem>' +
- '<listItem listIndent="1" listType="numbered" listStyle="lower-latin">Bar 1</listItem>' +
- '<listItem listIndent="1" listType="numbered" listStyle="lower-latin">Bar 2</listItem>' +
- '<listItem listIndent="0" listType="numbered" listStyle="decimal-leading-zero">Foo 2</listItem>' +
- '<listItem listIndent="0" listType="numbered" listStyle="decimal-leading-zero">Foo 3</listItem>'
- );
- expect( editor.getData() ).to.equal(
- '<ol style="list-style-type:decimal-leading-zero;">' +
- '<li>Foo 1' +
- '<ol style="list-style-type:lower-latin;">' +
- '<li>Bar 1</li>' +
- '<li>Bar 2</li>' +
- '</ol>' +
- '</li>' +
- '<li>Foo 2</li>' +
- '<li>Foo 3</li>' +
- '</ol>'
- );
- } );
- it( 'should convert nested mixed lists (ul>ol, main: square, nested: lower-roman)', () => {
- setModelData( model,
- '<listItem listIndent="0" listType="bulleted" listStyle="square">Foo 1</listItem>' +
- '<listItem listIndent="1" listType="numbered" listStyle="lower-roman">Bar 1</listItem>' +
- '<listItem listIndent="1" listType="numbered" listStyle="lower-roman">Bar 2</listItem>' +
- '<listItem listIndent="0" listType="bulleted" listStyle="square">Foo 2</listItem>' +
- '<listItem listIndent="0" listType="bulleted" listStyle="square">Foo 3</listItem>'
- );
- expect( editor.getData() ).to.equal(
- '<ul style="list-style-type:square;">' +
- '<li>Foo 1' +
- '<ol style="list-style-type:lower-roman;">' +
- '<li>Bar 1</li>' +
- '<li>Bar 2</li>' +
- '</ol>' +
- '</li>' +
- '<li>Foo 2</li>' +
- '<li>Foo 3</li>' +
- '</ul>'
- );
- } );
- it( 'should produce nested lists (different `listIndent` attribute)', () => {
- setModelData( model,
- '<listItem listIndent="0" listType="numbered" listStyle="decimal">Foo 1</listItem>' +
- '<listItem listIndent="0" listType="numbered" listStyle="decimal">Foo 2</listItem>' +
- '<listItem listIndent="1" listType="numbered" listStyle="decimal">Bar 1</listItem>' +
- '<listItem listIndent="1" listType="numbered" listStyle="decimal">Bar 2</listItem>'
- );
- expect( editor.getData() ).to.equal(
- '<ol style="list-style-type:decimal;">' +
- '<li>Foo 1</li>' +
- '<li>Foo 2' +
- '<ol style="list-style-type:decimal;">' +
- '<li>Bar 1</li>' +
- '<li>Bar 2</li>' +
- '</ol>' +
- '</li>' +
- '</ol>'
- );
- } );
- it( 'should produce two different lists (different `listType` attribute)', () => {
- setModelData( model,
- '<listItem listIndent="0" listType="numbered" listStyle="decimal">Foo 1</listItem>' +
- '<listItem listIndent="0" listType="numbered" listStyle="decimal">Foo 2</listItem>' +
- '<listItem listIndent="0" listType="bulleted" listStyle="disc">Bar 1</listItem>' +
- '<listItem listIndent="0" listType="bulleted" listStyle="disc">Bar 2</listItem>'
- );
- expect( editor.getData() ).to.equal(
- '<ol style="list-style-type:decimal;">' +
- '<li>Foo 1</li>' +
- '<li>Foo 2</li>' +
- '</ol>' +
- '<ul style="list-style-type:disc;">' +
- '<li>Bar 1</li>' +
- '<li>Bar 2</li>' +
- '</ul>'
- );
- } );
- it( 'should produce two different lists (different `listStyle` attribute)', () => {
- setModelData( model,
- '<listItem listIndent="0" listType="bulleted" listStyle="disc">Foo 1</listItem>' +
- '<listItem listIndent="0" listType="bulleted" listStyle="disc">Foo 2</listItem>' +
- '<listItem listIndent="0" listType="bulleted" listStyle="circle">Bar 1</listItem>' +
- '<listItem listIndent="0" listType="bulleted" listStyle="circle">Bar 2</listItem>'
- );
- expect( editor.getData() ).to.equal(
- '<ul style="list-style-type:disc;">' +
- '<li>Foo 1</li>' +
- '<li>Foo 2</li>' +
- '</ul>' +
- '<ul style="list-style-type:circle;">' +
- '<li>Bar 1</li>' +
- '<li>Bar 2</li>' +
- '</ul>'
- );
- } );
- it( 'should not allow to set the `listStyle` attribute in to-do list item', () => {
- setModelData( model, '<listItem listIndent="0" listType="todo">Foo</listItem>' );
- const listItem = model.document.getRoot().getChild( 0 );
- expect( listItem.hasAttribute( 'listItem' ) ).to.be.false;
- model.change( writer => {
- writer.setAttribute( 'listType', 'foo', listItem );
- } );
- expect( listItem.hasAttribute( 'listItem' ) ).to.be.false;
- } );
- } );
- describe( 'view to model', () => {
- it( 'should convert single list (type: bulleted)', () => {
- editor.setData( '<ul><li>Foo</li><li>Bar</li></ul>' );
- expect( getModelData( model, { withoutSelection: true } ) ).to.equal(
- '<listItem listIndent="0" listStyle="default" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="default" listType="bulleted">Bar</listItem>'
- );
- } );
- it( 'should convert single list (type: numbered)', () => {
- editor.setData( '<ol><li>Foo</li><li>Bar</li></ol>' );
- expect( getModelData( model, { withoutSelection: true } ) ).to.equal(
- '<listItem listIndent="0" listStyle="default" listType="numbered">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="default" listType="numbered">Bar</listItem>'
- );
- } );
- it( 'should convert single list (type: bulleted, style: circle)', () => {
- editor.setData( '<ul style="list-style-type:circle;"><li>Foo</li><li>Bar</li></ul>' );
- expect( getModelData( model, { withoutSelection: true } ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Bar</listItem>'
- );
- } );
- it( 'should convert single list (type: numbered, style: upper-alpha)', () => {
- editor.setData( '<ol style="list-style-type:upper-alpha;"><li>Foo</li><li>Bar</li></ol>' );
- expect( getModelData( model, { withoutSelection: true } ) ).to.equal(
- '<listItem listIndent="0" listStyle="upper-alpha" listType="numbered">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="upper-alpha" listType="numbered">Bar</listItem>'
- );
- } );
- it( 'should convert nested and mixed lists', () => {
- editor.setData(
- '<ol style="list-style-type:upper-alpha;">' +
- '<li>OL 1</li>' +
- '<li>OL 2' +
- '<ul style="list-style-type:circle;">' +
- '<li>UL 1</li>' +
- '<li>UL 2</li>' +
- '</ul>' +
- '</li>' +
- '<li>OL 3</li>' +
- '</ol>'
- );
- expect( getModelData( model, { withoutSelection: true } ) ).to.equal(
- '<listItem listIndent="0" listStyle="upper-alpha" listType="numbered">OL 1</listItem>' +
- '<listItem listIndent="0" listStyle="upper-alpha" listType="numbered">OL 2</listItem>' +
- '<listItem listIndent="1" listStyle="circle" listType="bulleted">UL 1</listItem>' +
- '<listItem listIndent="1" listStyle="circle" listType="bulleted">UL 2</listItem>' +
- '<listItem listIndent="0" listStyle="upper-alpha" listType="numbered">OL 3</listItem>'
- );
- } );
- it( 'should convert when the list is in the middle of the content', () => {
- editor.setData(
- '<p>Paragraph.</p>' +
- '<ol style="list-style-type:upper-alpha;">' +
- '<li>Foo</li>' +
- '<li>Bar</li>' +
- '</ol>' +
- '<p>Paragraph.</p>'
- );
- expect( getModelData( model, { withoutSelection: true } ) ).to.equal(
- '<paragraph>Paragraph.</paragraph>' +
- '<listItem listIndent="0" listStyle="upper-alpha" listType="numbered">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="upper-alpha" listType="numbered">Bar</listItem>' +
- '<paragraph>Paragraph.</paragraph>'
- );
- } );
- // See: #8262.
- describe( 'list conversion with surrounding text nodes', () => {
- let editor;
- beforeEach( () => {
- return VirtualTestEditor
- .create( {
- plugins: [ ListStyleEditing ]
- } )
- .then( newEditor => {
- editor = newEditor;
- } );
- } );
- afterEach( () => {
- return editor.destroy();
- } );
- it( 'should convert a list if raw text is before the list', () => {
- editor.setData( 'Foo<ul><li>Foo</li></ul>' );
- expect( editor.getData() ).to.equal( '<p>Foo</p><ul><li>Foo</li></ul>' );
- } );
- it( 'should convert a list if raw text is after the list', () => {
- editor.setData( '<ul><li>Foo</li></ul>Foo' );
- expect( editor.getData() ).to.equal( '<ul><li>Foo</li></ul><p>Foo</p>' );
- } );
- it( 'should convert a list if it is surrender by two text nodes', () => {
- editor.setData( 'Foo<ul><li>Foo</li></ul>Foo' );
- expect( editor.getData() ).to.equal( '<p>Foo</p><ul><li>Foo</li></ul><p>Foo</p>' );
- } );
- } );
- } );
- } );
- // At this moment editing and data pipelines produce exactly the same content.
- // Just a few tests will be enough here. `model to data` block contains all cases checked.
- describe( 'conversion in editing pipeline', () => {
- describe( 'model to view', () => {
- it( 'should convert single list (type: bulleted, style: default)', () => {
- setModelData( model,
- '<listItem listIndent="0" listType="bulleted" listStyle="default">Foo</listItem>' +
- '<listItem listIndent="0" listType="bulleted" listStyle="default">Bar</listItem>'
- );
- expect( getViewData( view, { withoutSelection: true } ) ).to.equal(
- '<ul><li>Foo</li><li>Bar</li></ul>'
- );
- } );
- it( 'should convert single list (type: bulleted, style: circle)', () => {
- setModelData( model,
- '<listItem listIndent="0" listType="bulleted" listStyle="circle">Foo</listItem>' +
- '<listItem listIndent="0" listType="bulleted" listStyle="circle">Bar</listItem>'
- );
- expect( getViewData( view, { withoutSelection: true } ) ).to.equal(
- '<ul style="list-style-type:circle"><li>Foo</li><li>Bar</li></ul>'
- );
- } );
- it( 'should convert nested bulleted lists (main: circle, nested: disc)', () => {
- setModelData( model,
- '<listItem listIndent="0" listType="bulleted" listStyle="circle">Foo 1</listItem>' +
- '<listItem listIndent="1" listType="bulleted" listStyle="disc">Bar 1</listItem>' +
- '<listItem listIndent="1" listType="bulleted" listStyle="disc">Bar 2</listItem>' +
- '<listItem listIndent="0" listType="bulleted" listStyle="circle">Foo 2</listItem>' +
- '<listItem listIndent="0" listType="bulleted" listStyle="circle">Foo 3</listItem>'
- );
- expect( getViewData( view, { withoutSelection: true } ) ).to.equal(
- '<ul style="list-style-type:circle">' +
- '<li>Foo 1' +
- '<ul style="list-style-type:disc">' +
- '<li>Bar 1</li>' +
- '<li>Bar 2</li>' +
- '</ul>' +
- '</li>' +
- '<li>Foo 2</li>' +
- '<li>Foo 3</li>' +
- '</ul>'
- );
- } );
- // See: #8081.
- it( 'should convert properly nested list styles', () => {
- // ■ Level 0
- // ▶ Level 0.1
- // ○ Level 0.1.1
- // ▶ Level 0.2
- // ○ Level 0.2.1
- setModelData( model,
- '<listItem listIndent="0" listType="bulleted" listStyle="default">Level 0</listItem>' +
- '<listItem listIndent="1" listType="bulleted" listStyle="default">Level 0.1</listItem>' +
- '<listItem listIndent="2" listType="bulleted" listStyle="circle">Level 0.1.1</listItem>' +
- '<listItem listIndent="1" listType="bulleted" listStyle="default">Level 0.2</listItem>' +
- '<listItem listIndent="2" listType="bulleted" listStyle="circle">Level 0.2.1</listItem>'
- );
- expect( getViewData( view, { withoutSelection: true } ) ).to.equal(
- '<ul>' +
- '<li>Level 0' +
- '<ul>' +
- '<li>Level 0.1' +
- '<ul style="list-style-type:circle">' +
- '<li>Level 0.1.1</li>' +
- '</ul>' +
- '</li>' +
- '<li>Level 0.2' +
- '<ul style="list-style-type:circle">' +
- '<li>Level 0.2.1</li>' +
- '</ul>' +
- '</li>' +
- '</ul>' +
- '</li>' +
- '</ul>'
- );
- } );
- } );
- } );
- describe( 'integrations', () => {
- describe( 'merging a list into a styled list', () => {
- it( 'should inherit the list style attribute when merging the same kind of lists (from top, merge a single item)', () => {
- setModelData( model,
- '<paragraph>Foo Bar.[]</paragraph>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Bar</listItem>'
- );
- editor.execute( 'bulletedList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo Bar.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Bar</listItem>'
- );
- } );
- it( 'should inherit the list style attribute when merging the same kind of lists (from top, merge a few items)', () => {
- setModelData( model,
- '<paragraph>[Foo Bar 1.</paragraph>' +
- '<paragraph>Foo Bar 2.]</paragraph>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Bar</listItem>'
- );
- editor.execute( 'bulletedList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">[Foo Bar 1.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo Bar 2.]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Bar</listItem>'
- );
- } );
- it( 'should not inherit anything if there is no list below the inserted list', () => {
- setModelData( model,
- '<paragraph>Foo Bar 1.[]</paragraph>' +
- '<paragraph>Foo Bar 2.</paragraph>'
- );
- editor.execute( 'bulletedList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="default" listType="bulleted">Foo Bar 1.[]</listItem>' +
- '<paragraph>Foo Bar 2.</paragraph>'
- );
- } );
- it( 'should not inherit anything if replacing the entire content with a list', () => {
- setModelData( model,
- '<paragraph>Foo Bar 1.[]</paragraph>'
- );
- editor.execute( 'bulletedList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="default" listType="bulleted">Foo Bar 1.[]</listItem>'
- );
- } );
- it( 'should not inherit the list style attribute when merging different kind of lists (from top, merge a single item)', () => {
- setModelData( model,
- '<paragraph>Foo Bar.[]</paragraph>' +
- '<listItem listIndent="0" listStyle="decimal-leading-zero" listType="numbered">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="decimal-leading-zero" listType="numbered">Bar</listItem>'
- );
- editor.execute( 'bulletedList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="default" listType="bulleted">Foo Bar.[]</listItem>' +
- '<listItem listIndent="0" listStyle="decimal-leading-zero" listType="numbered">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="decimal-leading-zero" listType="numbered">Bar</listItem>'
- );
- } );
- it(
- 'should not inherit the list style attribute when merging different kind of lists (from bottom, merge a single item)',
- () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="decimal-leading-zero" listType="numbered">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="decimal-leading-zero" listType="numbered">Bar</listItem>' +
- '<paragraph>Foo Bar.[]</paragraph>'
- );
- editor.execute( 'bulletedList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="decimal-leading-zero" listType="numbered">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="decimal-leading-zero" listType="numbered">Bar</listItem>' +
- '<listItem listIndent="0" listStyle="default" listType="bulleted">Foo Bar.[]</listItem>'
- );
- }
- );
- it( 'should inherit the list style attribute when merging the same kind of lists (from bottom, merge a single item)', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Bar</listItem>' +
- '<paragraph>Foo Bar.[]</paragraph>'
- );
- editor.execute( 'bulletedList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Bar</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo Bar.[]</listItem>'
- );
- } );
- it(
- 'should inherit the list style attribute from listIndent=0 element when merging the same kind of lists (from bottom)',
- () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="1" listStyle="square" listType="bulleted">Bar</listItem>' +
- '<listItem listIndent="2" listStyle="disc" listType="bulleted">Foo Bar</listItem>' +
- '<paragraph>Foo Bar.[]</paragraph>'
- );
- editor.execute( 'bulletedList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="1" listStyle="square" listType="bulleted">Bar</listItem>' +
- '<listItem listIndent="2" listStyle="disc" listType="bulleted">Foo Bar</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo Bar.[]</listItem>'
- );
- }
- );
- } );
- describe( 'modifying "listType" attribute', () => {
- it( 'should inherit the list style attribute when the modified list is the same kind of the list as next sibling', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="default" listType="numbered">Foo Bar.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Bar</listItem>'
- );
- editor.execute( 'bulletedList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo Bar.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Bar</listItem>'
- );
- } );
- it( 'should inherit the list style attribute when the modified list is the same kind of the list as previous sibling', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Bar</listItem>' +
- '<listItem listIndent="0" listStyle="default" listType="numbered">Foo Bar.[]</listItem>'
- );
- editor.execute( 'bulletedList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Bar</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo Bar.[]</listItem>'
- );
- } );
- it( 'should not inherit the list style attribute when the modified list already has defined it (next sibling check)', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="default" listType="bulleted">Foo Bar.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Bar</listItem>'
- );
- editor.execute( 'listStyle', { type: 'disc' } );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="disc" listType="bulleted">Foo Bar.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Bar</listItem>'
- );
- } );
- it(
- 'should not inherit the list style attribute when the modified list already has defined it (previous sibling check)',
- () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Bar</listItem>' +
- '<listItem listIndent="0" listStyle="default" listType="bulleted">Foo Bar.[]</listItem>'
- );
- editor.execute( 'listStyle', { type: 'disc' } );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Bar</listItem>' +
- '<listItem listIndent="0" listStyle="disc" listType="bulleted">Foo Bar.[]</listItem>'
- );
- }
- );
- } );
- describe( 'indenting lists', () => {
- it( 'should restore the default value for the list style attribute when indenting a single item', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">1A.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2B.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">3.</listItem>'
- );
- editor.execute( 'indentList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">1A.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2B.</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">2.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">3.</listItem>'
- );
- } );
- it( 'should restore the default value for the list style attribute when indenting a few items', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">[2.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">3.]</listItem>'
- );
- editor.execute( 'indentList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">[2.</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">3.]</listItem>'
- );
- } );
- it(
- 'should copy the value for the list style attribute when indenting a single item into a nested list (default value)',
- () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">3.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">4.</listItem>'
- );
- editor.execute( 'indentList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">3.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">4.</listItem>'
- );
- }
- );
- it(
- 'should copy the value for the list style attribute when indenting a single item into a nested list (changed value)',
- () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="disc" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">3.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">4.</listItem>'
- );
- editor.execute( 'indentList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="disc" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="1" listStyle="disc" listType="bulleted">3.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">4.</listItem>'
- );
- }
- );
- it( 'should copy the value for the list style attribute when indenting a single item into a nested list', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.[]</listItem>' +
- '<listItem listIndent="1" listStyle="square" listType="bulleted">3.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">4.</listItem>'
- );
- editor.execute( 'indentList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">2.[]</listItem>' +
- '<listItem listIndent="2" listStyle="square" listType="bulleted">3.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">4.</listItem>'
- );
- } );
- it(
- 'should copy the value for the list style attribute when indenting a single item into a nested list ' +
- '(many nested lists check)',
- () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="disc" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="2" listStyle="square" listType="bulleted">3.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">4.[]</listItem>'
- );
- editor.execute( 'indentList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="disc" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="2" listStyle="square" listType="bulleted">3.</listItem>' +
- '<listItem listIndent="1" listStyle="disc" listType="bulleted">4.[]</listItem>'
- );
- }
- );
- it( 'should inherit the list style attribute from nested list if the `listType` is other than indenting element', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="decimal" listType="numbered">2.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">3.[]</listItem>'
- );
- editor.execute( 'indentList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="decimal" listType="numbered">2.</listItem>' +
- '<listItem listIndent="1" listStyle="decimal" listType="numbered">3.[]</listItem>'
- );
- } );
- // See: #8072.
- it( 'should not throw when indenting a list without any other content in the editor', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="default" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="default" listType="bulleted">[]</listItem>'
- );
- editor.execute( 'indentList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="default" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">[]</listItem>'
- );
- } );
- } );
- describe( 'outdenting lists', () => {
- it( 'should inherit the list style attribute from parent list (change the first nested item)', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">2.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">3.</listItem>'
- );
- editor.execute( 'outdentList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">3.</listItem>'
- );
- } );
- it( 'should inherit the list style attribute from parent list (change the second nested item)', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">3.[]</listItem>'
- );
- editor.execute( 'outdentList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">3.[]</listItem>'
- );
- } );
- it( 'should inherit the list style attribute from parent list (modifying nested lists)', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">[2.</listItem>' +
- '<listItem listIndent="2" listStyle="square" listType="bulleted">3.]</listItem>'
- );
- editor.execute( 'outdentList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">[2.</listItem>' +
- '<listItem listIndent="1" listStyle="square" listType="bulleted">3.]</listItem>'
- );
- } );
- it(
- 'should inherit the list style attribute from parent list (outdenting many items, including the first one in the list)',
- () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">[1.</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="2" listStyle="square" listType="bulleted">3.]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">4.</listItem>'
- );
- editor.execute( 'outdentList' );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>[1.</paragraph>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="1" listStyle="square" listType="bulleted">3.]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">4.</listItem>'
- );
- }
- );
- it(
- 'should inherit the list style attribute from parent list (outdenting the first item that is a parent for next list)',
- () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.[]</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="2" listStyle="square" listType="bulleted">3.</listItem>' +
- '<listItem listIndent="3" listStyle="disc" listType="bulleted">4.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">5.</listItem>'
- );
- editor.execute( 'outdentList' );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>1.[]</paragraph>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="1" listStyle="square" listType="bulleted">3.</listItem>' +
- '<listItem listIndent="2" listStyle="disc" listType="bulleted">4.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">5.</listItem>'
- );
- }
- );
- it( 'should not inherit the list style if outdented the only one item in the list', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.[]</listItem>' +
- '<listItem listIndent="1" listStyle="disc" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="2" listStyle="square" listType="bulleted">3.</listItem>'
- );
- editor.execute( 'outdentList' );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>1.[]</paragraph>' +
- '<listItem listIndent="0" listStyle="disc" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="1" listStyle="square" listType="bulleted">3.</listItem>'
- );
- } );
- it( 'should not inherit the list style if outdented the only one item in the list (a paragraph below the list)', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.[]</listItem>' +
- '<listItem listIndent="1" listStyle="disc" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="2" listStyle="square" listType="bulleted">3.</listItem>' +
- '<paragraph>Foo</paragraph>'
- );
- editor.execute( 'outdentList' );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>1.[]</paragraph>' +
- '<listItem listIndent="0" listStyle="disc" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="1" listStyle="square" listType="bulleted">3.</listItem>' +
- '<paragraph>Foo</paragraph>'
- );
- } );
- it( 'should not inherit the list style attribute from parent list if the `listType` is other than outdenting element', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="decimal" listType="numbered">2.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">3.</listItem>'
- );
- editor.execute( 'outdentList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="decimal" listType="numbered">2.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">3.</listItem>'
- );
- } );
- it( 'should not do anything if there is no list after outdenting', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.[]</listItem>'
- );
- editor.execute( 'outdentList' );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>1.[]</paragraph>'
- );
- } );
- } );
- describe( 'indent/outdent + undo', () => {
- it( 'should use the same batch for indenting a list and updating `listType` attribute', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">1A.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2B.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">3.</listItem>'
- );
- editor.execute( 'indentList' );
- editor.execute( 'undo' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">1A.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2B.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">3.</listItem>'
- );
- } );
- it( 'should use the same batch for outdenting a list and updating `listType` attribute', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">2.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">3.</listItem>'
- );
- editor.execute( 'outdentList' );
- editor.execute( 'undo' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">2.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">3.</listItem>'
- );
- } );
- } );
- describe( 'delete + undo', () => {
- let editor, model, view;
- beforeEach( () => {
- return VirtualTestEditor
- .create( {
- plugins: [ Paragraph, ListStyleEditing, Typing, UndoEditing ]
- } )
- .then( newEditor => {
- editor = newEditor;
- model = editor.model;
- view = editor.editing.view;
- } );
- } );
- afterEach( () => {
- return editor.destroy();
- } );
- // See: #7930.
- it( 'should restore proper list style attribute after undo merging lists', () => {
- // ○ 1.
- // ○ 2.
- // ○ 3.
- // <paragraph>
- // ■ 1.
- // ■ 2.
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">3.</listItem>' +
- '<paragraph>[]</paragraph>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2.</listItem>'
- );
- expect( getViewData( view, { withoutSelection: true } ), 'initial data' ).to.equal(
- '<ul style="list-style-type:circle">' +
- '<li>1.</li>' +
- '<li>2.</li>' +
- '<li>3.</li>' +
- '</ul>' +
- '<p></p>' +
- '<ul style="list-style-type:square">' +
- '<li>1.</li>' +
- '<li>2.</li>' +
- '</ul>'
- );
- // After removing the paragraph.
- // ○ 1.
- // ○ 2.
- // ○ 3.
- // ○ 1.
- // ○ 2.
- editor.execute( 'delete' );
- expect( getViewData( view, { withoutSelection: true } ), 'executing delete' ).to.equal(
- '<ul style="list-style-type:circle">' +
- '<li>1.</li>' +
- '<li>2.</li>' +
- '<li>3.</li>' +
- '<li>1.</li>' +
- '<li>2.</li>' +
- '</ul>'
- );
- // After undo.
- // ○ 1.
- // ○ 2.
- // ○ 3.
- // <paragraph>
- // ■ 1.
- // ■ 2.
- editor.execute( 'undo' );
- expect( getViewData( view, { withoutSelection: true } ), 'initial data' ).to.equal(
- '<ul style="list-style-type:circle">' +
- '<li>1.</li>' +
- '<li>2.</li>' +
- '<li>3.</li>' +
- '</ul>' +
- '<p></p>' +
- '<ul style="list-style-type:square">' +
- '<li>1.</li>' +
- '<li>2.</li>' +
- '</ul>'
- );
- } );
- } );
- describe( 'todo list', () => {
- let editor, model;
- beforeEach( () => {
- return VirtualTestEditor
- .create( {
- // TodoListEditing is at the end by design. Check `ListStyleEditing.afterInit()` call.
- plugins: [ Paragraph, ListStyleEditing, TodoListEditing ]
- } )
- .then( newEditor => {
- editor = newEditor;
- model = editor.model;
- } );
- } );
- afterEach( () => {
- return editor.destroy();
- } );
- it( 'should not add the `listStyle` attribute while creating a todo list', () => {
- setModelData( model, '<paragraph>Foo[]</paragraph>' );
- editor.execute( 'todoList' );
- expect( getModelData( model ), '<listItem listIndent="0" listType="todo">Foo[]</listItem>' );
- } );
- it( 'should not add the `listStyle` attribute while switching the list type', () => {
- setModelData( model, '<listItem listIndent="0" listType="bulleted">Foo[]</listItem>' );
- editor.execute( 'todoList' );
- expect( getModelData( model ), '<listItem listIndent="0" listType="todo">Foo[]</listItem>' );
- } );
- it( 'should remove the `listStyle` attribute while switching the list type that uses the list style feature', () => {
- setModelData( model, '<listItem listIndent="0" listType="bulleted" listStyle="circle">Foo[]</listItem>' );
- editor.execute( 'todoList' );
- expect( getModelData( model ), '<listItem listIndent="0" listType="todo">Foo[]</listItem>' );
- } );
- it( 'should not inherit the list style attribute when inserting a todo list item', () => {
- setModelData( model,
- '<paragraph>Foo Bar.[]</paragraph>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Bar</listItem>'
- );
- editor.execute( 'todoList' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listType="todo">Foo Bar.[]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Foo</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">Bar</listItem>'
- );
- } );
- } );
- describe( 'removing content between two lists', () => {
- let editor, model;
- beforeEach( () => {
- return VirtualTestEditor
- .create( {
- plugins: [ Paragraph, ListStyleEditing, Typing ]
- } )
- .then( newEditor => {
- editor = newEditor;
- model = editor.model;
- } );
- } );
- afterEach( () => {
- return editor.destroy();
- } );
- it( 'should not do anything while removing a letter inside a listItem', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="square" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2.[]</listItem>' +
- '<paragraph></paragraph>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.</listItem>'
- );
- editor.execute( 'delete' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="square" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2[]</listItem>' +
- '<paragraph></paragraph>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.</listItem>'
- );
- } );
- it( 'should not do anything if there is a non-listItem before the removed content', () => {
- setModelData( model,
- '<paragraph>Foo</paragraph>' +
- '<paragraph>[]</paragraph>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.</listItem>'
- );
- editor.execute( 'delete' );
- expect( getModelData( model ) ).to.equal(
- '<paragraph>Foo[]</paragraph>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.</listItem>'
- );
- } );
- it( 'should not do anything if there is a non-listItem after the removed content', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.</listItem>' +
- '<paragraph>[]</paragraph>' +
- '<paragraph>Foo</paragraph>'
- );
- editor.execute( 'delete' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.[]</listItem>' +
- '<paragraph>Foo</paragraph>'
- );
- } );
- it( 'should not do anything if there is no element after the removed content', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.</listItem>' +
- '<paragraph>[]</paragraph>'
- );
- editor.execute( 'delete' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.[]</listItem>'
- );
- } );
- it(
- 'should modify the the `listStyle` attribute for the merged (second) list when removing content between those lists',
- () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="square" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2.</listItem>' +
- '<paragraph>[]</paragraph>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.</listItem>'
- );
- editor.execute( 'delete' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="square" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2.[]</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2.</listItem>'
- );
- }
- );
- it( 'should read the `listStyle` attribute from the most outer list', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="square" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="1" listStyle="decimal" listType="numbered">2.1.</listItem>' +
- '<listItem listIndent="2" listStyle="default" listType="numbered">2.1.1</listItem>' +
- '<paragraph>[]</paragraph>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.</listItem>'
- );
- editor.execute( 'delete' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="square" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="1" listStyle="decimal" listType="numbered">2.1.</listItem>' +
- '<listItem listIndent="2" listStyle="default" listType="numbered">2.1.1[]</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2.</listItem>'
- );
- } );
- it(
- 'should not modify the the `listStyle` attribute for the merged (second) list if merging different `listType` attribute',
- () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="square" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2.</listItem>' +
- '<paragraph>[]</paragraph>' +
- '<listItem listIndent="0" listStyle="decimal" listType="numbered">1.</listItem>' +
- '<listItem listIndent="0" listStyle="decimal" listType="numbered">2.</listItem>'
- );
- editor.execute( 'delete' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="square" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2.[]</listItem>' +
- '<listItem listIndent="0" listStyle="decimal" listType="numbered">1.</listItem>' +
- '<listItem listIndent="0" listStyle="decimal" listType="numbered">2.</listItem>'
- );
- }
- );
- it(
- 'should modify the the `listStyle` attribute for the merged (second) list when removing content from both lists',
- () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="square" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">[3.</listItem>' +
- '<paragraph>Foo</paragraph>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.</listItem>'
- );
- editor.execute( 'delete' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="square" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">[]</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2.</listItem>'
- );
- }
- );
- it(
- 'should modify the the `listStyle` attribute for the merged (second) list when typing over content from both lists',
- () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="square" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">[3.</listItem>' +
- '<paragraph>Foo</paragraph>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.]</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.</listItem>'
- );
- editor.execute( 'input', { text: 'Foo' } );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="square" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">Foo[]</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2.</listItem>'
- );
- }
- );
- it(
- 'should not modify the the `listStyle` if lists were not merged but the content was partially removed',
- () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="square" listType="bulleted">111.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">222.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">[333.</listItem>' +
- '<paragraph>Foo</paragraph>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1]11.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.</listItem>'
- );
- editor.execute( 'delete' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="square" listType="bulleted">111.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">222.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">[]11.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.</listItem>'
- );
- }
- );
- it( 'should not do anything while typing in a list item', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="square" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2.[]</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">3.</listItem>' +
- '<paragraph></paragraph>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.</listItem>'
- );
- const modelChangeStub = sinon.stub( model, 'change' ).callThrough();
- simulateTyping( ' Foo' );
- // Each character calls `editor.model.change()`.
- expect( modelChangeStub.callCount ).to.equal( 4 );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="square" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2. Foo[]</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">3.</listItem>' +
- '<paragraph></paragraph>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">2.</listItem>'
- );
- } );
- // See: #8073.
- it( 'should not crash when removing a content between intended lists', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="default" listType="bulleted">aaaa</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">bb[bb</listItem>' +
- '<listItem listIndent="2" listStyle="default" listType="bulleted">cc]cc</listItem>' +
- '<listItem listIndent="3" listStyle="default" listType="bulleted">dddd</listItem>'
- );
- editor.execute( 'delete' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="default" listType="bulleted">aaaa</listItem>' +
- '<listItem listIndent="1" listStyle="default" listType="bulleted">bb[]cc</listItem>' +
- '<listItem listIndent="2" listStyle="default" listType="bulleted">dddd</listItem>'
- );
- } );
- it( 'should read the `listStyle` attribute from the most outer selected list while removing content between lists', () => {
- setModelData( model,
- '<listItem listIndent="0" listStyle="square" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="1" listStyle="decimal" listType="numbered">2.1.</listItem>' +
- '<listItem listIndent="2" listStyle="lower-latin" listType="numbered">2.1.1[foo</listItem>' +
- '<paragraph>Foo</paragraph>' +
- '<listItem listIndent="0" listStyle="circle" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="1" listStyle="circle" listType="bulleted">bar]2.</listItem>'
- );
- editor.execute( 'delete' );
- expect( getModelData( model ) ).to.equal(
- '<listItem listIndent="0" listStyle="square" listType="bulleted">1.</listItem>' +
- '<listItem listIndent="0" listStyle="square" listType="bulleted">2.</listItem>' +
- '<listItem listIndent="1" listStyle="decimal" listType="numbered">2.1.</listItem>' +
- '<listItem listIndent="2" listStyle="lower-latin" listType="numbered">2.1.1[]2.</listItem>'
- );
- } );
- function simulateTyping( text ) {
- // While typing, every character is an atomic change.
- text.split( '' ).forEach( character => {
- editor.execute( 'input', {
- text: character
- } );
- } );
- }
- } );
- } );
- } );
|