1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
|
odoo.define('web.search_bar_tests', function (require) {
"use strict";
const { Model } = require('web/static/src/js/model.js');
const Registry = require("web.Registry");
const SearchBar = require('web.SearchBar');
const testUtils = require('web.test_utils');
const cpHelpers = testUtils.controlPanel;
const { createActionManager, createComponent } = testUtils;
QUnit.module('Components', {
beforeEach: function () {
this.data = {
partner: {
fields: {
bar: { string: "Bar", type: 'many2one', relation: 'partner' },
birthday: { string: "Birthday", type: 'date' },
birth_datetime: { string: "Birth DateTime", type: 'datetime' },
foo: { string: "Foo", type: 'char' },
bool: { string: "Bool", type: 'boolean' },
},
records: [
{ id: 1, display_name: "First record", foo: "yop", bar: 2, bool: true, birthday: '1983-07-15', birth_datetime: '1983-07-15 01:00:00' },
{ id: 2, display_name: "Second record", foo: "blip", bar: 1, bool: false, birthday: '1982-06-04', birth_datetime: '1982-06-04 02:00:00' },
{ id: 3, display_name: "Third record", foo: "gnap", bar: 1, bool: false, birthday: '1985-09-13', birth_datetime: '1985-09-13 03:00:00' },
{ id: 4, display_name: "Fourth record", foo: "plop", bar: 2, bool: true, birthday: '1983-05-05', birth_datetime: '1983-05-05 04:00:00' },
{ id: 5, display_name: "Fifth record", foo: "zoup", bar: 2, bool: true, birthday: '1800-01-01', birth_datetime: '1800-01-01 05:00:00' },
],
},
};
this.actions = [{
id: 1,
name: "Partners Action",
res_model: 'partner',
search_view_id: [false, 'search'],
type: 'ir.actions.act_window',
views: [[false, 'list']],
}];
this.archs = {
'partner,false,list': `
<tree>
<field name="foo"/>
</tree>`,
'partner,false,search': `
<search>
<field name="foo"/>
<field name="birthday"/>
<field name="birth_datetime"/>
<field name="bar" context="{'bar': self}"/>
<filter string="Date Field Filter" name="positive" date="birthday"/>
<filter string="Date Field Groupby" name="coolName" context="{'group_by': 'birthday:day'}"/>
</search>`,
};
},
}, function () {
QUnit.module('SearchBar');
QUnit.test('basic rendering', async function (assert) {
assert.expect(1);
const actionManager = await createActionManager({
actions: this.actions,
archs: this.archs,
data: this.data,
});
await actionManager.doAction(1);
assert.strictEqual(document.activeElement,
actionManager.el.querySelector('.o_searchview input.o_searchview_input'),
"searchview input should be focused");
actionManager.destroy();
});
QUnit.test('navigation with facets', async function (assert) {
assert.expect(4);
const actionManager = await createActionManager({
actions: this.actions,
archs: this.archs,
data: this.data,
});
await actionManager.doAction(1);
// add a facet
await cpHelpers.toggleGroupByMenu(actionManager);
await cpHelpers.toggleMenuItem(actionManager, 0);
await cpHelpers.toggleMenuItemOption(actionManager, 0, 0);
assert.containsOnce(actionManager, '.o_searchview .o_searchview_facet',
"there should be one facet");
assert.strictEqual(document.activeElement,
actionManager.el.querySelector('.o_searchview input.o_searchview_input'));
// press left to focus the facet
await testUtils.dom.triggerEvent(document.activeElement, 'keydown', { key: 'ArrowLeft' });
assert.strictEqual(document.activeElement, actionManager.el.querySelector('.o_searchview .o_searchview_facet'));
// press right to focus the input
await testUtils.dom.triggerEvent(document.activeElement, 'keydown', { key: 'ArrowRight' });
assert.strictEqual(document.activeElement, actionManager.el.querySelector('.o_searchview input.o_searchview_input'));
actionManager.destroy();
});
QUnit.test('search date and datetime fields. Support of timezones', async function (assert) {
assert.expect(4);
let searchReadCount = 0;
const actionManager = await createActionManager({
actions: this.actions,
archs: this.archs,
data: this.data,
session: {
getTZOffset() {
return 360;
}
},
async mockRPC(route, args) {
if (route === '/web/dataset/search_read') {
switch (searchReadCount) {
case 0:
// Done on loading
break;
case 1:
assert.deepEqual(args.domain, [["birthday", "=", "1983-07-15"]],
"A date should stay what the user has input, but transmitted in server's format");
break;
case 2:
// Done on closing the first facet
break;
case 3:
assert.deepEqual(args.domain, [["birth_datetime", "=", "1983-07-14 18:00:00"]],
"A datetime should be transformed in UTC and transmitted in server's format");
break;
}
searchReadCount++;
}
return this._super(...arguments);
},
});
await actionManager.doAction(1);
// Date case
let searchInput = actionManager.el.querySelector('.o_searchview_input');
await testUtils.fields.editInput(searchInput, '07/15/1983');
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'ArrowDown' });
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'Enter' });
assert.strictEqual(actionManager.el.querySelector('.o_searchview_facet .o_facet_values').innerText.trim(),
'07/15/1983',
'The format of the date in the facet should be in locale');
// Close Facet
await testUtils.dom.click($('.o_searchview_facet .o_facet_remove'));
// DateTime case
searchInput = actionManager.el.querySelector('.o_searchview_input');
await testUtils.fields.editInput(searchInput, '07/15/1983 00:00:00');
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'ArrowDown' });
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'ArrowDown' });
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'Enter' });
assert.strictEqual(actionManager.el.querySelector('.o_searchview_facet .o_facet_values').innerText.trim(),
'07/15/1983 00:00:00',
'The format of the datetime in the facet should be in locale');
actionManager.destroy();
});
QUnit.test("autocomplete menu clickout interactions", async function (assert) {
assert.expect(9);
const fields = this.data.partner.fields;
class TestModelExtension extends Model.Extension {
get(property) {
switch (property) {
case 'facets':
return [];
case 'filters':
return Object.keys(fields).map((fname, index) => Object.assign({
description: fields[fname].string,
fieldName: fname,
fieldType: fields[fname].type,
id: index,
}, fields[fname]));
default:
break;
}
}
}
class MockedModel extends Model { }
MockedModel.registry = new Registry({ Test: TestModelExtension, });
const searchModel = new MockedModel({ Test: {} });
const searchBar = await createComponent(SearchBar, {
data: this.data,
env: { searchModel },
props: { fields },
});
const input = searchBar.el.querySelector('.o_searchview_input');
assert.containsNone(searchBar, '.o_searchview_autocomplete');
await testUtils.controlPanel.editSearch(searchBar, "Hello there");
assert.strictEqual(input.value, "Hello there", "input value should be updated");
assert.containsOnce(searchBar, '.o_searchview_autocomplete');
await testUtils.dom.triggerEvent(input, 'keydown', { key: 'Escape' });
assert.strictEqual(input.value, "", "input value should be empty");
assert.containsNone(searchBar, '.o_searchview_autocomplete');
await testUtils.controlPanel.editSearch(searchBar, "General Kenobi");
assert.strictEqual(input.value, "General Kenobi", "input value should be updated");
assert.containsOnce(searchBar, '.o_searchview_autocomplete');
await testUtils.dom.click(document.body);
assert.strictEqual(input.value, "", "input value should be empty");
assert.containsNone(searchBar, '.o_searchview_autocomplete');
searchBar.destroy();
});
QUnit.test('select an autocomplete field', async function (assert) {
assert.expect(3);
let searchReadCount = 0;
const actionManager = await createActionManager({
actions: this.actions,
archs: this.archs,
data: this.data,
async mockRPC(route, args) {
if (route === '/web/dataset/search_read') {
switch (searchReadCount) {
case 0:
// Done on loading
break;
case 1:
assert.deepEqual(args.domain, [["foo", "ilike", "a"]]);
break;
}
searchReadCount++;
}
return this._super(...arguments);
},
});
await actionManager.doAction(1);
const searchInput = actionManager.el.querySelector('.o_searchview_input');
await testUtils.fields.editInput(searchInput, 'a');
assert.containsN(actionManager, '.o_searchview_autocomplete li', 2,
"there should be 2 result for 'a' in search bar autocomplete");
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'Enter' });
assert.strictEqual(actionManager.el.querySelector('.o_searchview_input_container .o_facet_values').innerText.trim(),
"a", "There should be a field facet with label 'a'");
actionManager.destroy();
});
QUnit.test('select an autocomplete field with `context` key', async function (assert) {
assert.expect(9);
let searchReadCount = 0;
const firstLoading = testUtils.makeTestPromise();
const actionManager = await createActionManager({
actions: this.actions,
archs: this.archs,
data: this.data,
async mockRPC(route, args) {
if (route === '/web/dataset/search_read') {
switch (searchReadCount) {
case 0:
firstLoading.resolve();
break;
case 1:
assert.deepEqual(args.domain, [["bar", "=", 1]]);
assert.deepEqual(args.context.bar, [1]);
break;
case 2:
assert.deepEqual(args.domain, ["|", ["bar", "=", 1], ["bar", "=", 2]]);
assert.deepEqual(args.context.bar, [1, 2]);
break;
}
searchReadCount++;
}
return this._super(...arguments);
},
});
await actionManager.doAction(1);
await firstLoading;
assert.strictEqual(searchReadCount, 1, "there should be 1 search_read");
const searchInput = actionManager.el.querySelector('.o_searchview_input');
// 'r' key to filter on bar "First Record"
await testUtils.fields.editInput(searchInput, 'record');
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'ArrowDown' });
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'ArrowRight' });
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'ArrowDown' });
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'Enter' });
assert.strictEqual(actionManager.el.querySelector('.o_searchview_input_container .o_facet_values').innerText.trim(),
"First record",
"the autocompletion facet should be correct");
assert.strictEqual(searchReadCount, 2, "there should be 2 search_read");
// 'r' key to filter on bar "Second Record"
await testUtils.fields.editInput(searchInput, 'record');
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'ArrowDown' });
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'ArrowRight' });
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'ArrowDown' });
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'ArrowDown' });
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'Enter' });
assert.strictEqual(actionManager.el.querySelector('.o_searchview_input_container .o_facet_values').innerText.trim(),
"First recordorSecond record",
"the autocompletion facet should be correct");
assert.strictEqual(searchReadCount, 3, "there should be 3 search_read");
actionManager.destroy();
});
QUnit.test('no search text triggers a reload', async function (assert) {
assert.expect(2);
// Switch to pivot to ensure that the event comes from the control panel
// (pivot does not have a handler on "reload" event).
this.actions[0].views = [[false, 'pivot']];
this.archs['partner,false,pivot'] = `
<pivot>
<field name="foo" type="row"/>
</pivot>`;
let rpcs;
const actionManager = await createActionManager({
actions: this.actions,
archs: this.archs,
data: this.data,
mockRPC: function () {
rpcs++;
return this._super.apply(this, arguments);
},
});
await actionManager.doAction(1);
const searchInput = actionManager.el.querySelector('.o_searchview_input');
rpcs = 0;
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'Enter' });
assert.containsNone(actionManager, '.o_searchview_facet_label');
assert.strictEqual(rpcs, 2, "should have reloaded");
actionManager.destroy();
});
QUnit.test('selecting (no result) triggers a re-render', async function (assert) {
assert.expect(3);
const actionManager = await createActionManager({
actions: this.actions,
archs: this.archs,
data: this.data,
});
await actionManager.doAction(1);
const searchInput = actionManager.el.querySelector('.o_searchview_input');
// 'a' key to filter nothing on bar
await testUtils.fields.editInput(searchInput, 'hello there');
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'ArrowDown' });
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'ArrowRight' });
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'ArrowDown' });
assert.strictEqual(actionManager.el.querySelector('.o_searchview_autocomplete .o_selection_focus').innerText.trim(), "(no result)",
"there should be no result for 'a' in bar");
await testUtils.dom.triggerEvent(searchInput, 'keydown', { key: 'Enter' });
assert.containsNone(actionManager, '.o_searchview_facet_label');
assert.strictEqual(actionManager.el.querySelector('.o_searchview_input').value, "",
"the search input should be re-rendered");
actionManager.destroy();
});
QUnit.test('update suggested filters in autocomplete menu with Japanese IME', async function (assert) {
assert.expect(4);
// The goal here is to simulate as many events happening during an IME
// assisted composition session as possible. Some of these events are
// not handled but are triggered to ensure they do not interfere.
const TEST = "TEST";
const テスト = "テスト";
const actionManager = await createActionManager({
actions: this.actions,
archs: this.archs,
data: this.data,
});
await actionManager.doAction(1);
const searchInput = actionManager.el.querySelector('.o_searchview_input');
// Simulate typing "TEST" on search view.
for (let i = 0; i < TEST.length; i++) {
const key = TEST[i].toUpperCase();
await testUtils.dom.triggerEvent(searchInput, 'keydown',
{ key, isComposing: true });
if (i === 0) {
// Composition is initiated after the first keydown
await testUtils.dom.triggerEvent(searchInput, 'compositionstart');
}
await testUtils.dom.triggerEvent(searchInput, 'keypress',
{ key, isComposing: true });
searchInput.value = TEST.slice(0, i + 1);
await testUtils.dom.triggerEvent(searchInput, 'keyup',
{ key, isComposing: true });
await testUtils.dom.triggerEvent(searchInput, 'input',
{ inputType: 'insertCompositionText', isComposing: true });
}
assert.containsOnce(actionManager.el, '.o_searchview_autocomplete',
"should display autocomplete dropdown menu on typing something in search view"
);
assert.strictEqual(
actionManager.el.querySelector('.o_searchview_autocomplete li').innerText.trim(),
"Search Foo for: TEST",
`1st filter suggestion should be based on typed word "TEST"`
);
// Simulate soft-selection of another suggestion from IME through keyboard navigation.
await testUtils.dom.triggerEvent(searchInput, 'keydown',
{ key: 'ArrowDown', isComposing: true });
await testUtils.dom.triggerEvent(searchInput, 'keypress',
{ key: 'ArrowDown', isComposing: true });
searchInput.value = テスト;
await testUtils.dom.triggerEvent(searchInput, 'keyup',
{ key: 'ArrowDown', isComposing: true });
await testUtils.dom.triggerEvent(searchInput, 'input',
{ inputType: 'insertCompositionText', isComposing: true });
assert.strictEqual(
actionManager.el.querySelector('.o_searchview_autocomplete li').innerText.trim(),
"Search Foo for: テスト",
`1st filter suggestion should be updated with soft-selection typed word "テスト"`
);
// Simulate selection on suggestion item "TEST" from IME.
await testUtils.dom.triggerEvent(searchInput, 'keydown',
{ key: 'Enter', isComposing: true });
await testUtils.dom.triggerEvent(searchInput, 'keypress',
{ key: 'Enter', isComposing: true });
searchInput.value = TEST;
await testUtils.dom.triggerEvent(searchInput, 'keyup',
{ key: 'Enter', isComposing: true });
await testUtils.dom.triggerEvent(searchInput, 'input',
{ inputType: 'insertCompositionText', isComposing: true });
// End of the composition
await testUtils.dom.triggerEvent(searchInput, 'compositionend');
assert.strictEqual(
actionManager.el.querySelector('.o_searchview_autocomplete li').innerText.trim(),
"Search Foo for: TEST",
`1st filter suggestion should finally be updated with click selection on word "TEST" from IME`
);
actionManager.destroy();
});
QUnit.test('open search view autocomplete on paste value using mouse', async function (assert) {
assert.expect(1);
const actionManager = await createActionManager({
actions: this.actions,
archs: this.archs,
data: this.data,
});
await actionManager.doAction(1);
// Simulate paste text through the mouse.
const searchInput = actionManager.el.querySelector('.o_searchview_input');
searchInput.value = "ABC";
await testUtils.dom.triggerEvent(searchInput, 'input',
{ inputType: 'insertFromPaste' });
await testUtils.nextTick();
assert.containsOnce(actionManager, '.o_searchview_autocomplete',
"should display autocomplete dropdown menu on paste in search view");
actionManager.destroy();
});
QUnit.test('select autocompleted many2one', async function (assert) {
assert.expect(5);
const archs = Object.assign({}, this.archs, {
'partner,false,search': `
<search>
<field name="foo"/>
<field name="birthday"/>
<field name="birth_datetime"/>
<field name="bar" operator="child_of"/>
</search>`,
});
const actionManager = await createActionManager({
actions: this.actions,
archs,
data: this.data,
async mockRPC(route, { domain }) {
if (route === '/web/dataset/search_read') {
assert.step(JSON.stringify(domain));
}
return this._super(...arguments);
},
});
await actionManager.doAction(1);
await cpHelpers.editSearch(actionManager, "rec");
await testUtils.dom.click(actionManager.el.querySelector('.o_searchview_autocomplete li:last-child'));
await cpHelpers.removeFacet(actionManager, 0);
await cpHelpers.editSearch(actionManager, "rec");
await testUtils.dom.click(actionManager.el.querySelector('.o_expand'));
await testUtils.dom.click(actionManager.el.querySelector('.o_searchview_autocomplete li.o_menu_item.o_indent'));
assert.verifySteps([
'[]',
'[["bar","child_of","rec"]]', // Incomplete string -> Name search
'[]',
'[["bar","child_of",1]]', // Suggestion select -> Specific ID
]);
actionManager.destroy();
});
QUnit.test('"null" as autocomplete value', async function (assert) {
assert.expect(4);
const actionManager = await createActionManager({
actions: this.actions,
archs: this.archs,
data: this.data,
mockRPC(route, args) {
if (route === '/web/dataset/search_read') {
assert.step(JSON.stringify(args.domain));
}
return this._super(...arguments);
},
});
await actionManager.doAction(1);
await cpHelpers.editSearch(actionManager, "null");
assert.strictEqual(actionManager.$('.o_searchview_autocomplete .o_selection_focus').text(),
"Search Foo for: null");
await testUtils.dom.click(actionManager.el.querySelector('.o_searchview_autocomplete li.o_selection_focus a'));
assert.verifySteps([
JSON.stringify([]), // initial search
JSON.stringify([["foo", "ilike", "null"]]),
]);
actionManager.destroy();
});
QUnit.test('autocompletion with a boolean field', async function (assert) {
assert.expect(9);
this.archs['partner,false,search'] = '<search><field name="bool"/></search>';
const actionManager = await createActionManager({
actions: this.actions,
archs: this.archs,
data: this.data,
mockRPC(route, args) {
if (route === '/web/dataset/search_read') {
assert.step(JSON.stringify(args.domain));
}
return this._super(...arguments);
},
});
await actionManager.doAction(1);
await cpHelpers.editSearch(actionManager, "y");
assert.containsN(actionManager, '.o_searchview_autocomplete li', 2);
assert.strictEqual(actionManager.$('.o_searchview_autocomplete li:last-child').text(), "Yes");
// select "Yes"
await testUtils.dom.click(actionManager.el.querySelector('.o_searchview_autocomplete li:last-child'));
await cpHelpers.removeFacet(actionManager, 0);
await cpHelpers.editSearch(actionManager, "No");
assert.containsN(actionManager, '.o_searchview_autocomplete li', 2);
assert.strictEqual(actionManager.$('.o_searchview_autocomplete li:last-child').text(), "No");
// select "No"
await testUtils.dom.click(actionManager.el.querySelector('.o_searchview_autocomplete li:last-child'));
assert.verifySteps([
JSON.stringify([]), // initial search
JSON.stringify([["bool", "=", true]]),
JSON.stringify([]),
JSON.stringify([["bool", "=", false]]),
]);
actionManager.destroy();
});
QUnit.test("reference fields are supported in search view", async function (assert) {
assert.expect(7);
this.data.partner.fields.ref = { type: 'reference', string: "Reference" };
this.data.partner.records.forEach((record, i) => {
record.ref = `ref${String(i).padStart(3, "0")}`;
});
const archs = Object.assign({}, this.archs, {
'partner,false,search': `
<search>
<field name="ref"/>
</search>`,
});
const actionManager = await createActionManager({
actions: this.actions,
archs,
data: this.data,
async mockRPC(route, { domain }) {
if (route === '/web/dataset/search_read') {
assert.step(JSON.stringify(domain));
}
return this._super(...arguments);
}
});
await actionManager.doAction(1);
await cpHelpers.editSearch(actionManager, "ref");
await cpHelpers.validateSearch(actionManager);
assert.containsN(actionManager, ".o_data_row", 5);
await cpHelpers.removeFacet(actionManager, 0);
await cpHelpers.editSearch(actionManager, "ref002");
await cpHelpers.validateSearch(actionManager);
assert.containsOnce(actionManager, ".o_data_row");
assert.verifySteps([
'[]',
'[["ref","ilike","ref"]]',
'[]',
'[["ref","ilike","ref002"]]',
]);
actionManager.destroy();
});
QUnit.test('focus should be on search bar when switching between views', async function (assert) {
assert.expect(4);
this.actions[0].views = [[false, 'list'], [false, 'form']];
this.archs['partner,false,form'] = `
<form>
<group>
<field name="display_name"/>
</group>
</form>`;
const actionManager = await createActionManager({
actions: this.actions,
archs: this.archs,
data: this.data,
});
await actionManager.doAction(1);
assert.containsOnce(actionManager, '.o_list_view');
assert.strictEqual(document.activeElement, actionManager.el.querySelector('.o_searchview input.o_searchview_input'),
"searchview should have focus");
await testUtils.dom.click(actionManager.$('.o_list_view .o_data_cell:first'));
assert.containsOnce(actionManager, '.o_form_view');
await testUtils.dom.click(actionManager.$('.o_back_button'));
assert.strictEqual(document.activeElement, actionManager.el.querySelector('.o_searchview input.o_searchview_input'),
"searchview should have focus");
actionManager.destroy();
});
});
});
|