1
1
import { DocumentEditor } from '../../src/document-editor/document-editor' ;
2
2
import { createElement } from '@syncfusion/ej2-base' ;
3
- import { Editor } from '../../src/index' ;
3
+ import { ContentControlInfo , Editor } from '../../src/index' ;
4
4
import { TestHelper } from '../test-helper.spec' ;
5
5
import { Selection } from '../../src/index' ;
6
6
import { EditorHistory } from '../../src/document-editor/implementation/editor-history/editor-history' ;
@@ -108,7 +108,7 @@ describe('check apply content control', () => {
108
108
editor . editorModule . insertContentControl ( 'CheckBox' ) ;
109
109
editor . selection . handleLeftKey ( ) ;
110
110
expect ( editor . documentHelper . contentControlCollection [ 0 ] . contentControlProperties . isChecked ) . toBe ( false ) ;
111
- editor . editorModule . toggleContentControlCheckBox ( editor . documentHelper . contentControlCollection [ 0 ] ) ;
111
+ editor . editorModule . toggleContentControlCheckBox ( editor . documentHelper . contentControlCollection [ 0 ] , ! editor . documentHelper . contentControlCollection [ 0 ] . contentControlProperties . isChecked ) ;
112
112
expect ( editor . documentHelper . contentControlCollection [ 0 ] . contentControlProperties . isChecked ) . toBe ( true ) ;
113
113
} ) ;
114
114
it ( 'validate text insertion after content control' , ( ) => {
@@ -120,4 +120,89 @@ describe('check apply content control', () => {
120
120
editor . editor . insertText ( "Text after CC" ) ;
121
121
expect ( editor . selection . start . currentWidget . children . length > count ) . toBe ( true ) ;
122
122
} )
123
- } ) ;
123
+ } ) ;
124
+
125
+ describe ( 'Validate getContentControinfo' , ( ) => {
126
+ let editor : DocumentEditor ;
127
+ beforeAll ( ( ) : void => {
128
+ let ele : HTMLElement = createElement ( 'div' , { id : 'container' } ) ;
129
+ document . body . appendChild ( ele ) ;
130
+ editor = new DocumentEditor ( { enableEditor : true , isReadOnly : false } ) ;
131
+ DocumentEditor . Inject ( Editor , Selection , EditorHistory ) ; editor . enableEditorHistory = true ;
132
+ ( editor . documentHelper as any ) . containerCanvasIn = TestHelper . containerCanvas ;
133
+ ( editor . documentHelper as any ) . selectionCanvasIn = TestHelper . selectionCanvas ;
134
+ ( editor . documentHelper . render as any ) . pageCanvasIn = TestHelper . pageCanvas ;
135
+ ( editor . documentHelper . render as any ) . selectionCanvasIn = TestHelper . pageSelectionCanvas ;
136
+ editor . appendTo ( '#container' ) ;
137
+ } ) ;
138
+ afterAll ( ( done ) : void => {
139
+ editor . destroy ( ) ;
140
+ document . body . removeChild ( document . getElementById ( 'container' ) ) ;
141
+ editor = undefined ;
142
+ setTimeout ( function ( ) {
143
+ document . body . innerHTML = '' ;
144
+ done ( ) ;
145
+ } , 1000 ) ;
146
+ } ) ;
147
+ it ( 'apply plain text content control' , ( ) => {
148
+ console . log ( 'apply plain text content control' ) ;
149
+ editor . openBlank ( ) ;
150
+ editor . editorModule . insertText ( 'Insering the plain text content control and using using getContentControlInfo method' ) ;
151
+ editor . selection . selectAll ( ) ;
152
+ editor . editorModule . insertContentControl ( 'Text' ) ;
153
+ editor . selection . select ( '0;0;10' , '0;0;10' ) ;
154
+ let contentControlInfo : ContentControlInfo = editor . selectionModule . getContentControlInfo ( ) ;
155
+ expect ( contentControlInfo . value ) . toBe ( 'Insering the plain text content control and using using getContentControlInfo method' ) ;
156
+ expect ( contentControlInfo . type ) . toBe ( 'Text' ) ;
157
+ contentControlInfo . value = contentControlInfo . value + ' added new text' ;
158
+ editor . importContentControlData ( [ contentControlInfo ] ) ;
159
+ editor . selection . select ( '0;0;10' , '0;0;10' ) ;
160
+ contentControlInfo = editor . selectionModule . getContentControlInfo ( ) ;
161
+ expect ( contentControlInfo . value ) . toBe ( 'Insering the plain text content control and using using getContentControlInfo method added new text' ) ;
162
+ } ) ;
163
+ it ( 'apply combo box content control' , ( ) => {
164
+ console . log ( 'apply combo box content control' ) ;
165
+ editor . openBlank ( ) ;
166
+ editor . editorModule . insertText ( 'sample' ) ;
167
+ editor . selection . selectAll ( ) ;
168
+ editor . editorModule . insertContentControl ( 'ComboBox' ) ;
169
+ editor . selection . select ( '0;0;5' , '0;0;5' ) ;
170
+ let contentControlInfo : ContentControlInfo = editor . selectionModule . getContentControlInfo ( ) ;
171
+ expect ( contentControlInfo . value ) . toBe ( 'sample' ) ;
172
+ expect ( contentControlInfo . type ) . toBe ( 'ComboBox' ) ;
173
+ contentControlInfo . value = 'new value' ;
174
+ editor . importContentControlData ( [ contentControlInfo ] ) ;
175
+ editor . selection . select ( '0;0;5' , '0;0;5' ) ;
176
+ contentControlInfo = editor . selectionModule . getContentControlInfo ( ) ;
177
+ expect ( contentControlInfo . value ) . toBe ( 'new value' ) ;
178
+ } ) ;
179
+ it ( 'apply check box content control' , ( ) => {
180
+ console . log ( 'apply check box content control' ) ;
181
+ editor . openBlank ( ) ;
182
+ editor . editorModule . insertContentControl ( 'CheckBox' ) ;
183
+ editor . selection . select ( '0;0;1' , '0;0;1' ) ;
184
+ let contentControlInfo : ContentControlInfo = editor . selectionModule . getContentControlInfo ( ) ;
185
+ expect ( contentControlInfo . value ) . toBe ( 'false' ) ;
186
+ expect ( contentControlInfo . type ) . toBe ( 'CheckBox' ) ;
187
+ contentControlInfo . value = 'true' ;
188
+ editor . importContentControlData ( [ contentControlInfo ] ) ;
189
+ editor . selection . select ( '0;0;1' , '0;0;1' ) ;
190
+ contentControlInfo = editor . selectionModule . getContentControlInfo ( ) ;
191
+ expect ( contentControlInfo . value ) . toBe ( 'true' ) ;
192
+ } ) ;
193
+ it ( 'apply date picker content control' , ( ) => {
194
+ console . log ( 'apply date picker content control' ) ;
195
+ editor . openBlank ( ) ;
196
+ editor . editorModule . insertContentControl ( 'Date' , '5/12/24' ) ;
197
+ editor . selection . select ( '0;0;3' , '0;0;3' ) ;
198
+ let contentControlInfo : ContentControlInfo = editor . selectionModule . getContentControlInfo ( ) ;
199
+ expect ( contentControlInfo . value ) . toBe ( '5/12/24' ) ;
200
+ expect ( contentControlInfo . type ) . toBe ( 'Date' ) ;
201
+ contentControlInfo . value = '6/12/24' ;
202
+ editor . importContentControlData ( [ contentControlInfo ] ) ;
203
+ editor . selection . select ( '0;0;3' , '0;0;3' ) ;
204
+ contentControlInfo = editor . selectionModule . getContentControlInfo ( ) ;
205
+ expect ( contentControlInfo . value ) . toBe ( '6/12/24' ) ;
206
+ } ) ;
207
+
208
+ } ) ;
0 commit comments