[IMP] test_new_api: add field and template to test the X2many communication between web client and server side
This commit is contained in:
@@ -56,6 +56,9 @@ $.extend($.expr[':'],{
|
||||
propValue: function(element, index, matches) {
|
||||
return $(element).prop("value") === matches[3];
|
||||
},
|
||||
propValueContains: function(element, index, matches) {
|
||||
return $(element).prop("value") && $(element).prop("value").indexOf(matches[3]) !== -1;
|
||||
},
|
||||
});
|
||||
$.ajaxSetup({
|
||||
beforeSend:function(){
|
||||
@@ -655,6 +658,9 @@ var Tour = {
|
||||
click_event("mousedown");
|
||||
click_event("mouseup");
|
||||
click_event("click");
|
||||
if ($element.is("input, textarea, select") && !$element.is(":focus")) {
|
||||
$element.focus();
|
||||
}
|
||||
|
||||
// trigger after for step like: mouseenter, next step click on button display with mouseenter
|
||||
setTimeout(function () {
|
||||
@@ -663,7 +669,6 @@ var Tour = {
|
||||
}, self.defaultDelay<<1);
|
||||
}
|
||||
if (step.sampleText) {
|
||||
|
||||
$element.trigger($.Event("keydown", { srcElement: $element[0] }));
|
||||
if ($element.is("input") || $element.is('textarea')) {
|
||||
$element.val(step.sampleText);
|
||||
|
||||
@@ -926,9 +926,8 @@ var One2ManyListView = ListView.extend({
|
||||
this._mousedown_blur_line = function (event) {
|
||||
if (self.__focus) {
|
||||
self.__ignore_blur = true;
|
||||
var $dom = self.editor.$el.add(self.$el);
|
||||
if ($(event.target).closest("button, *:not(.oe_form_field_one2many_list_row_add) > a").length ||
|
||||
($dom.index(event.target) === -1 && !_.any($(event.target).parents(), function (p) { return $dom.index(p) !== -1 ; }))) {
|
||||
(!$(event.target).closest(self.editor.$el[0]).length && !$(event.target).closest(self.$el[0]).length)) {
|
||||
self.__ignore_blur = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,12 +34,12 @@ Tour.register({
|
||||
},
|
||||
{
|
||||
title: "insert body",
|
||||
element: 'textarea.field_text',
|
||||
element: '.modal textarea.field_text',
|
||||
sampleText: 'a'
|
||||
},
|
||||
{
|
||||
title: "create new message",
|
||||
waitFor: 'textarea.field_text:propValue(a)',
|
||||
waitFor: '.modal textarea.field_text:propValue(a)',
|
||||
element: '.oe_abstractformpopup-form-save'
|
||||
},
|
||||
|
||||
@@ -47,17 +47,18 @@ Tour.register({
|
||||
|
||||
{
|
||||
title: "create new message",
|
||||
waitFor: '.oe_list_field_cell',
|
||||
waitNot: '.modal',
|
||||
waitFor: '.oe_application:has(.oe_list_field_cell):has(textarea[name="message_concat"]:propValue([test] Administrator:a))',
|
||||
element: '.oe_form_field_one2many_list_row_add a'
|
||||
},
|
||||
{
|
||||
title: "insert body",
|
||||
element: 'textarea.field_text',
|
||||
element: '.modal textarea.field_text',
|
||||
sampleText: 'b'
|
||||
},
|
||||
{
|
||||
title: "create new message",
|
||||
waitFor: 'textarea.field_text:propValue(b)',
|
||||
waitFor: '.modal textarea.field_text:propValue(b)',
|
||||
element: '.oe_abstractformpopup-form-save'
|
||||
},
|
||||
|
||||
@@ -65,27 +66,37 @@ Tour.register({
|
||||
|
||||
{
|
||||
title: "insert title",
|
||||
waitFor: '.oe_list_field_cell:eq(2)',
|
||||
waitNot: '.modal',
|
||||
waitFor: 'textarea[name="message_concat"]:propValue([test] Administrator:a\n[test] Administrator:b)',
|
||||
element: '.oe_form_required input',
|
||||
sampleText: 'test trigger'
|
||||
sampleText: 'test_trigger'
|
||||
},
|
||||
{
|
||||
title: "blur the title field",
|
||||
waitFor: '.oe_form_required input:propValue(test_trigger)',
|
||||
element: '.oe_form_field_many2one input:first',
|
||||
},
|
||||
{
|
||||
title: "check onchange",
|
||||
waitFor: 'textarea[name="message_concat"]:propValue([test_trigger] Administrator:a\n[test_trigger] Administrator:b)',
|
||||
},
|
||||
|
||||
// change message b
|
||||
|
||||
{
|
||||
title: "edit message b",
|
||||
waitFor: 'tr:has(.oe_list_field_cell):not(:has(.oe_list_record_selector)):eq(1) .oe_list_field_cell:contains([test trigger] )',
|
||||
waitFor: 'tr:has(.oe_list_field_cell):not(:has(.oe_list_record_selector)):eq(1) .oe_list_field_cell:contains([test_trigger] )',
|
||||
waitNot: 'tr:has(.oe_list_field_cell):not(:has(.oe_list_record_selector)):eq(2)',
|
||||
element: '.oe_list_field_cell:containsExact(b)'
|
||||
},
|
||||
{
|
||||
title: "change the body",
|
||||
element: 'textarea.field_text',
|
||||
element: '.modal textarea.field_text',
|
||||
sampleText: 'bbb'
|
||||
},
|
||||
{
|
||||
title: "save changes",
|
||||
waitFor: 'textarea.field_text:propValue(bbb)',
|
||||
waitFor: '.modal textarea.field_text:propValue(bbb)',
|
||||
element: '.oe_abstractformpopup-form-save'
|
||||
},
|
||||
|
||||
@@ -94,17 +105,17 @@ Tour.register({
|
||||
{
|
||||
title: "create new message",
|
||||
waitNot: '.modal',
|
||||
waitFor: 'tr:has(.oe_list_field_cell):not(:has(.oe_list_record_selector)):eq(1) .oe_list_field_text:contains(bbb)',
|
||||
waitFor: 'textarea[name="message_concat"]:propValue([test_trigger] Administrator:a\n[test_trigger] Administrator:bbb)',
|
||||
element: '.oe_form_field_one2many_list_row_add a'
|
||||
},
|
||||
{
|
||||
title: "insert body",
|
||||
element: 'textarea.field_text',
|
||||
element: '.modal textarea.field_text',
|
||||
sampleText: 'c'
|
||||
},
|
||||
{
|
||||
title: "create new message",
|
||||
waitFor: 'textarea.field_text:propValue(c)',
|
||||
waitFor: '.modal textarea.field_text:propValue(c)',
|
||||
element: '.oe_abstractformpopup-form-save'
|
||||
},
|
||||
|
||||
@@ -112,6 +123,7 @@ Tour.register({
|
||||
|
||||
{
|
||||
title: "change tab to Participants",
|
||||
waitNot: '.modal',
|
||||
waitFor: '.oe_form_field_one2many .oe_list_field_cell:eq(3)',
|
||||
element: '[data-toggle="tab"]:contains(Participants)'
|
||||
},
|
||||
@@ -152,7 +164,7 @@ Tour.register({
|
||||
},
|
||||
{
|
||||
title: "check data 2",
|
||||
waitFor: '.oe_form_field_one2many tr:has(.oe_list_field_text:containsExact(bbb)):has(.oe_list_field_char:containsExact([test trigger] Administrator))',
|
||||
waitFor: '.oe_form_field_one2many tr:has(.oe_list_field_text:containsExact(bbb)):has(.oe_list_field_char:containsExact([test_trigger] Administrator))',
|
||||
},
|
||||
{
|
||||
title: "check data 3",
|
||||
@@ -182,12 +194,12 @@ Tour.register({
|
||||
},
|
||||
{
|
||||
title: "insert body",
|
||||
element: 'textarea.field_text',
|
||||
element: '.modal textarea.field_text',
|
||||
sampleText: 'd'
|
||||
},
|
||||
{
|
||||
title: "create new message",
|
||||
waitFor: 'textarea.field_text:propValue(d)',
|
||||
waitFor: '.modal textarea.field_text:propValue(d)',
|
||||
element: '.oe_abstractformpopup-form-save'
|
||||
},
|
||||
|
||||
@@ -195,17 +207,18 @@ Tour.register({
|
||||
|
||||
{
|
||||
title: "create new message",
|
||||
waitNot: '.modal',
|
||||
waitFor: '.oe_list_field_cell:containsExact(d)',
|
||||
element: '.oe_form_field_one2many_list_row_add a'
|
||||
},
|
||||
{
|
||||
title: "insert body",
|
||||
element: 'textarea.field_text',
|
||||
element: '.modal textarea.field_text',
|
||||
sampleText: 'e'
|
||||
},
|
||||
{
|
||||
title: "create new message",
|
||||
waitFor: 'textarea.field_text:propValue(e)',
|
||||
waitFor: '.modal textarea.field_text:propValue(e)',
|
||||
element: '.oe_abstractformpopup-form-save'
|
||||
},
|
||||
|
||||
@@ -213,17 +226,18 @@ Tour.register({
|
||||
|
||||
{
|
||||
title: "create new message",
|
||||
waitNot: '.modal',
|
||||
waitFor: '.oe_list_field_cell:containsExact(e)',
|
||||
element: '.oe_list_field_cell:containsExact(a)'
|
||||
},
|
||||
{
|
||||
title: "change the body",
|
||||
element: 'textarea.field_text',
|
||||
element: '.modal textarea.field_text',
|
||||
sampleText: 'aaa'
|
||||
},
|
||||
{
|
||||
title: "save changes",
|
||||
waitFor: 'textarea.field_text:propValue(aaa)',
|
||||
waitFor: '.modal textarea.field_text:propValue(aaa)',
|
||||
element: '.oe_abstractformpopup-form-save'
|
||||
},
|
||||
|
||||
@@ -231,8 +245,8 @@ Tour.register({
|
||||
|
||||
{
|
||||
title: "remove b",
|
||||
waitFor: '.oe_list_field_text:contains(aaa)',
|
||||
waitNot: '.modal',
|
||||
waitFor: '.oe_list_field_text:contains(aaa)',
|
||||
element: 'tr:has(.oe_list_field_cell:containsExact(bbb)) .oe_list_record_delete button'
|
||||
},
|
||||
{
|
||||
@@ -240,6 +254,9 @@ Tour.register({
|
||||
waitNot: 'tr:has(.oe_list_field_cell:containsExact(bbb))',
|
||||
element: 'tr:has(.oe_list_field_cell:containsExact(e)) .oe_list_record_delete button'
|
||||
},
|
||||
|
||||
// save
|
||||
|
||||
{
|
||||
title: "save discussion",
|
||||
waitNot: 'tr:has(.oe_list_field_cell:containsExact(e))',
|
||||
@@ -258,7 +275,7 @@ Tour.register({
|
||||
},
|
||||
{
|
||||
title: "check data 6",
|
||||
waitFor: '.oe_form_field_one2many tr:has(.oe_list_field_text:containsExact(aaa)):has(.oe_list_field_char:containsExact([test trigger] Administrator))',
|
||||
waitFor: '.oe_form_field_one2many tr:has(.oe_list_field_text:containsExact(aaa)):has(.oe_list_field_char:containsExact([test_trigger] Administrator))',
|
||||
},
|
||||
{
|
||||
title: "check data 7",
|
||||
@@ -266,9 +283,128 @@ Tour.register({
|
||||
waitNot: '.oe_form_field_many2many tbody tr:has(.oe_list_field_char):eq(2)',
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
{
|
||||
title: "finish",
|
||||
title: "switch to the second form view to test one2many with editable list",
|
||||
waitFor: '.oe_list_field_cell:eq(3)',
|
||||
element: 'a.oe_menu_leaf:contains(Discussions 2)'
|
||||
},
|
||||
|
||||
{
|
||||
title: "switch to list view",
|
||||
waitFor: ".oe_list_editable",
|
||||
element: '.oe-cp-switch-list',
|
||||
},
|
||||
{
|
||||
title: "select previous created record",
|
||||
element: 'td[data-field="name"]:contains(test_trigger):last',
|
||||
},
|
||||
{
|
||||
title: "click on edit",
|
||||
element: '.oe_form_button_edit',
|
||||
},
|
||||
|
||||
{
|
||||
title: "click on a field of the editable list to edit content",
|
||||
element: '.oe_list_editable tr[data-id]:eq(1) .oe_list_field_cell:eq(2)',
|
||||
},
|
||||
{
|
||||
title: "change text value",
|
||||
element: '.oe_form_field[data-fieldname="body"] textarea',
|
||||
sampleText: 'ccc'
|
||||
},
|
||||
{
|
||||
title: "click on a many2one (trigger the line onchange)",
|
||||
element: '.oe_list_editable tr[data-id]:eq(1) .oe_list_field_cell:eq(1)',
|
||||
},
|
||||
{
|
||||
title: "test on2many's line onchange",
|
||||
waitFor: '.oe_list_editable tr[data-id]:eq(1) .oe_list_field_cell:eq(3):contains(3)',
|
||||
},
|
||||
{
|
||||
title: "test on2many field not triggered onchange",
|
||||
waitNot: 'textarea[name="message_concat"]:propValueContains(ccc)',
|
||||
},
|
||||
|
||||
{
|
||||
title: "open the many2one to select an other user",
|
||||
element: '.oe_m2o_drop_down_button',
|
||||
},
|
||||
{
|
||||
title: "select an other user",
|
||||
element: '.oe_application li a:contains(Demo User)',
|
||||
},
|
||||
{
|
||||
title: "test on2many's line onchange after many2one",
|
||||
waitFor: '.oe_form_char_content:contains([test_trigger] Demo User)',
|
||||
},
|
||||
{
|
||||
title: "test on2many field not triggered onchange",
|
||||
waitNot: 'textarea[name="message_concat"]:propValueContains(ccc)',
|
||||
},
|
||||
{
|
||||
title: "change text value",
|
||||
element: '.oe_form_field[data-fieldname="body"] textarea',
|
||||
sampleText: 'ccccc'
|
||||
},
|
||||
|
||||
// check onchange
|
||||
|
||||
{
|
||||
title: "click outside to trigger one2many onchange",
|
||||
waitNot: 'textarea[name="message_concat"]:propValueContains(Demo User)',
|
||||
element: '.oe_form_required input',
|
||||
},
|
||||
{
|
||||
title: "test one2many onchange",
|
||||
waitFor: 'textarea[name="message_concat"]:propValueContains([test_trigger] Demo User:ccccc)',
|
||||
},
|
||||
|
||||
{
|
||||
title: "click outside to trigger one2many onchange",
|
||||
element: '.oe_tags .text-arrow',
|
||||
},
|
||||
{
|
||||
title: "click outside to trigger one2many onchange",
|
||||
element: '.text-label:first',
|
||||
},
|
||||
|
||||
{
|
||||
title: "click outside to trigger one2many onchange",
|
||||
element: '.text-label:first',
|
||||
},
|
||||
|
||||
// remove record
|
||||
|
||||
{
|
||||
title: "delete the last item in the editable list",
|
||||
element: '.oe_list_record_delete button:visible:last',
|
||||
},
|
||||
{
|
||||
title: "test one2many onchange after delete",
|
||||
waitNot: 'textarea[name="message_concat"]:propValueContains(Administrator:d)',
|
||||
},
|
||||
|
||||
// save
|
||||
|
||||
{
|
||||
title: "save discussion",
|
||||
waitNot: 'tr:has(.oe_list_field_cell:containsExact(e))',
|
||||
element: 'button.oe_form_button_save'
|
||||
},
|
||||
|
||||
// check saved data
|
||||
|
||||
{
|
||||
title: "check data 8",
|
||||
waitFor: '.oe_form_text_content:containsExact([test_trigger] Administrator:aaa\n[test_trigger] Demo User:ccccc)',
|
||||
},
|
||||
{
|
||||
title: "check data 9",
|
||||
waitFor: '.oe_form_field_one2many tbody tr:has(.oe_list_field_cell):eq(1)',
|
||||
waitNot: '.oe_form_field_one2many tbody tr:has(.oe_list_field_cell):eq(2)',
|
||||
},
|
||||
]
|
||||
});
|
||||
|
||||
@@ -85,7 +85,7 @@ class Discussion(models.Model):
|
||||
'test_new_api_discussion_category', 'discussion', 'category')
|
||||
participants = fields.Many2many('res.users')
|
||||
messages = fields.One2many('test_new_api.message', 'discussion')
|
||||
message_changes = fields.Integer(string='Message changes')
|
||||
message_concat = fields.Text(string='Message concatenate')
|
||||
|
||||
@api.onchange('moderator')
|
||||
def _onchange_moderator(self):
|
||||
@@ -93,7 +93,7 @@ class Discussion(models.Model):
|
||||
|
||||
@api.onchange('messages')
|
||||
def _onchange_messages(self):
|
||||
self.message_changes = len(self.messages)
|
||||
self.message_concat = "\n".join(["%s:%s" % (m.name, m.body) for m in self.messages])
|
||||
|
||||
|
||||
class Message(models.Model):
|
||||
|
||||
@@ -193,8 +193,9 @@ class TestOnChange(common.TransactionCase):
|
||||
'categories': [(4, cat.id) for cat in discussion.categories],
|
||||
'messages': messages,
|
||||
'participants': [(4, usr.id) for usr in discussion.participants],
|
||||
'message_changes': 0,
|
||||
'message_concat': False,
|
||||
}
|
||||
result = discussion.onchange(values, 'messages', field_onchange)
|
||||
self.assertIn('message_changes', result['value'])
|
||||
self.assertEqual(result['value']['message_changes'], len(discussion.messages))
|
||||
self.assertIn('message_concat', result['value'])
|
||||
self.assertEqual(result['value']['message_concat'],
|
||||
"\n".join(["%s:%s" % (m.name, m.body) for m in discussion.messages]))
|
||||
|
||||
@@ -33,12 +33,17 @@
|
||||
<record id="discussion_form" model="ir.ui.view">
|
||||
<field name="name">discussion form view</field>
|
||||
<field name="model">test_new_api.discussion</field>
|
||||
<field name="priority" eval="1"/>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Discussion" version="7.0">
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<field name="categories" widget="many2many_tags"/>
|
||||
<!--
|
||||
Bug if the view contains at least 5 fields.
|
||||
The order of the dic values changes and the _check_author constraint raise.
|
||||
<field name="categories" widget="many2many_tags"/>
|
||||
-->
|
||||
<field name="moderator"/>
|
||||
</group>
|
||||
<notebook>
|
||||
@@ -63,11 +68,58 @@
|
||||
<field name="participants"/>
|
||||
</page>
|
||||
</notebook>
|
||||
<group>
|
||||
<field name="message_concat"/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Discussion form view with editable list -->
|
||||
<record id="discussion_form_2" model="ir.ui.view">
|
||||
<field name="name">discussion form view</field>
|
||||
<field name="model">test_new_api.discussion</field>
|
||||
<field name="priority" eval="10"/>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Discussion" version="7.0">
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<field name="categories" widget="many2many_tags"/>
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="Messages">
|
||||
<field name="messages">
|
||||
<tree name="Messages" editable="bottom">
|
||||
<field name="name"/>
|
||||
<field name="author"/>
|
||||
<field name="body"/>
|
||||
<field name="size"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
<page string="Participants">
|
||||
<field name="participants"/>
|
||||
</page>
|
||||
</notebook>
|
||||
<group>
|
||||
<field name="message_concat"/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_discussions_2" model="ir.actions.act_window">
|
||||
<field name="name">Discussions 2</field>
|
||||
<field name="res_model">test_new_api.discussion</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="discussion_form_2"/>
|
||||
</record>
|
||||
<menuitem id="menu_discussions_2" action="action_discussions_2" parent="menu_sub" sequence="10"/>
|
||||
|
||||
|
||||
<!-- Message tree view -->
|
||||
<record id="message_tree" model="ir.ui.view">
|
||||
<field name="name">message tree view</field>
|
||||
|
||||
Reference in New Issue
Block a user