summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/relational_fields
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2019-02-28 13:47:09 +0100
committerChristophe Simonis <chs@odoo.com>2019-02-28 13:47:09 +0100
commit06898fac3c9b21d4fd5ef7efd35f829cdff15e46 (patch)
tree6b6d657677778365b06bbf4fb7babcab688edcc2 /addons/web/static/tests/fields/relational_fields
parent012816f85f8f20243bd3dfb55abdfaac59722284 (diff)
parentf9d3b5b7dfe15fb53f14fa0a0ae91bbeded9939b (diff)
[MERGE] forward port branch saas-12.1 up to f9d3b5b7dfe
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields')
-rw-r--r--addons/web/static/tests/fields/relational_fields/field_many2one_tests.js103
1 files changed, 102 insertions, 1 deletions
diff --git a/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js b/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js
index 84fac135ad2..04b58b017ba 100644
--- a/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js
+++ b/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js
@@ -958,7 +958,7 @@ QUnit.module('fields', {}, function () {
return result;
},
});
- await testUtils.fields.many2one.searchAndClickItem('trululu', 'b');
+ await testUtils.fields.many2one.searchAndClickItem('trululu', {search: 'b'});
testUtils.form.clickSave(form);
assert.verifySteps(['name_create'],
@@ -2596,6 +2596,107 @@ QUnit.module('fields', {}, function () {
form.destroy();
});
+ QUnit.test('search more in many2one: no text in input', async function (assert) {
+ // when the user clicks on 'Search More...' in a many2one dropdown, and there is no text
+ // in the input (i.e. no value to search on), we bypass the name_search that is meant to
+ // return a list of preselected ids to filter on in the list view (opened in a dialog)
+ assert.expect(6);
+
+ for (var i = 0; i < 8; i++) {
+ this.data.partner.records.push({id: 100 + i, display_name: 'test_' + i});
+ }
+
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form><field name="trululu"/></form>',
+ archs: {
+ 'partner,false,list': '<list><field name="display_name"/></list>',
+ 'partner,false,search': '<search></search>',
+ },
+ mockRPC: function (route, args) {
+ assert.step(args.method || route);
+ if (route === '/web/dataset/search_read') {
+ assert.deepEqual(args.domain, [],
+ "should not preselect ids as there as nothing in the m2o input");
+ }
+ return this._super.apply(this, arguments);
+ },
+ });
+
+ await testUtils.fields.many2one.searchAndClickItem('trululu', {
+ item: 'Search More',
+ search: '',
+ });
+
+ assert.verifySteps([
+ 'default_get',
+ 'name_search', // to display results in the dropdown
+ 'load_views', // list view in dialog
+ '/web/dataset/search_read', // to display results in the dialog
+ ]);
+
+ form.destroy();
+ });
+
+ QUnit.test('search more in many2one: text in input', async function (assert) {
+ // when the user clicks on 'Search More...' in a many2one dropdown, and there is some
+ // text in the input, we perform a name_search to get a (limited) list of preselected
+ // ids and we add a dynamic filter (with those ids) to the search view in the dialog, so
+ // that the user can remove this filter to bypass the limit
+ assert.expect(12);
+
+ for (var i = 0; i < 8; i++) {
+ this.data.partner.records.push({id: 100 + i, display_name: 'test_' + i});
+ }
+
+ var expectedDomain;
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form><field name="trululu"/></form>',
+ archs: {
+ 'partner,false,list': '<list><field name="display_name"/></list>',
+ 'partner,false,search': '<search></search>',
+ },
+ mockRPC: function (route, args) {
+ assert.step(args.method || route);
+ if (route === '/web/dataset/search_read') {
+ assert.deepEqual(args.domain, expectedDomain);
+ }
+ return this._super.apply(this, arguments);
+ },
+ });
+
+ expectedDomain = [['id', 'in', [100, 101, 102, 103, 104, 105, 106, 107]]];
+ await testUtils.fields.many2one.searchAndClickItem('trululu', {
+ item: 'Search More',
+ search: 'test',
+ });
+
+ assert.containsOnce(document.body, '.modal .o_list_view');
+ assert.containsOnce(document.body, '.modal .o_cp_searchview .o_facet_values',
+ "should have a special facet for the pre-selected ids");
+
+ // remove the filter on ids
+ expectedDomain = [];
+ testUtils.dom.click($('.modal .o_cp_searchview .o_facet_remove'));
+
+ assert.verifySteps([
+ 'default_get',
+ 'name_search', // empty search, triggered when the user clicks in the input
+ 'name_search', // to display results in the dropdown
+ 'name_search', // to get preselected ids matching the search
+ 'load_views', // list view in dialog
+ '/web/dataset/search_read', // to display results in the dialog
+ '/web/dataset/search_read', // after removal of dynamic filter
+ ]);
+
+ form.destroy();
+ });
+
QUnit.test('updating a many2one from a many2many', function (assert) {
assert.expect(4);