| 
									
										
										
										
											2025-05-04 22:50:18 +03:00
										 |  |  | import { ClassicEditor, type EditorConfig } from 'ckeditor5'; | 
					
						
							| 
									
										
										
										
											2024-09-11 21:04:41 +03:00
										 |  |  | import MathUI from '../src/mathui'; | 
					
						
							| 
									
										
										
										
											2025-05-10 00:01:38 +03:00
										 |  |  | import { describe, beforeEach, it, afterEach, expect } from "vitest"; | 
					
						
							| 
									
										
										
										
											2024-09-11 21:04:41 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe( 'Lazy load', () => { | 
					
						
							|  |  |  | 	let editorElement: HTMLDivElement; | 
					
						
							|  |  |  | 	let editor: ClassicEditor; | 
					
						
							|  |  |  | 	let lazyLoadInvoked: boolean; | 
					
						
							|  |  |  | 	let mathUIFeature: MathUI; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	function buildEditor( config: EditorConfig ) { | 
					
						
							|  |  |  | 		return ClassicEditor | 
					
						
							|  |  |  | 			.create( editorElement, { | 
					
						
							|  |  |  | 				...config, | 
					
						
							| 
									
										
										
										
											2025-05-09 22:16:12 +03:00
										 |  |  | 				licenseKey: "GPL", | 
					
						
							| 
									
										
										
										
											2024-09-11 21:04:41 +03:00
										 |  |  | 				plugins: [ MathUI ] | 
					
						
							|  |  |  | 			} ) | 
					
						
							|  |  |  | 			.then( newEditor => { | 
					
						
							|  |  |  | 				editor = newEditor; | 
					
						
							|  |  |  | 				mathUIFeature = editor.plugins.get( MathUI ); | 
					
						
							|  |  |  | 			} ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	beforeEach( () => { | 
					
						
							|  |  |  | 		editorElement = document.createElement( 'div' ); | 
					
						
							|  |  |  | 		document.body.appendChild( editorElement ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		lazyLoadInvoked = false; | 
					
						
							|  |  |  | 	} ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	afterEach( () => { | 
					
						
							|  |  |  | 		editorElement.remove(); | 
					
						
							|  |  |  | 		return editor.destroy(); | 
					
						
							|  |  |  | 	} ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	it( 'initializes lazy load for KaTeX', async () => { | 
					
						
							|  |  |  | 		await buildEditor( { | 
					
						
							|  |  |  | 			math: { | 
					
						
							|  |  |  | 				engine: 'katex', | 
					
						
							|  |  |  | 				lazyLoad: async () => { | 
					
						
							|  |  |  | 					lazyLoadInvoked = true; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		mathUIFeature._showUI(); | 
					
						
							|  |  |  | 		expect( lazyLoadInvoked ).to.be.true; | 
					
						
							|  |  |  | 	} ); | 
					
						
							|  |  |  | } ); |