@@ -3,115 +3,118 @@ import { RTEPlugin } from "..";
33import React from "react" ;
44
55const createDropdown = ( ) => {
6- const DropDown = new RTEPlugin ( ' Parent' , ( ) => {
7- return ( {
8- title : ' Dropdown' ,
9- icon : React . createElement ( 'p' )
10- } )
6+ const DropDown = new RTEPlugin ( " Parent" , ( ) => {
7+ return {
8+ title : " Dropdown" ,
9+ icon : React . createElement ( "p" ) ,
10+ } ;
1111 } ) ;
12- const Child = new RTEPlugin ( ' Child' , ( ) => {
13- return ( {
14- title : ' Child' ,
15- icon : React . createElement ( ' span' )
16- } )
12+ const Child = new RTEPlugin ( " Child" , ( ) => {
13+ return {
14+ title : " Child" ,
15+ icon : React . createElement ( " span" ) ,
16+ } ;
1717 } ) ;
1818 DropDown . addPlugins ( Child ) ;
1919 return DropDown ;
20- }
20+ } ;
2121
2222const createPlugin = ( ) => {
23- const detail :any = {
24- id : ' plugin' ,
25- title : ' Plugin' ,
26- icon : React . createElement ( ' span' ) ,
23+ const detail : any = {
24+ id : " plugin" ,
25+ title : " Plugin" ,
26+ icon : React . createElement ( " span" ) ,
2727 render : ( props ) => {
28- return React . createElement ( ' div' , { } , props . children ) ;
28+ return React . createElement ( " div" , { } , props . children ) ;
2929 } ,
30- display : [ ' hoveringToolbar' , ' toolbar' ] ,
31- elementType : [ ' inline' , ' void' , ' block' , ' text' ]
30+ display : [ " hoveringToolbar" , " toolbar" ] ,
31+ elementType : [ " inline" , " void" , " block" , " text" ] ,
3232 } ;
3333 const Plugin = new RTEPlugin ( detail . id , ( ) => {
3434 return detail ;
3535 } ) ;
3636 return [ Plugin , detail ] ;
37- }
37+ } ;
3838
39- const stringify = ( j :any ) :string => JSON . stringify ( Object ( j ) ) ;
39+ const stringify = ( j : any ) : string => JSON . stringify ( Object ( j ) ) ;
4040
41- describe ( ' RTE Plugin' , ( ) => {
42- it ( ' Contains all RTE Callback properties in get' , ( ) => {
41+ describe ( " RTE Plugin" , ( ) => {
42+ it ( " Contains all RTE Callback properties in get" , async ( ) => {
4343 const [ plugin , inputPluginProps ] = createPlugin ( ) ;
44- const pluginProps = plugin . get ( ) ;
44+ const pluginProps = await plugin . get ( ) ;
4545 const registry = pluginProps . registry ;
46+ console . log ( "mayhem " , createPlugin ( ) , {
47+ pluginProps,
48+ } ) ;
4649 const basicDetails = {
4750 title : inputPluginProps . title ,
4851 toolbar : {
49- " inHoveringToolbar" : true ,
50- " inMainToolbar" : true
52+ inHoveringToolbar : true ,
53+ inMainToolbar : true ,
5154 } ,
5255 iconName : inputPluginProps . icon ,
5356 meta : {
54- 'id' : inputPluginProps . id ,
57+ id : inputPluginProps . id ,
5558 elementType : inputPluginProps . elementType ,
5659 editorCallbacks : { } ,
57- isDependent : false
58- }
60+ isDependent : false ,
61+ } ,
5962 } ;
60- expect ( stringify ( basicDetails ) ) . to . equal ( stringify ( {
61- title : registry . title ,
62- toolbar : registry . toolbar ,
63- iconName : registry . iconName ,
64- meta : pluginProps . meta
65- } ) ) ;
66- } )
63+ expect ( stringify ( basicDetails ) ) . to . equal (
64+ stringify ( {
65+ title : registry . title ,
66+ toolbar : registry . toolbar ,
67+ iconName : registry . iconName ,
68+ meta : pluginProps . meta ,
69+ } )
70+ ) ;
71+ } ) ;
6772
68- it ( ' Check editor callbacks are getting applied' , ( ) => {
73+ it ( " Check editor callbacks are getting applied" , async ( ) => {
6974 const [ plugin , details ] = createPlugin ( ) ;
7075 const fnc = jest . fn ( ( ) => { } ) ;
7176 const events = [
72- ' keydown' ,
73- ' paste' ,
74- ' deleteBackward' ,
75- ' deleteForward' ,
76- ' insertBreak' ,
77- ' normalize'
77+ " keydown" ,
78+ " paste" ,
79+ " deleteBackward" ,
80+ " deleteForward" ,
81+ " insertBreak" ,
82+ " normalize" ,
7883 ] ;
79- events . forEach ( event => plugin . on ( event , fnc ) ) ;
80- const callbacks = plugin . get ( ) . meta . editorCallbacks ;
84+ events . forEach ( ( event ) => plugin . on ( event , fnc ) ) ;
85+ const callbacks = ( await plugin . get ( ) ) . meta . editorCallbacks ;
8186 expect ( Object . keys ( callbacks ) . length ) . to . eq ( events . length ) ;
82- expect ( events . every ( event => callbacks [ event ] === fnc ) ) . to . be . true ;
83- Object . values ( callbacks ) . forEach ( ( callback :any ) => callback ( ) ) ;
87+ expect ( events . every ( ( event ) => callbacks [ event ] === fnc ) ) . to . be . true ;
88+ Object . values ( callbacks ) . forEach ( ( callback : any ) => callback ( ) ) ;
8489 expect ( fnc . mock . calls . length ) . to . eq ( events . length ) ;
85- } )
90+ } ) ;
8691
87- it ( ' Check if callbacks under register is registered under plugin' , async ( ) => {
92+ it ( " Check if callbacks under register is registered under plugin" , async ( ) => {
8893 const [ plugin , details ] = createPlugin ( ) ;
8994 const fnc = jest . fn ( ( ) => { } ) ;
90- const events = [
91- 'exec' ,
92- 'beforeRender' ,
93- 'beforeChildRender'
94- ] ;
95+ const events = [ "exec" , "beforeRender" , "beforeChildRender" ] ;
9596 const callbackEventName = [
96- ' handleMouseDown' ,
97- ' beforeElementRender' ,
98- ' beforeChildrenRender'
99- ]
100- events . forEach ( event => plugin . on ( event , fnc ) ) ;
101- const registry = plugin . get ( ) . registry ;
102- expect ( callbackEventName . every ( event => registry [ event ] ) ) . to . be . true ;
103- callbackEventName . forEach ( event => registry [ event ] ( ) ) ;
97+ " handleMouseDown" ,
98+ " beforeElementRender" ,
99+ " beforeChildrenRender" ,
100+ ] ;
101+ events . forEach ( ( event ) => plugin . on ( event , fnc ) ) ;
102+ const registry = ( await plugin . get ( ) ) . registry ;
103+ expect ( callbackEventName . every ( ( event ) => registry [ event ] ) ) . to . be . true ;
104+ callbackEventName . forEach ( ( event ) => registry [ event ] ( ) ) ;
104105 expect ( fnc . mock . calls . length ) . to . eq ( callbackEventName . length ) ;
105- } )
106+ } ) ;
106107
107- it ( ' Dropdown get() has icon' , async ( ) => {
108+ it ( " Dropdown get() has icon" , async ( ) => {
108109 const dropdown = await createDropdown ( ) . get ( ) ;
109- expect ( dropdown . registry ) . to . have . property ( 'iconName' ) ;
110- expect ( stringify ( dropdown . registry . iconName ) ) . to . equal ( stringify ( React . createElement ( 'p' ) ) ) ;
110+ expect ( dropdown . registry ) . to . have . property ( "iconName" ) ;
111+ expect ( stringify ( dropdown . registry . iconName ) ) . to . equal (
112+ stringify ( React . createElement ( "p" ) )
113+ ) ;
111114 } ) ;
112-
113- it ( ' Dropdown get() has dependent plugin' , async ( ) => {
114- const dropdown :any = await createDropdown ( ) . get ( ) ;
115+
116+ it ( " Dropdown get() has dependent plugin" , async ( ) => {
117+ const dropdown : any = await createDropdown ( ) . get ( ) ;
115118 expect ( dropdown . meta . dependentPlugins ) . to . have . length ( 1 ) ;
116- } )
117- } )
119+ } ) ;
120+ } ) ;
0 commit comments