odoo.define("web/static/tests/views/search_panel_tests.js", function (require) { "use strict"; const FormView = require('web.FormView'); const KanbanView = require('web.KanbanView'); const ListView = require('web.ListView'); const testUtils = require('web.test_utils'); const SearchPanel = require("web/static/src/js/views/search_panel.js"); const cpHelpers = testUtils.controlPanel; const createActionManager = testUtils.createActionManager; const createView = testUtils.createView; /** * Return the list of counters displayed in the search panel (if any). * @param {Widget} view, view controller * @returns {number[]} */ function getCounters(view) { return [...view.el.querySelectorAll('.o_search_panel_counter')].map( counter => Number(counter.innerText.trim()) ); } /** * Fold/unfold the category value (with children) * @param {Widget} widget * @param {string} text * @returns {Promise} */ function toggleFold(widget, text) { const headers = [...widget.el.querySelectorAll(".o_search_panel_category_value header")]; const target = headers.find( (header) => header.innerText.trim().startsWith(text) ); return testUtils.dom.click(target); } QUnit.module('Views', { beforeEach: function () { this.data = { partner: { fields: { foo: {string: "Foo", type: 'char'}, bar: {string: "Bar", type: 'boolean'}, int_field: {string: "Int Field", type: 'integer', group_operator: 'sum'}, company_id: {string: "company", type: 'many2one', relation: 'company'}, company_ids: { string: "Companies", type: 'many2many', relation: 'company' }, category_id: { string: "category", type: 'many2one', relation: 'category' }, state: { string: "State", type: 'selection', selection: [['abc', "ABC"], ['def', "DEF"], ['ghi', "GHI"]]}, }, records: [ {id: 1, bar: true, foo: "yop", int_field: 1, company_ids: [3], company_id: 3, state: 'abc', category_id: 6}, {id: 2, bar: true, foo: "blip", int_field: 2, company_ids: [3], company_id: 5, state: 'def', category_id: 7}, {id: 3, bar: true, foo: "gnap", int_field: 4, company_ids: [], company_id: 3, state: 'ghi', category_id: 7}, {id: 4, bar: false, foo: "blip", int_field: 8, company_ids: [5], company_id: 5, state: 'ghi', category_id: 7}, ] }, company: { fields: { name: {string: "Display Name", type: 'char'}, parent_id: {string: 'Parent company', type: 'many2one', relation: 'company'}, category_id: {string: 'Category', type: 'many2one', relation: 'category'}, }, records: [ {id: 3, name: "asustek", category_id: 6}, {id: 5, name: "agrolait", category_id: 7}, ], }, category: { fields: { name: {string: "Category Name", type: 'char'}, }, records: [ {id: 6, name: "gold"}, {id: 7, name: "silver"}, ] }, }; this.actions = [{ id: 1, name: 'Partners', res_model: 'partner', type: 'ir.actions.act_window', views: [[false, 'kanban'], [false, 'list'], [false, 'pivot'], [false, 'form']], }, { id: 2, name: 'Partners', res_model: 'partner', type: 'ir.actions.act_window', views: [[false, 'form']], }]; this.archs = { 'partner,false,list': '', 'partner,false,kanban': `
`, 'partner,false,form': `