mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	Fix automath tests
This commit is contained in:
		| @@ -46,7 +46,7 @@ | |||||||
|   "scripts": { |   "scripts": { | ||||||
|     "lint": "eslint --quiet **/*.js", |     "lint": "eslint --quiet **/*.js", | ||||||
|     "lint:fix": "eslint --quiet **/*.js --fix", |     "lint:fix": "eslint --quiet **/*.js --fix", | ||||||
|     "test": "node ./node_modules/.bin/ckeditor5-dev-tests" |     "test": "node node_modules/@ckeditor/ckeditor5-dev-tests/bin/test.js" | ||||||
|   }, |   }, | ||||||
|   "lint-staged": { |   "lint-staged": { | ||||||
|     "**/*.js": [ |     "**/*.js": [ | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ import LiveRange from '@ckeditor/ckeditor5-engine/src/model/liverange'; | |||||||
| import LivePosition from '@ckeditor/ckeditor5-engine/src/model/liveposition'; | import LivePosition from '@ckeditor/ckeditor5-engine/src/model/liveposition'; | ||||||
| import global from '@ckeditor/ckeditor5-utils/src/dom/global'; | import global from '@ckeditor/ckeditor5-utils/src/dom/global'; | ||||||
|  |  | ||||||
| import { defaultConfig, extractDelimiters, hasDelimiters } from './utils'; | import { defaultConfig, extractDelimiters, hasDelimiters, delimitersCounts } from './utils'; | ||||||
|  |  | ||||||
| export default class AutoMath extends Plugin { | export default class AutoMath extends Plugin { | ||||||
| 	static get requires() { | 	static get requires() { | ||||||
| @@ -76,7 +76,7 @@ export default class AutoMath extends Plugin { | |||||||
| 		text = text.trim(); | 		text = text.trim(); | ||||||
|  |  | ||||||
| 		// Skip if don't have delimiters | 		// Skip if don't have delimiters | ||||||
| 		if ( !hasDelimiters( text ) ) { | 		if ( !hasDelimiters( text ) || delimitersCounts( text ) !== 2 ) { | ||||||
| 			return; | 			return; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -29,6 +29,11 @@ export function hasDelimiters( text ) { | |||||||
| 	return text.match( /^(\\\[.*?\\\]|\\\(.*?\\\))$/ ); | 	return text.match( /^(\\\[.*?\\\]|\\\(.*?\\\))$/ ); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // Find delimiters count | ||||||
|  | export function delimitersCounts( text ) { | ||||||
|  | 	return text.match( /(\\\[|\\\]|\\\(|\\\))/g ).length; | ||||||
|  | } | ||||||
|  |  | ||||||
| // Extract delimiters and figure display mode for the model | // Extract delimiters and figure display mode for the model | ||||||
| export function extractDelimiters( equation ) { | export function extractDelimiters( equation ) { | ||||||
| 	equation = equation.trim(); | 	equation = equation.trim(); | ||||||
|   | |||||||
| @@ -2,6 +2,7 @@ import Mathematics from '../src/math'; | |||||||
| import AutoMath from '../src/automath'; | import AutoMath from '../src/automath'; | ||||||
| import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor'; | import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor'; | ||||||
| import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard'; | import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard'; | ||||||
|  | import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'; | ||||||
| import Undo from '@ckeditor/ckeditor5-undo/src/undo'; | import Undo from '@ckeditor/ckeditor5-undo/src/undo'; | ||||||
| import Typing from '@ckeditor/ckeditor5-typing/src/typing'; | import Typing from '@ckeditor/ckeditor5-typing/src/typing'; | ||||||
| import global from '@ckeditor/ckeditor5-utils/src/dom/global'; | import global from '@ckeditor/ckeditor5-utils/src/dom/global'; | ||||||
| @@ -16,7 +17,7 @@ describe( 'AutoMath - integration', () => { | |||||||
|  |  | ||||||
| 		return ClassicTestEditor | 		return ClassicTestEditor | ||||||
| 			.create( editorElement, { | 			.create( editorElement, { | ||||||
| 				plugins: [ Mathematics, AutoMath, Typing ] | 				plugins: [ Mathematics, AutoMath, Typing, Paragraph ] | ||||||
| 			} ) | 			} ) | ||||||
| 			.then( newEditor => { | 			.then( newEditor => { | ||||||
| 				editor = newEditor; | 				editor = newEditor; | ||||||
| @@ -63,7 +64,7 @@ describe( 'AutoMath - integration', () => { | |||||||
| 			clock.tick( 100 ); | 			clock.tick( 100 ); | ||||||
|  |  | ||||||
| 			expect( getData( editor.model ) ).to.equal( | 			expect( getData( editor.model ) ).to.equal( | ||||||
| 				'[<mathtex equation="x^2" display="true"></mathtex>]' | 				'<paragraph>[<mathtex display="true" equation="x^2" type="script"></mathtex>]</paragraph>' | ||||||
| 			); | 			); | ||||||
| 		} ); | 		} ); | ||||||
|  |  | ||||||
| @@ -78,7 +79,7 @@ describe( 'AutoMath - integration', () => { | |||||||
| 			clock.tick( 100 ); | 			clock.tick( 100 ); | ||||||
|  |  | ||||||
| 			expect( getData( editor.model ) ).to.equal( | 			expect( getData( editor.model ) ).to.equal( | ||||||
| 				'[<mathtex equation="x^2" display="false"></mathtex>]' | 				'<paragraph>[<mathtex display="false" equation="x^2" type="script"></mathtex>]</paragraph>' | ||||||
| 			); | 			); | ||||||
| 		} ); | 		} ); | ||||||
|  |  | ||||||
| @@ -106,7 +107,7 @@ describe( 'AutoMath - integration', () => { | |||||||
| 			clock.tick( 100 ); | 			clock.tick( 100 ); | ||||||
|  |  | ||||||
| 			expect( getData( editor.model ) ).to.equal( | 			expect( getData( editor.model ) ).to.equal( | ||||||
| 				'[<mathtex equation="x^2"" display="true"></mathtex>]' | 				'<paragraph>[<mathtex display="true" equation="x^2" type="script"></mathtex>]</paragraph>' | ||||||
| 			); | 			); | ||||||
| 		} ); | 		} ); | ||||||
|  |  | ||||||
| @@ -117,7 +118,7 @@ describe( 'AutoMath - integration', () => { | |||||||
| 			clock.tick( 100 ); | 			clock.tick( 100 ); | ||||||
|  |  | ||||||
| 			expect( getData( editor.model ) ).to.equal( | 			expect( getData( editor.model ) ).to.equal( | ||||||
| 				'<paragraph>Fo</paragraph>[<mathtex equation="x^2" display="true"></mathtex>]<paragraph>r</paragraph>' | 				'<paragraph>Fo[<mathtex display="true" equation="x^2" type="script"></mathtex>]r</paragraph>' | ||||||
| 			); | 			); | ||||||
| 		} ); | 		} ); | ||||||
|  |  | ||||||
| @@ -128,22 +129,22 @@ describe( 'AutoMath - integration', () => { | |||||||
| 			clock.tick( 100 ); | 			clock.tick( 100 ); | ||||||
|  |  | ||||||
| 			expect( getData( editor.model ) ).to.equal( | 			expect( getData( editor.model ) ).to.equal( | ||||||
| 				'<paragraph>Foo </paragraph>' + | 				'<paragraph>Foo ' + | ||||||
| 				'[<mathtex equation="x^2" display="true"></mathtex>]' + | 				'[<mathtex display="true" equation="x^2" type="script"></mathtex>]' + | ||||||
| 				'<paragraph>Bar</paragraph>' | 				'Bar</paragraph>' | ||||||
| 			); | 			); | ||||||
| 		} ); | 		} ); | ||||||
|  |  | ||||||
| 		it( 'inserts media in-place (non-collapsed selection)', () => { | 		it( 'inserts math in-place (non-collapsed selection)', () => { | ||||||
| 			setData( editor.model, '<paragraph>Foo [Bar] Baz</paragraph>' ); | 			setData( editor.model, '<paragraph>Foo [Bar] Baz</paragraph>' ); | ||||||
| 			pasteHtml( editor, '\\[x^2\\]' ); | 			pasteHtml( editor, '\\[x^2\\]' ); | ||||||
|  |  | ||||||
| 			clock.tick( 100 ); | 			clock.tick( 100 ); | ||||||
|  |  | ||||||
| 			expect( getData( editor.model ) ).to.equal( | 			expect( getData( editor.model ) ).to.equal( | ||||||
| 				'<paragraph>Foo </paragraph>' + | 				'<paragraph>Foo ' + | ||||||
| 				'[<mathtex equation="x^2" display="true"></mathtex>]' + | 				'[<mathtex display="true" equation="x^2" type="script"></mathtex>]' + | ||||||
| 				'<paragraph> Baz</paragraph>' | 				' Baz</paragraph>' | ||||||
| 			); | 			); | ||||||
| 		} ); | 		} ); | ||||||
|  |  | ||||||
| @@ -154,7 +155,7 @@ describe( 'AutoMath - integration', () => { | |||||||
| 			clock.tick( 100 ); | 			clock.tick( 100 ); | ||||||
|  |  | ||||||
| 			expect( getData( editor.model ) ).to.equal( | 			expect( getData( editor.model ) ).to.equal( | ||||||
| 				'\\[x^2\\] \\[\\sqrt{x}2\\]' | 				'<paragraph>\\[x^2\\] \\[\\sqrt{x}2\\][]</paragraph>' | ||||||
| 			); | 			); | ||||||
| 		} ); | 		} ); | ||||||
| 	} ); | 	} ); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user