mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-12 11:45:38 +08:00
Merge pull request #7680 from jdfreder/persistfix
Fix widget view persistence.
This commit is contained in:
commit
c6bc3cc407
@ -381,16 +381,18 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Get the views that are displayed *now*.
|
// Get the views that are displayed *now*.
|
||||||
model_promises.push(utils.resolve_promises_dict(model.views).then(function(model_views) {
|
(function(local_state) {
|
||||||
for (var id in model_views) {
|
model_promises.push(utils.resolve_promises_dict(model.views).then(function(model_views) {
|
||||||
if (model_views.hasOwnProperty(id)) {
|
for (var id in model_views) {
|
||||||
var view = model_views[id];
|
if (model_views.hasOwnProperty(id)) {
|
||||||
if (view.options.cell_index) {
|
var view = model_views[id];
|
||||||
state[model_id].views.push(view.options.cell_index);
|
if (view.options.cell_index) {
|
||||||
|
local_state.views.push(view.options.cell_index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}));
|
||||||
}));
|
})(state[model_id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,4 +42,53 @@ casper.notebook_test(function () {
|
|||||||
var slider_id = this.evaluate(function() { return window.slider_id; });
|
var slider_id = this.evaluate(function() { return window.slider_id; });
|
||||||
this.test.assertEquals(output, slider_id, "Widget created from the front-end.");
|
this.test.assertEquals(output, slider_id, "Widget created from the front-end.");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Widget persistence tests.
|
||||||
|
index = this.append_cell(
|
||||||
|
'from IPython.html.widgets import HTML\n' +
|
||||||
|
'from IPython.display import display\n' +
|
||||||
|
'display(HTML(value="<div id=\'hello\'></div>"))');
|
||||||
|
this.execute_cell_then(index, function() {});
|
||||||
|
|
||||||
|
index = this.append_cell(
|
||||||
|
'display(HTML(value="<div id=\'world\'></div>"))');
|
||||||
|
this.execute_cell_then(index, function() {});
|
||||||
|
|
||||||
|
var that = this;
|
||||||
|
this.then(function() {
|
||||||
|
// Wait for the widgets to be shown.
|
||||||
|
that.waitForSelector('#hello', function() {
|
||||||
|
that.waitForSelector('#world', function() {
|
||||||
|
that.test.assertExists('#hello', 'Hello HTML widget constructed.');
|
||||||
|
that.test.assertExists('#world', 'World HTML widget constructed.');
|
||||||
|
|
||||||
|
// Save the notebook.
|
||||||
|
that.evaluate(function() {
|
||||||
|
IPython.notebook.save_notebook(false).then(function() {
|
||||||
|
window.was_saved = true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
that.waitFor(function check() {
|
||||||
|
return that.evaluate(function() {
|
||||||
|
return window.was_saved;
|
||||||
|
});
|
||||||
|
}, function then() {
|
||||||
|
|
||||||
|
// Reload the page
|
||||||
|
that.reload(function() {
|
||||||
|
|
||||||
|
// Wait for the elements to show up again.
|
||||||
|
that.waitForSelector('#hello', function() {
|
||||||
|
that.waitForSelector('#world', function() {
|
||||||
|
that.test.assertExists('#hello', 'Hello HTML widget persisted.');
|
||||||
|
that.test.assertExists('#world', 'World HTML widget persisted.');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user