From f50474d60d94b5b934b85e4a398fbde4e77af3f7 Mon Sep 17 00:00:00 2001 From: Julien Rebetez Date: Thu, 25 Feb 2016 10:38:18 +0100 Subject: [PATCH] Add test for attachments garbage collection --- notebook/tests/notebook/attachments.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/notebook/tests/notebook/attachments.js b/notebook/tests/notebook/attachments.js index e3d97eff0..cbeff5308 100644 --- a/notebook/tests/notebook/attachments.js +++ b/notebook/tests/notebook/attachments.js @@ -3,7 +3,7 @@ // var fs = require('fs'); casper.notebook_test(function () { - // Test the Edit->Insert Image menu to insert new attachments + // -- Test the Edit->Insert Image menu to insert new attachments "use strict"; casper.test.info("Testing attachments insertion through the menuitem"); @@ -70,7 +70,7 @@ casper.notebook_test(function () { //this.capture('test.png'); //}); - // Use the Edit->Copy/Paste Cell Attachments menu items + // -- Use the Edit->Copy/Paste Cell Attachments menu items selector = '#copy_cell_attachments > a'; this.waitForSelector(selector); this.thenClick(selector); @@ -85,8 +85,6 @@ casper.notebook_test(function () { selector = '#paste_cell_attachments > a'; this.waitForSelector(selector); this.thenClick(selector); - // Small delay so the paste has the time to complete - this.wait(500); // check that the new cell has attachments this.then(function() { @@ -101,5 +99,25 @@ casper.notebook_test(function () { this.test.assertEquals(cell.attachments, orig_cell.attachments, "both cells have the attachments"); }); + + // -- Save the notebook. This should cause garbage collection for the + // second cell (since we just pasted the attachments but there is no + // markdown referencing them) + this.thenEvaluate(function() { + IPython.notebook.save_checkpoint(); + }); + + this.then(function() { + var cell0 = this.evaluate(function() { + return IPython.notebook.get_cell(0); + }); + var cell1 = this.evaluate(function() { + return IPython.notebook.get_cell(1); + }); + this.test.assert('black_square_22.png' in cell0.attachments, + 'cell0 has kept its attachments'); + this.test.assertEquals(Object.keys(cell1.attachments).length, 0, + 'cell1 attachments have been garbage collected'); + }); });