@@ -134,54 +134,39 @@ Cypress.Commands.add("drupalWatchdogHasNewErrors", (username, count) => {
134
134
} ) ;
135
135
136
136
Cypress . Commands . add ( "iframe" , { prevSubject : "element" } , ( $iframe ) => {
137
- cy . get ( $iframe ) . scrollIntoView ( ) ;
138
- cy . get ( $iframe )
139
- . its ( "0.contentDocument" )
140
- . should ( "not.be.empty" )
141
- . its ( "body" )
142
- . as ( "body" ) ;
143
- cy . get ( "@body" ) . should ( "be.visible" ) . should ( "not.be.empty" ) . then ( cy . wrap ) ;
137
+ return cy
138
+ . wrap ( $iframe )
139
+ . should ( ( iframe ) => expect ( iframe . contents ( ) . find ( "body" ) ) . to . exist )
140
+ . then ( ( iframe ) => cy . wrap ( iframe . contents ( ) . find ( "body" ) ) ) ;
144
141
} ) ;
145
142
146
- Cypress . Commands . add ( "type_ckeditor" , ( element , content ) => {
147
- cy . window ( ) . then ( ( win ) => {
143
+ Cypress . Commands . add ( "get_ckeditor" , ( element ) => {
144
+ cy . wait ( 5000 ) ;
145
+ return cy . window ( ) . then ( ( win ) => {
148
146
const elements = Object . keys ( win . CKEDITOR . instances ) ;
149
- if ( elements . indexOf ( element ) === - 1 ) {
147
+ const index = elements . indexOf ( element ) ;
148
+ if ( index === - 1 ) {
150
149
const matches = elements . filter ( ( el ) => el . includes ( element ) ) ;
151
150
if ( matches . length ) {
152
151
// eslint-disable-next-line prefer-destructuring
153
152
element = matches [ 0 ] ;
153
+ } else {
154
+ throw new Error ( `CKEditor instance not found: ${ element } ` ) ;
154
155
}
155
156
}
156
- cy . wait ( 2000 ) ;
157
- cy . get ( `#${ element } ` )
158
- . parent ( )
159
- . find ( "iframe" )
160
- . iframe ( )
161
- . then ( ( ) => {
162
- win . CKEDITOR . instances [ element ] . setData ( content ) ;
163
- } ) ;
157
+ return cy . wrap ( win . CKEDITOR . instances [ element ] ) ;
158
+ } ) ;
159
+ } ) ;
160
+
161
+ Cypress . Commands . add ( "type_ckeditor" , ( element , content ) => {
162
+ return cy . get_ckeditor ( element ) . then ( ( editor ) => {
163
+ return cy . wrap ( editor . setData ( content ) ) ;
164
164
} ) ;
165
165
} ) ;
166
166
167
167
Cypress . Commands . add ( "read_ckeditor" , ( element ) => {
168
- return cy . window ( ) . then ( ( win ) => {
169
- const elements = Object . keys ( win . CKEDITOR . instances ) ;
170
- if ( elements . indexOf ( element ) === - 1 ) {
171
- const matches = elements . filter ( ( el ) => el . includes ( element ) ) ;
172
- if ( matches . length ) {
173
- [ element ] = matches ;
174
- }
175
- }
176
- cy . wait ( 2000 ) ;
177
- return cy
178
- . get ( `#${ element } ` )
179
- . parent ( )
180
- . find ( "iframe" )
181
- . iframe ( )
182
- . then ( ( ) => {
183
- return cy . wrap ( win . CKEDITOR . instances [ element ] . getData ( ) ) ;
184
- } ) ;
168
+ return cy . get_ckeditor ( element ) . then ( ( editor ) => {
169
+ return cy . wrap ( editor . getData ( ) ) ;
185
170
} ) ;
186
171
} ) ;
187
172
0 commit comments