##// END OF EJS Templates
Apply width and height to outter most div of the tab widget.
Apply width and height to outter most div of the tab widget.

File last commit:

r18917:0204be4a
r21464:39954bd8
Show More
widget.js
191 lines | 7.1 KiB | application/javascript | JavascriptLexer
Jonathan Frederic
Added test for pack and unpack Model functions
r15082 var xor = function (a, b) {return !a ^ !b;};
Jonathan Frederic
Adde slimerjs support to JS tests...
r16828 var isArray = function (a) {
try {
return Object.toString.call(a) === "[object Array]" || Object.toString.call(a) === "[object RuntimeArray]";
} catch (e) {
return Array.isArray(a);
}
};
Jonathan Frederic
Added test for pack and unpack Model functions
r15082 var recursive_compare = function(a, b) {
// Recursively compare two objects.
var same = true;
Jonathan Frederic
Adde slimerjs support to JS tests...
r16828 same = same && !xor(a instanceof Object || typeof a == 'object', b instanceof Object || typeof b == 'object');
Jonathan Frederic
Added test for pack and unpack Model functions
r15082 same = same && !xor(isArray(a), isArray(b));
if (same) {
if (a instanceof Object) {
Jonathan Frederic
Added test that shows the problem.
r15277 var key;
for (key in a) {
Jonathan Frederic
Added test for pack and unpack Model functions
r15082 if (a.hasOwnProperty(key) && !recursive_compare(a[key], b[key])) {
same = false;
break;
}
}
Jonathan Frederic
Added test that shows the problem.
r15277 for (key in b) {
Jonathan Frederic
Added test for pack and unpack Model functions
r15082 if (b.hasOwnProperty(key) && !recursive_compare(a[key], b[key])) {
same = false;
break;
}
}
} else {
return a === b;
}
}
return same;
Jonathan Frederic
Added test that shows the problem.
r15277 };
Jonathan Frederic
Added test for pack and unpack Model functions
r15082
Jonathan Frederic
Add basic widget.js tests
r14309 // Test the widget framework.
casper.notebook_test(function () {
Jonathan Frederic
Cleaned up utilities in widget casper js tests
r14435 var index;
Jonathan Frederic
Fixed casperjs widget tests...
r14350
Jonathan Frederic
Make widget tests use new casper util functions
r14436 index = this.append_cell(
Jonathan Frederic
Cleaned up utilities in widget casper js tests
r14435 'from IPython.html import widgets\n' +
'from IPython.display import display, clear_output\n' +
'print("Success")');
Jonathan Frederic
Make widget tests use new casper util functions
r14436 this.execute_cell_then(index);
Jonathan Frederic
Cleaned up utilities in widget casper js tests
r14435
Jonathan Frederic
Fixed casperjs widget tests...
r14350 this.then(function () {
Jonathan Frederic
Added test for pack and unpack Model functions
r15082
// Functions that can be used to test the packing and unpacking APIs
var that = this;
var test_pack = function (input) {
var output = that.evaluate(function(input) {
var model = new IPython.WidgetModel(IPython.notebook.kernel.widget_manager, undefined);
var results = model._pack_models(input);
return results;
}, {input: input});
that.test.assert(recursive_compare(input, output),
JSON.stringify(input) + ' passed through Model._pack_model unchanged');
};
var test_unpack = function (input) {
Jonathan Frederic
Test fixes
r18899 that.thenEvaluate(function(input) {
window.results = undefined;
Jonathan Frederic
Added test for pack and unpack Model functions
r15082 var model = new IPython.WidgetModel(IPython.notebook.kernel.widget_manager, undefined);
Jonathan Frederic
Test fixes
r18899 model._unpack_models(input).then(function(results) {
window.results = results;
});
Jonathan Frederic
Added test for pack and unpack Model functions
r15082 }, {input: input});
Jonathan Frederic
Test fixes
r18899
that.waitFor(function check() {
return that.evaluate(function() {
return window.results;
});
});
that.then(function() {
var results = that.evaluate(function() {
return window.results;
});
that.test.assert(recursive_compare(input, results),
JSON.stringify(input) + ' passed through Model._unpack_model unchanged');
});
Jonathan Frederic
Added test for pack and unpack Model functions
r15082 };
var test_packing = function(input) {
test_pack(input);
test_unpack(input);
};
Jonathan Frederic
Added test that shows the problem.
r15277 test_packing({0: 'hi', 1: 'bye'});
test_packing(['hi', 'bye']);
test_packing(['hi', 5]);
test_packing(['hi', '5']);
test_packing([1.0, 0]);
test_packing([1.0, false]);
test_packing([1, false]);
test_packing([1, false, {a: 'hi'}]);
test_packing([1, false, ['hi']]);
Sylvain Corlay
Test packing/unpacking instances of Date and String
r18823 test_packing([String('hi'), Date("Thu Nov 13 2014 13:46:21 GMT-0500")])
Jonathan Frederic
Added test that shows the problem.
r15277
// Test multi-set, single touch code. First create a custom widget.
Jonathan Frederic
Test fixes
r18899 this.thenEvaluate(function() {
Jonathan Frederic
Added test that shows the problem.
r15277 var MultiSetView = IPython.DOMWidgetView.extend({
render: function(){
this.model.set('a', 1);
this.model.set('b', 2);
this.model.set('c', 3);
this.touch();
},
});
Jonathan Frederic
Fixed typo in new test
r15278 IPython.WidgetManager.register_widget_view('MultiSetView', MultiSetView);
Jonathan Frederic
Added test that shows the problem.
r15277 }, {});
});
// Try creating the multiset widget, verify that sets the values correctly.
var multiset = {};
multiset.index = this.append_cell(
'from IPython.utils.traitlets import Unicode, CInt\n' +
'class MultiSetWidget(widgets.Widget):\n' +
' _view_name = Unicode("MultiSetView", sync=True)\n' +
' a = CInt(0, sync=True)\n' +
' b = CInt(0, sync=True)\n' +
' c = CInt(0, sync=True)\n' +
Jonathan Frederic
Added a test to make sure full state was not getting sent.
r15282 ' d = CInt(-1, sync=True)\n' + // See if it sends a full state.
Jonathan Frederic
s/_handle_receive_state/set_state in tests too
r18071 ' def set_state(self, sync_data):\n' +
' widgets.Widget.set_state(self, sync_data)\n'+
Jonathan Frederic
Added a test to make sure full state was not getting sent.
r15282 ' self.d = len(sync_data)\n' +
Jonathan Frederic
Added test that shows the problem.
r15277 'multiset = MultiSetWidget()\n' +
'display(multiset)\n' +
'print(multiset.model_id)');
this.execute_cell_then(multiset.index, function(index) {
multiset.model_id = this.get_output_cell(index).text.trim();
});
Jonathan Frederic
Address review comments
r18917 this.wait_for_widget(multiset);
Jonathan Frederic
Added test that shows the problem.
r15277
index = this.append_cell(
'print("%d%d%d" % (multiset.a, multiset.b, multiset.c))');
this.execute_cell_then(index, function(index) {
this.test.assertEquals(this.get_output_cell(index).text.trim(), '123',
'Multiple model.set calls and one view.touch update state in back-end.');
Jonathan Frederic
Add basic widget.js tests
r14309 });
Jonathan Frederic
Added a test to make sure full state was not getting sent.
r15282 index = this.append_cell(
'print("%d" % (multiset.d))');
this.execute_cell_then(index, function(index) {
this.test.assertEquals(this.get_output_cell(index).text.trim(), '3',
'Multiple model.set calls sent a partial state.');
});
Jonathan Frederic
Use wait_for_widget in widgets and string widget tests
r14995 var textbox = {};
Jonathan Frederic
Added throttling test
r14463 throttle_index = this.append_cell(
'import time\n' +
Jonathan Frederic
Renamed *Widget to *,...
r17598 'textbox = widgets.Text()\n' +
Jonathan Frederic
Use waitFor instead of sleeping.
r14951 'display(textbox)\n' +
Jonathan Frederic
Fix tests
r17721 'textbox._dom_classes = ["my-throttle-textbox"]\n' +
Jonathan Frederic
Added throttling test
r14463 'def handle_change(name, old, new):\n' +
MinRK
test coalesced output in js
r17307 ' display(len(new))\n' +
Jonathan Frederic
Added throttling test
r14463 ' time.sleep(0.5)\n' +
MinRK
first review pass on widget tests
r14797 'textbox.on_trait_change(handle_change, "value")\n' +
Jonathan Frederic
Use wait_for_widget in widgets and string widget tests
r14995 'print(textbox.model_id)');
Jonathan Frederic
Added throttling test
r14463 this.execute_cell_then(throttle_index, function(index){
Jonathan Frederic
Use wait_for_widget in widgets and string widget tests
r14995 textbox.model_id = this.get_output_cell(index).text.trim();
Jonathan Frederic
Added throttling test
r14463
this.test.assert(this.cell_element_exists(index,
'.widget-area .widget-subarea'),
'Widget subarea exists.');
this.test.assert(this.cell_element_exists(index,
'.my-throttle-textbox'), 'Textbox exists.');
// Send 20 characters
Jonathan Frederic
Fix tests
r17721 this.sendKeys('.my-throttle-textbox input', '....................');
Jonathan Frederic
Added throttling test
r14463 });
Jonathan Frederic
Use wait_for_widget in widgets and string widget tests
r14995 this.wait_for_widget(textbox);
this.then(function () {
MinRK
first review pass on widget tests
r14797 var outputs = this.evaluate(function(i) {
return IPython.notebook.get_cell(i).output_area.outputs;
}, {i : throttle_index});
Jonathan Frederic
Added throttling test
r14463
// Only 4 outputs should have printed, but because of timing, sometimes
// 5 outputs will print. All we need to do is verify num outputs <= 5
// because that is much less than 20.
MinRK
first review pass on widget tests
r14797 this.test.assert(outputs.length <= 5, 'Messages throttled.');
Jonathan Frederic
Added throttling test
r14463
// We also need to verify that the last state sent was correct.
MinRK
output[mime/type] -> output.data[mime/type] in javascript
r18592 var last_state = outputs[outputs.length-1].data['text/plain'];
MinRK
test coalesced output in js
r17307 this.test.assertEquals(last_state, "20", "Last state sent when throttling.");
Jonathan Frederic
Fixed widget_manager instance test.
r14625 });
Jonathan Frederic
Added int range and int widget tests.
r14454 });