From 5b1a0ae284b317998c7eecd898649983a831fb84 Mon Sep 17 00:00:00 2001 From: marisaleung Date: Fri, 9 Jun 2017 15:53:35 -0700 Subject: [PATCH] Test Delete Variable Twice. --- tests/jsunit/workspace_undo_redo_test.js | 59 +++++++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/tests/jsunit/workspace_undo_redo_test.js b/tests/jsunit/workspace_undo_redo_test.js index d8f116caf..33dc855d7 100644 --- a/tests/jsunit/workspace_undo_redo_test.js +++ b/tests/jsunit/workspace_undo_redo_test.js @@ -166,7 +166,7 @@ function test_undoDeleteVariable_WithBlocks() { undoRedoTest_tearDown(); } -function test_redoAndUndoDeleteVariable() { +function test_redoAndUndoDeleteVariable_NoBlocks() { undoRedoTest_setUp(); workspace.createVariable('name1', 'type1', 'id1'); workspace.createVariable('name2', 'type2', 'id2'); @@ -188,7 +188,7 @@ function test_redoAndUndoDeleteVariable() { undoRedoTest_tearDown(); } -function test_redoAndUndoDeleteVariableWithBlocks() { +function test_redoAndUndoDeleteVariable_WithBlocks() { undoRedoTest_setUp(); workspace.createVariable('name1', 'type1', 'id1'); workspace.createVariable('name2', 'type2', 'id2'); @@ -214,6 +214,61 @@ function test_redoAndUndoDeleteVariableWithBlocks() { undoRedoTest_tearDown(); } +function test_redoAndUndoDeleteVariableTwice_NoBlocks() { + undoRedoTest_setUp(); + workspace.createVariable('name1', 'type1', 'id1'); + workspace.deleteVariableById('id1'); + workspace.deleteVariableById('id1'); + + // Check the undoStack only recorded one delete event. + var undoStack = workspace.undoStack_; + assertEquals('var_delete', undoStack[undoStack.length-1].type); + assertNotEquals('var_delete', undoStack[undoStack.length-2].type); + + // undo delete + workspace.undo(); + checkVariableValues(workspace, 'name1', 'type1', 'id1'); + + // redo delete + workspace.undo(true); + assertNull(workspace.getVariableById('id1')); + + // redo delete, nothing should happen + workspace.undo(true); + assertNull(workspace.getVariableById('id1')); + undoRedoTest_tearDown(); +} + +function test_redoAndUndoDeleteVariableTwice_WithBlocks() { + undoRedoTest_setUp(); + workspace.createVariable('name1', 'type1', 'id1'); + createMockBlock('name1'); + workspace.deleteVariableById('id1'); + workspace.deleteVariableById('id1'); + + // Check the undoStack only recorded one delete event. + var undoStack = workspace.undoStack_; + assertEquals('var_delete', undoStack[undoStack.length-1].type); + assertEquals('delete', undoStack[undoStack.length-2].type); + assertNotEquals('var_delete', undoStack[undoStack.length-3].type); + + // undo delete + workspace.undo(); + undoRedoTest_checkBlockVariableName(0, 'name1'); + checkVariableValues(workspace, 'name1', 'type1', 'id1'); + + // redo delete + workspace.undo(true); + assertEquals(0, workspace.topBlocks_.length); + assertNull(workspace.getVariableById('id1')); + + // redo delete, nothing should happen + workspace.undo(true); + assertEquals(0, workspace.topBlocks_.length); + assertNull(workspace.getVariableById('id1')); + undoRedoTest_tearDown(); +} + function test_undoRedoRenameVariable_NeitherVariableExists() { // Expect that a variable with the name, 'name2', and the generated UUID, // 'id2', to be created when rename is called. Undo removes this variable