@@ -167,4 +167,49 @@ suite('Comments', function () {
167167 assertBubbleLocation ( this . comment , 100 , 100 ) ;
168168 } ) ;
169169 } ) ;
170+ suite ( 'Undo/Redo' , function ( ) {
171+ test ( 'Adding an empty comment can be undone' , function ( ) {
172+ const block = this . workspace . newBlock ( 'empty_block' ) ;
173+ block . setCommentText ( '' ) ;
174+ assert . isNotNull ( block . getIcon ( Blockly . icons . IconType . COMMENT ) ) ;
175+ assert . equal ( block . getCommentText ( ) , '' ) ;
176+
177+ this . workspace . undo ( false ) ;
178+
179+ assert . isUndefined ( block . getIcon ( Blockly . icons . IconType . COMMENT ) ) ;
180+ assert . isNull ( block . getCommentText ( ) ) ;
181+ } ) ;
182+
183+ test ( 'Adding an empty comment can be redone' , function ( ) {
184+ const block = this . workspace . newBlock ( 'empty_block' ) ;
185+ block . setCommentText ( '' ) ;
186+ this . workspace . undo ( false ) ;
187+ this . workspace . undo ( true ) ;
188+
189+ assert . isNotNull ( block . getIcon ( Blockly . icons . IconType . COMMENT ) ) ;
190+ assert . equal ( block . getCommentText ( ) , '' ) ;
191+ } ) ;
192+
193+ test ( 'Adding a non-empty comment can be undone' , function ( ) {
194+ const block = this . workspace . newBlock ( 'empty_block' ) ;
195+ block . setCommentText ( 'hey there' ) ;
196+ assert . isNotNull ( block . getIcon ( Blockly . icons . IconType . COMMENT ) ) ;
197+ assert . equal ( block . getCommentText ( ) , 'hey there' ) ;
198+
199+ this . workspace . undo ( false ) ;
200+
201+ assert . isUndefined ( block . getIcon ( Blockly . icons . IconType . COMMENT ) ) ;
202+ assert . isNull ( block . getCommentText ( ) ) ;
203+ } ) ;
204+
205+ test ( 'Adding a non-empty comment can be redone' , function ( ) {
206+ const block = this . workspace . newBlock ( 'empty_block' ) ;
207+ block . setCommentText ( 'hey there' ) ;
208+ this . workspace . undo ( false ) ;
209+ this . workspace . undo ( true ) ;
210+
211+ assert . isNotNull ( block . getIcon ( Blockly . icons . IconType . COMMENT ) ) ;
212+ assert . equal ( block . getCommentText ( ) , 'hey there' ) ;
213+ } ) ;
214+ } ) ;
170215} ) ;
0 commit comments