Ejemplo n.º 1
0
		it( 'should update value after execution', () => {
			setData( model, '<paragraph>[]</paragraph>' );
			command.execute( { value: 'heading1' } );

			expect( getData( model ) ).to.equal( '<heading1>[]</heading1>' );
			expect( command.value ).to.equal( 'heading1' );
		} );
Ejemplo n.º 2
0
		it( 'should do nothing with non-registered model elements', () => {
			setData( model, '<heading1>[]</heading1>' );
			command.execute( { value: 'heading5' } );

			expect( getData( model ) ).to.equal( '<heading1>[]</heading1>' );
			expect( command.value ).to.equal( 'heading1' );
		} );
Ejemplo n.º 3
0
			it( 'does nothing to the elements with same option (#2)', () => {
				setData( model, '<heading1>[foo</heading1><heading1>bar</heading1><heading2>baz]</heading2>' );
				command.execute( { value: 'heading1' } );

				expect( getData( model ) ).to.equal(
					'<heading1>[foo</heading1><heading1>bar</heading1><heading1>baz]</heading1>'
				);
			} );
Ejemplo n.º 4
0
			it( 'converts topmost blocks', () => {
				schema.register( 'inlineImage', { allowWhere: '$text' } );
				schema.extend( '$text', { allowIn: 'inlineImage' } );

				setData( model, '<paragraph><inlineImage>foo[]</inlineImage>bar</paragraph>' );
				command.execute( { value: 'heading1' } );

				expect( getData( model ) ).to.equal( '<heading1><inlineImage>foo[]</inlineImage>bar</heading1>' );
			} );
Ejemplo n.º 5
0
			it( 'converts all elements where selection is applied', () => {
				setData( model, '<heading1>foo[</heading1><heading2>bar</heading2><heading3>baz]</heading3>' );

				command.execute( { value: 'heading3' } );

				expect( getData( model ) ).to.equal(
					'<heading3>foo[</heading3><heading3>bar</heading3><heading3>baz]</heading3>'
				);
			} );
Ejemplo n.º 6
0
			it( `equals false if moved from ${ modelElement } to non-block element`, () => {
				setData( model, `<${ modelElement }>[foo]</${ modelElement }><notBlock>foo</notBlock>` );
				const element = document.getRoot().getChild( 1 );

				model.change( writer => {
					writer.setSelection( writer.createRangeIn( element ) );
				} );

				expect( command.value ).to.be.false;
			} );
Ejemplo n.º 7
0
		it( 'should use parent batch', () => {
			setData( model, '<paragraph>foo[]bar</paragraph>' );

			model.change( writer => {
				expect( writer.batch.operations.length ).to.equal( 0 );

				command.execute( { value: 'heading1' } );

				expect( writer.batch.operations.length ).to.be.above( 0 );
			} );
		} );
Ejemplo n.º 8
0
			it( 'should be refreshed after calling refresh()', () => {
				setData( model, `<${ modelElement }>[foo]</${ modelElement }><notBlock>foo</notBlock>` );
				const element = document.getRoot().getChild( 1 );

				model.change( writer => {
					writer.setSelection( writer.createRangeIn( element ) );

					expect( command.value ).to.equal( modelElement );
					command.refresh();
					expect( command.value ).to.be.false;
				} );
			} );
Ejemplo n.º 9
0
			it( `equals ${ modelElement } when collapsed selection is placed inside ${ modelElement } element`, () => {
				setData( model, `<${ modelElement }>foobar</${ modelElement }>` );
				const element = root.getChild( 0 );
				model.change( writer => {
					const ranges = [
						...model.document.selection.getRanges(),
						writer.createRange( writer.createPositionAt( element, 3 ) )
					];
					writer.setSelection( ranges );
				} );
				expect( command.value ).to.equal( modelElement );
			} );
Ejemplo n.º 10
0
				it( `converts ${ fromElement } to ${ toElement } on non-collapsed selection`, () => {
					setData(
						model,
						`<${ fromElement }>foo[bar</${ fromElement }><${ fromElement }>baz]qux</${ fromElement }>`
					);

					command.execute( { value: toElement } );

					expect( getData( model ) ).to.equal(
						`<${ toElement }>foo[bar</${ toElement }><${ toElement }>baz]qux</${ toElement }>`
					);
				} );
		it( 'should bind button to command', () => {
			const paragraphButton = editor.ui.componentFactory.create( 'paragraph' );
			const paragraphCommand = editor.commands.get( 'paragraph' );

			expect( paragraphCommand.isEnabled ).to.be.true;
			expect( paragraphButton.isEnabled ).to.be.true;

			paragraphCommand.isEnabled = false;
			expect( paragraphButton.isEnabled ).to.be.false;

			expect( paragraphCommand.value ).to.be.true;
			expect( paragraphButton.isOn ).to.be.true;

			setData( editor.model, '<heading2>f{}oo</heading2>' );

			expect( paragraphCommand.value ).to.be.false;
			expect( paragraphButton.isOn ).to.be.false;
		} );
Ejemplo n.º 12
0
		it( 'should not rename blocks which cannot become headings (block is an object)', () => {
			schema.register( 'image', {
				isBlock: true,
				isObject: true,
				allowIn: '$root'
			} );

			setData(
				model,
				'<paragraph>a[bc</paragraph>' +
				'<image></image>' +
				'<paragraph>de]f</paragraph>'
			);

			command.execute( { value: 'heading1' } );

			expect( getData( model ) ).to.equal(
				'<heading1>a[bc</heading1>' +
				'<image></image>' +
				'<heading1>de]f</heading1>'
			);
		} );
Ejemplo n.º 13
0
		it( 'should not rename blocks which cannot become headings (heading is not allowed in their parent)', () => {
			schema.register( 'restricted' );
			schema.extend( 'restricted', { allowIn: '$root' } );

			schema.register( 'fooBlock', { inheritAllFrom: '$block' } );
			schema.extend( 'fooBlock', {
				allowIn: [ 'restricted', '$root' ]
			} );

			setData(
				model,
				'<paragraph>a[bc</paragraph>' +
				'<restricted><fooBlock></fooBlock></restricted>' +
				'<fooBlock>de]f</fooBlock>'
			);

			command.execute( { value: 'heading1' } );

			expect( getData( model ) ).to.equal(
				'<heading1>a[bc</heading1>' +
				'<restricted><fooBlock></fooBlock></restricted>' +
				'<heading1>de]f</heading1>'
			);
		} );
Ejemplo n.º 14
0
				it( 'should be enabled when inside another block', () => {
					setData( model, '<paragraph>f{}oo</paragraph>' );

					expect( command.isEnabled ).to.be.true;
				} );
			it( 'should return false if there are no nodes in selection that can have the attribute', () => {
				setData( model, '<x>[foo]</x>' );
				expect( command.isEnabled ).to.be.false;
			} );
		it( 'is true when the first item that allows attribute has the attribute set #2', () => {
			setData( model, '<h1>fo[o</h1><p><$text bold="true">f</$text>o]o</p>' );

			expect( command.value ).to.be.true;
		} );
Ejemplo n.º 17
0
			it( 'should be false in a root which does not allow blocks at all', () => {
				doc.createRoot( 'paragraph', 'inlineOnlyRoot' );
				setData( model, 'a[]b', { rootName: 'inlineOnlyRoot' } );
				expect( command.isEnabled ).to.be.false;
			} );
			it( 'should return true if there is at least one node in selection that can have the attribute', () => {
				setData( model, '<p>[foo]</p>' );
				expect( command.isEnabled ).to.be.true;
			} );
Ejemplo n.º 19
0
			it( 'should be true if entire selection is in a block which can be turned into a list', () => {
				setData( model, '<paragraph>[a]</paragraph>' );
				expect( command.isEnabled ).to.be.true;
			} );
			it( 'should return false if characters with the attribute cannot be placed at caret position', () => {
				setData( model, '<x>fo[]o</x>' );
				expect( command.isEnabled ).to.be.false;
			} );
Ejemplo n.º 21
0
			it( 'should be true if selection first position is in a block which can be turned into a list', () => {
				setData( model, '<paragraph>[a</paragraph><widget>b]</widget>' );
				expect( command.isEnabled ).to.be.true;
			} );
Ejemplo n.º 22
0
			it( 'should be true if entire selection is in a list', () => {
				setData( model, '<listItem listType="bulleted" listIndent="0">[a]</listItem>' );
				expect( command.isEnabled ).to.be.true;
			} );
Ejemplo n.º 23
0
				it( 'should handle outdenting sub-items when list item is turned off', () => {
					/* eslint-disable max-len */
					// Taken from docs.
					//
					// 1  * --------
					// 2     * --------
					// 3        * -------- <- this is turned off.
					// 4           * -------- <- this has to become indent = 0, because it will be first item on a new list.
					// 5              * -------- <- this should be still be a child of item above, so indent = 1.
					// 6        * -------- <- this also has to become indent = 0, because it shouldn't end up as a child of any of items above.
					// 7           * -------- <- this should be still be a child of item above, so indent = 1.
					// 8     * -------- <- this has to become indent = 0.
					// 9        * -------- <- this should still be a child of item above, so indent = 1.
					// 10          * -------- <- this should still be a child of item above, so indent = 2.
					// 11          * -------- <- this should still be at the same level as item above, so indent = 2.
					// 12 * -------- <- this and all below are left unchanged.
					// 13    * --------
					// 14       * --------
					//
					// After turning off "3", the list becomes:
					//
					// 1  * --------
					// 2     * --------
					//
					// 3  --------
					//
					// 4  * --------
					// 5     * --------
					// 6  * --------
					// 7     * --------
					// 8  * --------
					// 9     * --------
					// 10       * --------
					// 11       * --------
					// 12 * --------
					// 13    * --------
					// 14       * --------
					/* eslint-enable max-len */

					setData(
						model,
						'<listItem listIndent="0" listType="bulleted">---</listItem>' +
						'<listItem listIndent="1" listType="bulleted">---</listItem>' +
						'<listItem listIndent="2" listType="bulleted">[]---</listItem>' +
						'<listItem listIndent="3" listType="bulleted">---</listItem>' +
						'<listItem listIndent="4" listType="bulleted">---</listItem>' +
						'<listItem listIndent="2" listType="bulleted">---</listItem>' +
						'<listItem listIndent="3" listType="bulleted">---</listItem>' +
						'<listItem listIndent="1" listType="bulleted">---</listItem>' +
						'<listItem listIndent="2" listType="bulleted">---</listItem>' +
						'<listItem listIndent="3" listType="bulleted">---</listItem>' +
						'<listItem listIndent="3" listType="bulleted">---</listItem>' +
						'<listItem listIndent="0" listType="bulleted">---</listItem>' +
						'<listItem listIndent="1" listType="bulleted">---</listItem>' +
						'<listItem listIndent="2" listType="bulleted">---</listItem>'
					);

					command.execute();

					const expectedData =
						'<listItem listIndent="0" listType="bulleted">---</listItem>' +
						'<listItem listIndent="1" listType="bulleted">---</listItem>' +
						'<paragraph listIndent="2" listType="bulleted">[]---</paragraph>' + // Attributes will be removed by post fixer.
						'<listItem listIndent="0" listType="bulleted">---</listItem>' +
						'<listItem listIndent="1" listType="bulleted">---</listItem>' +
						'<listItem listIndent="0" listType="bulleted">---</listItem>' +
						'<listItem listIndent="1" listType="bulleted">---</listItem>' +
						'<listItem listIndent="0" listType="bulleted">---</listItem>' +
						'<listItem listIndent="1" listType="bulleted">---</listItem>' +
						'<listItem listIndent="2" listType="bulleted">---</listItem>' +
						'<listItem listIndent="2" listType="bulleted">---</listItem>' +
						'<listItem listIndent="0" listType="bulleted">---</listItem>' +
						'<listItem listIndent="1" listType="bulleted">---</listItem>' +
						'<listItem listIndent="2" listType="bulleted">---</listItem>';

					expect( getData( model ) ).to.equal( expectedData );
				} );
Ejemplo n.º 24
0
				it( 'should be disabled if inside non-block', () => {
					setData( model, '<notBlock>f{}oo</notBlock>' );

					expect( command.isEnabled ).to.be.false;
				} );
Ejemplo n.º 25
0
				it( 'should be disabled if selection is placed on non-block', () => {
					setData( model, '[<notBlock>foo</notBlock>]' );

					expect( command.isEnabled ).to.be.false;
				} );
Ejemplo n.º 26
0
			it( 'does nothing when executed with already applied option', () => {
				setData( model, '<heading1>foo[]bar</heading1>' );

				command.execute( { value: 'heading1' } );
				expect( getData( model ) ).to.equal( '<heading1>foo[]bar</heading1>' );
			} );
Ejemplo n.º 27
0
			it( 'equals false if inside to non-block element', () => {
				setData( model, '<notBlock>[foo]</notBlock>' );

				expect( command.value ).to.be.false;
			} );
		it( 'is false when the first item that allows attribute does not have the attribute set #2', () => {
			setData( model, '<h1>fo[o</h1><p>b<$text bold="true">r</$text>r]</p>' );

			expect( command.value ).to.be.false;
		} );
Ejemplo n.º 29
0
				it( `converts ${ from.model } to ${ to.model } on collapsed selection`, () => {
					setData( model, `<${ from.model }>foo[]bar</${ from.model }>` );
					command.execute( { value: to.model } );

					expect( getData( model ) ).to.equal( `<${ to.model }>foo[]bar</${ to.model }>` );
				} );
Ejemplo n.º 30
0
			it( 'should be false if selection first position is in an element which cannot be converted to a list item', () => {
				setData( model, '<widget><paragraph>[a</paragraph></widget><paragraph>b]</paragraph>' );
				expect( command.isEnabled ).to.be.false;
			} );