Skip to content
Permalink
Browse files

m

  • Loading branch information...
mge-odoo committed Mar 18, 2019
1 parent d027bcc commit 1485234afde3c817ddd257086c2e4080639ef03c
Showing with 94 additions and 85 deletions.
  1. +94 −85 addons/web/static/tests/views/list_tests.js
@@ -4622,38 +4622,41 @@ QUnit.module('Views', {
list.destroy();
});

QUnit.test('Grouped Editable List: edit list line after discard changes', async function (assert) {
QUnit.test('edit a line and discard it in grouped editable', async function (assert) {
assert.expect(5);

var list = await createView({
View: ListView,
model: 'foo',
data: this.data,
arch: '<tree editable="top"><field name="foo"/><field name="int_field"/></tree>',
groupBy: ['bar']
groupBy: ['bar'],
});

await testUtils.dom.click(list.$('.o_group_header:first'));
await testUtils.dom.click(list.$('.o_data_row:nth(2) > td:contains(gnap)'));
assert.ok(list.$('.o_data_row:nth(2)').is('.o_selected_row'),
"third group row should be in edition");

await testUtils.dom.click(list.$buttons.find('.o_list_button_discard'));
await testUtils.dom.click(list.$('.o_data_row:nth(0) > td:contains(yop)'));
assert.ok(list.$('.o_data_row:eq(0)').is('.o_selected_row'),
"first group row should be in edition");

await testUtils.dom.click(list.$buttons.find('.o_list_button_discard'));
assert.strictEqual(list.$('.o_selected_row').length, 0,
assert.containsNone(list, '.o_selected_row',
"no group row should be selected");

await testUtils.dom.click(list.$('.o_data_row:nth(2) > td:contains(gnap)'));
assert.ok(list.$('.o_data_row:nth(2)').is('.o_selected_row'),
"third group row should be in edition");
assert.strictEqual(list.$('.o_selected_row').length, 1,
assert.containsOnce(list, '.o_selected_row',
"no other row should be selected");

list.destroy();
});

QUnit.test('Grouped Editable List: inputs are disabled when unselecting rows', async function (assert) {
QUnit.test('inputs are disabled when unselecting rows in grouped editable', async function (assert) {
assert.expect(1);

var $input;
@@ -4669,7 +4672,7 @@ QUnit.module('Views', {
}
return this._super.apply(this, arguments);
},
groupBy: ['bar']
groupBy: ['bar'],
});

await testUtils.dom.click(list.$('.o_group_header:first'));
@@ -4681,7 +4684,7 @@ QUnit.module('Views', {
list.destroy();
});

QUnit.test('Grouped Editable List:add a new row in groupby list, editable from top', async function (assert) {
QUnit.test('add a new row in grouped top editable', async function (assert) {
assert.expect(7);

var list = await createView({
@@ -4692,83 +4695,86 @@ QUnit.module('Views', {
groupBy: ['bar'],
});

await testUtils.dom.click(list.$('.o_group_header:first')); //Open group
await testUtils.dom.click(list.$('.o_group_header:first')); // open group
await testUtils.dom.click(list.$('.o_group_field_row_add a'));// add a new row
assert.ok(list.$('.o_selected_row .o_input[name=foo]'), document.activeElement,
assert.strictEqual(list.$('.o_selected_row .o_input[name=foo]')[0], document.activeElement,
'The first input of the line should have the focus');
assert.strictEqual(list.$('tbody:nth(1)').find('.o_data_row').length, 4,
assert.containsN(list, 'tbody:nth(1) .o_data_row', 4,
"open group should contain 4 rows");
await testUtils.dom.click(list.$buttons.find('.o_list_button_discard')); //discard new row
await testUtils.dom.click(list.$('.o_group_header:eq(1)')); //open second group
assert.strictEqual(list.$('tbody:nth(3)').find('.o_data_row').length, 1,
"open group should contain 1 rows");
await testUtils.dom.click(list.$('.o_group_field_row_add a:eq(1)')); //create row in second group

await testUtils.dom.click(list.$buttons.find('.o_list_button_discard')); // discard new row
await testUtils.dom.click(list.$('.o_group_header:eq(1)')); // open second group
assert.containsOnce(list, 'tbody:nth(3) .o_data_row',
"open group should contain a single row");

await testUtils.dom.click(list.$('.o_group_field_row_add a:eq(1)')); // create row in second group
assert.strictEqual(list.$('.o_group_name:eq(1)').text(), 'false (2)',
"group should have correct name and count"); // row should be created in second group
assert.strictEqual(list.$('tbody:nth(3)').find('.o_data_row').length, 2,
"group should have correct name and count");
assert.containsN(list, 'tbody:nth(3) .o_data_row', 2,
"open group should contain 2 rows");
assert.ok(list.$('.o_data_row:nth(3)').hasClass('o_selected_row'),
assert.hasClass(list.$('.o_data_row:nth(3)'), 'o_selected_row',
"second group row should be create");

await testUtils.fields.editAndTrigger(list.$('tr.o_selected_row input[name="foo"]'), 'pla', 'input');
await testUtils.dom.click(list.$buttons.find('.o_list_button_save')); //save row
assert.strictEqual(list.$('tbody:nth(3)').find('.o_data_row').length, 2,
"open group should contain 2 rows"); //new row added in group
await testUtils.dom.click(list.$buttons.find('.o_list_button_save'));
assert.containsN(list, 'tbody:nth(3) .o_data_row', 2,
"open group should contain 2 rows");

list.destroy();
});

QUnit.test('Grouped Editable List:add a new row in groupby list with create="0', async function (assert) {
assert.expect(2);
QUnit.test('add a new row in grouped bottom editable', async function (assert) {
assert.expect(4);

var list = await createView({
View: ListView,
model: 'foo',
data: this.data,
arch: '<tree editable="top" create="0"><field name="foo" required="1"/></tree>',
arch: '<tree editable="bottom"><field name="foo" required="1"/></tree>',
groupBy: ['bar'],
});

await testUtils.dom.click(list.$('.o_group_header:first')); //Open group
assert.ok(!list.$('.o_group_field_row_add a').length,
"Add a line should not be available in readonly");
assert.strictEqual(list.$('tbody:nth(1)').find('.o_data_row').length, 3,
"open group should contain 3 rows");
await testUtils.dom.click(list.$('.o_group_header:first')); // open group
await testUtils.dom.click(list.$('.o_group_field_row_add a'));// add a new row
assert.hasClass(list.$('.o_data_row:nth(3)'), 'o_selected_row',
"first group last row should be create");
assert.containsN(list, 'tbody:nth(1) .o_data_row', 4,
"open group should contain 4 rows");

await testUtils.dom.click(list.$buttons.find('.o_list_button_discard')); // discard new row
await testUtils.dom.click(list.$('.o_group_header:eq(1)')); // open second group
await testUtils.dom.click(list.$('.o_group_field_row_add a:eq(1)')); // create row in second group
assert.hasClass(list.$('.o_data_row:nth(4)'), 'o_selected_row',
"second group last row should be selected");

await testUtils.fields.editAndTrigger(list.$('tr.o_selected_row input[name="foo"]'), 'pla', 'input');
await testUtils.dom.click(list.$buttons.find('.o_list_button_save'));
assert.containsN(list, 'tbody:nth(3) .o_data_row', 2,
"open group should contain 2 rows");

list.destroy();
});

QUnit.test('Grouped Editable List:add a new row in groupby list, editable from bottom', async function (assert) {
assert.expect(4);
QUnit.test('add a new row with create="0" in grouped editable', async function (assert) {
assert.expect(1);

var list = await createView({
View: ListView,
model: 'foo',
data: this.data,
arch: '<tree editable="bottom"><field name="foo" required="1"/></tree>',
arch: '<tree editable="top" create="0"><field name="foo" required="1"/></tree>',
groupBy: ['bar'],
});

await testUtils.dom.click(list.$('.o_group_header:first')); //Open group
await testUtils.dom.click(list.$('.o_group_field_row_add a'));// add a new row
assert.ok(list.$('.o_data_row:nth(3)').hasClass('o_selected_row'),
"first group last row should be create");
assert.strictEqual(list.$('tbody:nth(1)').find('.o_data_row').length, 4,
"open group should contain 4 rows");
await testUtils.dom.click(list.$buttons.find('.o_list_button_discard')); //discard new row
await testUtils.dom.click(list.$('.o_group_header:eq(1)')); //open second group
await testUtils.dom.click(list.$('.o_group_field_row_add a:eq(1)')); //create row in second group
assert.ok(list.$('.o_data_row:nth(4)').hasClass('o_selected_row'),
"second group last row should be selected");
await testUtils.fields.editAndTrigger(list.$('tr.o_selected_row input[name="foo"]'), 'pla', 'input');
await testUtils.dom.click(list.$buttons.find('.o_list_button_save')); //save row
assert.strictEqual(list.$('tbody:nth(3)').find('.o_data_row').length, 2,
"open group should contain 2 rows"); //new row added in group
await testUtils.dom.click(list.$('.o_group_header:first')); // open group
assert.containsNone(list, '.o_group_field_row_add a',
"Add a line should not be available in readonly");

list.destroy();
});

QUnit.test('Grouped Editable List:add a new row with default value in groupby list with groupby selection field', async function (assert) {
assert.expect(4);
QUnit.test('add a new row in (selection) grouped editable', async function (assert) {
assert.expect(6);

this.data.foo.fields.priority = {
string: "Priority",
@@ -4788,66 +4794,69 @@ QUnit.module('Views', {
'<field name="priority"/>'+
'<field name="m2o"/></tree>',
groupBy: ['priority'],
mockRPC: function (route, args) {
if (args.method === 'default_get') {
assert.step(args.kwargs.context.default_priority.toString());
}
return this._super.apply(this, arguments);
},
});

await testUtils.dom.click(list.$('.o_group_header:first')); //Open group
await testUtils.dom.click(list.$('.o_group_field_row_add a'));// add a new row
assert.ok(list.$('.o_data_row:first').hasClass('o_selected_row'),
"clicking on create should open the create in the first column");
await testUtils.dom.click($('body')); //unselect row
await testUtils.dom.click(list.$('.o_group_header:first')); // open group
await testUtils.dom.click(list.$('.o_group_field_row_add a')); // add a new row
await testUtils.dom.click($('body')); // unselect row
assert.verifySteps(['1']);
assert.strictEqual(list.$('.o_data_row .o_data_cell:eq(1)').text(),'Low',
"should have a column name with a value from the groupby");
await testUtils.dom.click(list.$('.o_group_header:eq(1)')); //open second group
await testUtils.dom.click(list.$('.o_group_field_row_add a:eq(1)')); //create row in second group
assert.ok(list.$('.o_data_row:nth(5)').hasClass('o_selected_row'),
"second group first row should be selected");
await testUtils.dom.click($('body')); //unselect row

await testUtils.dom.click(list.$('.o_group_header:eq(1)')); // open second group
await testUtils.dom.click(list.$('.o_group_field_row_add a:eq(1)')); // create row in second group
await testUtils.dom.click($('body')); // unselect row
assert.strictEqual(list.$('.o_data_row:nth(5) .o_data_cell:eq(1)').text(),'Medium',
"should have a column name with a value from the groupby");
assert.verifySteps(['2']);

list.destroy();
});

QUnit.test('Grouped Editable List:add a new row with default value in groupby list with groupby m2o field', async function (assert) {
assert.expect(4);

this.data.foo.fields.priority = {
string: "Priority",
type: "selection",
selection: [[1, "Low"], [2, "Medium"], [3, "High"]],
default: 1,
};
this.data.foo.records.push({id: 5, foo: "blip", int_field: -7, m2o: 1, priority: 2});
this.data.foo.records.push({id: 6, foo: "blip", int_field: 5, m2o: 1, priority: 3});
QUnit.test('add a new row in (m2o) grouped editable', async function (assert) {
assert.expect(6);

var list = await createView({
View: ListView,
model: 'foo',
data: this.data,
arch: '<tree editable="top">'+
'<field name="foo"/>'+
'<field name="priority"/>'+
arch: '<tree editable="top">' +
'<field name="foo"/>' +
'<field name="m2o"/></tree>',
groupBy: ['m2o'],
mockRPC: function (route, args) {
if (args.method === 'default_get') {
assert.step(args.kwargs.context.default_m2o.toString());
}
return this._super.apply(this, arguments);
},
});

await testUtils.dom.click(list.$('.o_group_header:first')); //Open group
await testUtils.dom.click(list.$('.o_group_field_row_add a'));// add a new row
assert.ok(list.$('.o_data_row:first').hasClass('o_selected_row'),
"clicking on create should open the create in the first column");
await testUtils.dom.click($('body')); //unselect row
assert.strictEqual(list.$('.o_data_row .o_data_cell:eq(2)').text(),'Value 1',
await testUtils.dom.click(list.$('.o_group_header:first'));
await testUtils.dom.click(list.$('.o_group_field_row_add a'));
await testUtils.dom.click($('body')); // unselect row
assert.strictEqual(list.$('tbody:eq(1) .o_data_row:first .o_data_cell:eq(1)').text(), 'Value 1',
"should have a column name with a value from the groupby");
await testUtils.dom.click(list.$('.o_group_header:eq(1)')); //open second group
await testUtils.dom.click(list.$('.o_group_field_row_add a:eq(1)')); //create row in second group
assert.ok(list.$('.o_data_row:nth(6)').hasClass('o_selected_row'),
"second group first row should be selected");
await testUtils.dom.click($('body')); //unselect row
assert.strictEqual(list.$('.o_data_row:nth(6) .o_data_cell:eq(2)').text(),'Value 2',
assert.verifySteps(['1']);

await testUtils.dom.click(list.$('.o_group_header:eq(1)')); // open second group
await testUtils.dom.click(list.$('.o_group_field_row_add a:eq(1)')); // create row in second group
await testUtils.dom.click($('body')); // unselect row
assert.strictEqual(list.$('tbody:eq(3) .o_data_row:first .o_data_cell:eq(1)').text(), 'Value 2',
"should have a column name with a value from the groupby");
assert.verifySteps(['2']);

list.destroy();
});

// TODO: write test on:
// - default_get with a field not in view
});

});

0 comments on commit 1485234

Please sign in to comment.
You can’t perform that action at this time.