[ADD] web: add state_selection widget tests and documentation

This commit also adds the special_click property which is used to mark
a DOM element such that clicks on it will not be intercepted by the
list view.

Basically, we need this on elements which rely on bootstrap events,
since those need to bubble all the way up. If we catch them in
the list view, to open a cell or a record, then they never get to
bootstrap's level and so the widgets relying on these elements
cannot work.

We plan to remove it at some point, when we have more time to figure
out a way for the click event to reach bootstrap from inside the list
view without breaking the list view behavior itself.
This commit is contained in:
David Monjoie
2017-04-11 19:44:38 +02:00
committed by Aaron Bohy
parent 8b2c091313
commit fbb0450d51
4 changed files with 261 additions and 14 deletions
@@ -57,6 +57,7 @@ QUnit.module('basic_fields', {
trululu: 1,
sequence: 4,
currency_id: 2,
selection: 'normal',
}, {
id: 4,
display_name: "aaa",
@@ -64,6 +65,7 @@ QUnit.module('basic_fields', {
sequence: 9,
int_field: false,
qux: false,
selection: 'done',
},
{id: 3, bar: true, foo: "gnap", int_field: 17, qux: -3.89859, m2o: 1, m2m: []},
{id: 5, bar: false, foo: "blop", int_field: -4, qux: 9.1, m2o: 1, m2m: [1], currency_id: 1}],
@@ -1882,6 +1884,203 @@ QUnit.module('basic_fields', {
});
QUnit.module('StateSelection Widget');
QUnit.test('state_selection widget in form view', function (assert) {
assert.expect(21);
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<group>' +
'<field name="selection" widget="state_selection"/>' +
'</group>' +
'</sheet>' +
'</form>',
res_id: 1,
});
assert.strictEqual(form.$('.o_form_field.o_selection > a span.o_status.o_status_red').length, 1,
"should have one red status since selection is the second, blocked state");
assert.strictEqual(form.$('.o_form_field.o_selection > a span.o_status.o_status_green').length, 0,
"should not have one green status since selection is the second, blocked state");
assert.strictEqual(form.$('ul.dropdown-menu.state:visible').length, 0,
"there should not be a dropdown");
// Click on the status button to make the dropdown appear
form.$('.o_form_field.o_selection .o_status').first().click();
assert.strictEqual(form.$('ul.dropdown-menu.state:visible').length, 1,
"there should be a dropdown");
assert.strictEqual(form.$('ul.dropdown-menu.state:visible li').length, 2,
"there should be two options in the dropdown");
// Click on the first option, "Normal"
form.$('ul.dropdown-menu.state:visible li').first().click();
assert.strictEqual(form.$('ul.dropdown-menu.state:visible').length, 0,
"there should not be a dropdown anymore");
assert.strictEqual(form.$('.o_form_field.o_selection > a span.o_status.o_status_red').length, 0,
"should not have one red status since selection is the first, normal state");
assert.strictEqual(form.$('.o_form_field.o_selection > a span.o_status.o_status_green').length, 0,
"should not have one green status since selection is the first, normal state");
assert.strictEqual(form.$('.o_form_field.o_selection > a span.o_status').length, 1,
"should have one grey status since selection is the first, normal state");
// switch to edit mode and check the result
form.$buttons.find('.o_form_button_edit').click();
assert.strictEqual(form.$('ul.dropdown-menu.state:visible').length, 0,
"there should still not be a dropdown");
assert.strictEqual(form.$('.o_form_field.o_selection > a span.o_status.o_status_red').length, 0,
"should still not have one red status since selection is the first, normal state");
assert.strictEqual(form.$('.o_form_field.o_selection > a span.o_status.o_status_green').length, 0,
"should still not have one green status since selection is the first, normal state");
assert.strictEqual(form.$('.o_form_field.o_selection > a span.o_status').length, 1,
"should still have one grey status since selection is the first, normal state");
// Click on the status button to make the dropdown appear
form.$('.o_form_field.o_selection .o_status').first().click();
assert.strictEqual(form.$('ul.dropdown-menu.state:visible').length, 1,
"there should be a dropdown");
assert.strictEqual(form.$('ul.dropdown-menu.state:visible li').length, 2,
"there should be two options in the dropdown");
// Click on the last option, "Done"
form.$('ul.dropdown-menu.state:visible li').last().click();
assert.strictEqual(form.$('ul.dropdown-menu.state:visible').length, 0,
"there should not be a dropdown anymore");
assert.strictEqual(form.$('.o_form_field.o_selection > a span.o_status.o_status_red').length, 0,
"should not have one red status since selection is the third, done state");
assert.strictEqual(form.$('.o_form_field.o_selection > a span.o_status.o_status_green').length, 1,
"should have one green status since selection is the third, done state");
// save
form.$buttons.find('.o_form_button_save').click();
assert.strictEqual(form.$('ul.dropdown-menu.state:visible').length, 0,
"there should still not be a dropdown anymore");
assert.strictEqual(form.$('.o_form_field.o_selection > a span.o_status.o_status_red').length, 0,
"should still not have one red status since selection is the third, done state");
assert.strictEqual(form.$('.o_form_field.o_selection > a span.o_status.o_status_green').length, 1,
"should still have one green status since selection is the third, done state");
form.destroy();
});
QUnit.test('state_selection widget in editable list view', function(assert) {
assert.expect(34);
var list = createView({
View: ListView,
model: 'partner',
data: this.data,
arch: '<tree editable="bottom">' +
'<field name="foo"/>' +
'<field name="selection" widget="state_selection"/>' +
'</tree>',
});
assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status').length, 5,
"should have five status selection widgets");
assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_red').length, 1,
"should have one red status");
assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_green').length, 1,
"should have one green status");
assert.strictEqual(list.$('ul.dropdown-menu.state:visible').length, 0,
"there should not be a dropdown");
// Click on the status button to make the dropdown appear
var $cell = list.$('tbody td.o_state_selection_cell').first();
list.$('.o_state_selection_cell .o_selection > a span.o_status').first().click();
assert.ok(!$cell.hasClass('o_edit_mode'),
'should not be in edit mode since we clicked on the widget and not the cell itself');
assert.ok(!$cell.siblings().hasClass('o_edit_mode'),
'siblings should not be in edit mode since we clicked on the widget and not the cell itself');
assert.strictEqual(list.$('ul.dropdown-menu.state:visible').length, 1,
"there should be a dropdown");
assert.strictEqual(list.$('ul.dropdown-menu.state:visible li').length, 2,
"there should be two options in the dropdown");
// Click on the first option, "Normal"
list.$('ul.dropdown-menu.state:visible li').first().click();
assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status').length, 5,
"should still have five status selection widgets");
assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_red').length, 0,
"should now have no red status");
assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_green').length, 1,
"should still have one green status");
assert.strictEqual(list.$('ul.dropdown-menu.state:visible').length, 0,
"there should not be a dropdown");
// switch to edit mode and check the result
$cell = list.$('tbody td.o_state_selection_cell').first();
$cell.click();
assert.ok(!$cell.hasClass('o_edit_mode'),
'should still not be in edit mode since widget is readonly');
assert.ok($cell.siblings().hasClass('o_edit_mode'),
'siblings should be in edit mode since we clicked on the cell and not the widget itself');
assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status').length, 5,
"should still have five status selection widgets");
assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_red').length, 0,
"should now have no red status");
assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_green').length, 1,
"should still have one green status");
assert.strictEqual(list.$('ul.dropdown-menu.state:visible').length, 0,
"there should not be a dropdown");
// Click on the status button to make the dropdown appear
list.$('.o_state_selection_cell .o_selection > a span.o_status').first().click();
assert.strictEqual(list.$('ul.dropdown-menu.state:visible').length, 1,
"there should be a dropdown");
assert.strictEqual(list.$('ul.dropdown-menu.state:visible li').length, 2,
"there should be two options in the dropdown");
// Click on another row
var $firstCell = list.$('tbody td.o_state_selection_cell').first();
var $lastCell = list.$('tbody td.o_state_selection_cell').last();
$lastCell.click();
assert.strictEqual(list.$('ul.dropdown-menu.state:visible').length, 0,
"there should not be a dropdown anymore");
assert.ok(!$firstCell.siblings().hasClass('o_edit_mode'),
'first row should not be in edit mode anymore');
assert.ok($lastCell.siblings().hasClass('o_edit_mode'),
'last row should be in edit mode');
// Click on the last status button to make the dropdown appear
list.$('.o_state_selection_cell .o_selection > a span.o_status').last().click();
assert.strictEqual(list.$('ul.dropdown-menu.state:visible').length, 1,
"there should be a dropdown");
assert.strictEqual(list.$('ul.dropdown-menu.state:visible li').length, 2,
"there should be two options in the dropdown");
// Click on the last option, "Done"
list.$('ul.dropdown-menu.state:visible li').last().click();
assert.strictEqual(list.$('ul.dropdown-menu.state:visible').length, 0,
"there should not be a dropdown anymore");
assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status').length, 5,
"should still have five status selection widgets");
assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_red').length, 0,
"should still have no red status");
assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_green').length, 2,
"should now have two green status");
assert.strictEqual(list.$('ul.dropdown-menu.state:visible').length, 0,
"there should not be a dropdown");
// save
list.$buttons.find('.o_list_button_save').click();
assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status').length, 5,
"should have five status selection widgets");
assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_red').length, 0,
"should have no red status");
assert.strictEqual(list.$('.o_state_selection_cell .o_selection > a span.o_status.o_status_green').length, 2,
"should have two green status");
assert.strictEqual(list.$('ul.dropdown-menu.state:visible').length, 0,
"there should not be a dropdown");
list.destroy();
});
QUnit.module('FieldDomain');
QUnit.test('basic domain field usage is ok', function (assert) {