summaryrefslogtreecommitdiff
path: root/addons/web/static/test/fields/basic_fields_tests.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/test/fields/basic_fields_tests.js')
-rw-r--r--addons/web/static/test/fields/basic_fields_tests.js199
1 files changed, 199 insertions, 0 deletions
diff --git a/addons/web/static/test/fields/basic_fields_tests.js b/addons/web/static/test/fields/basic_fields_tests.js
index 62d1fd6efe5..d489db97572 100644
--- a/addons/web/static/test/fields/basic_fields_tests.js
+++ b/addons/web/static/test/fields/basic_fields_tests.js
@@ -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) {