diff options
Diffstat (limited to 'addons/web/static/tests/views')
| -rw-r--r-- | addons/web/static/tests/views/abstract_controller_tests.js | 4 | ||||
| -rw-r--r-- | addons/web/static/tests/views/calendar_tests.js | 350 | ||||
| -rw-r--r-- | addons/web/static/tests/views/form_benchmarks.js | 2 | ||||
| -rw-r--r-- | addons/web/static/tests/views/form_tests.js | 1351 | ||||
| -rw-r--r-- | addons/web/static/tests/views/graph_tests.js | 71 | ||||
| -rw-r--r-- | addons/web/static/tests/views/kanban_mobile_tests.js | 24 | ||||
| -rw-r--r-- | addons/web/static/tests/views/kanban_tests.js | 1095 | ||||
| -rw-r--r-- | addons/web/static/tests/views/list_tests.js | 779 | ||||
| -rw-r--r-- | addons/web/static/tests/views/pivot_tests.js | 263 | ||||
| -rw-r--r-- | addons/web/static/tests/views/search_filters_menu_tests.js | 64 | ||||
| -rw-r--r-- | addons/web/static/tests/views/search_groupby_menu_tests.js | 45 | ||||
| -rw-r--r-- | addons/web/static/tests/views/search_view_tests.js | 196 | ||||
| -rw-r--r-- | addons/web/static/tests/views/view_dialogs_tests.js | 44 |
13 files changed, 2074 insertions, 2214 deletions
diff --git a/addons/web/static/tests/views/abstract_controller_tests.js b/addons/web/static/tests/views/abstract_controller_tests.js index c9b7daa45dc..cf5810219c7 100644 --- a/addons/web/static/tests/views/abstract_controller_tests.js +++ b/addons/web/static/tests/views/abstract_controller_tests.js @@ -64,8 +64,8 @@ odoo.define("base.abstract_controller_tests", function(require) { } } }); - view.$(".simple").click(); - view.$(".with-child span").click(); + testUtils.dom.click(view.$(".simple")); + testUtils.dom.click(view.$(".with-child span")); assert.verifySteps(["a1", "a2"]); } ); diff --git a/addons/web/static/tests/views/calendar_tests.js b/addons/web/static/tests/views/calendar_tests.js index 7ed0c3914ee..9f421e9c6e9 100644 --- a/addons/web/static/tests/views/calendar_tests.js +++ b/addons/web/static/tests/views/calendar_tests.js @@ -172,15 +172,15 @@ QUnit.module('Views', { // test view scales - assert.strictEqual(calendar.$('.fc-event').length, 9, "should display 9 events on the week (4 event + 5 days event)"); + assert.containsN(calendar, '.fc-event', 9, "should display 9 events on the week (4 event + 5 days event)"); assert.strictEqual($sidebar.find('.o_selected_range').length, 7, "week scale should highlight 7 days in mini calendar"); calendar.$buttons.find('.o_calendar_button_day').trigger('click'); // display only one day - assert.strictEqual(calendar.$('.fc-event').length, 2, "should display 2 events on the day"); + assert.containsN(calendar, '.fc-event', 2, "should display 2 events on the day"); assert.strictEqual($sidebar.find('.o_selected_range').length, 1, "should highlight the target day in mini calendar"); calendar.$buttons.find('.o_calendar_button_month').trigger('click'); // display all the month - assert.strictEqual(calendar.$('.fc-event').length, 7, "should display 7 events on the month (5 events + 2 week event - 1 'event 6' is filtered + 1 'Undefined event')"); + assert.containsN(calendar, '.fc-event', 7, "should display 7 events on the month (5 events + 2 week event - 1 'event 6' is filtered + 1 'Undefined event')"); assert.strictEqual($sidebar.find('.o_selected_range').length, 31, "month scale should highlight all days in mini calendar"); // test filters @@ -200,12 +200,12 @@ QUnit.module('Views', { assert.strictEqual($attendeesFilter.find('.o_calendar_filter_item').length, 3, "should display 3 filter items for 'attendees' who use write_model (2 saved + Everything)"); assert.ok($attendeesFilter.find('.o_field_many2one').length, "should display one2many search bar for 'attendees' filter"); - assert.strictEqual(calendar.$('.fc-event').length, 7, + assert.containsN(calendar, '.fc-event', 7, "should display 7 events ('event 5' counts for 2 because it spans two weeks and thus generate two fc-event elements)"); - calendar.$('.o_calendar_filter .custom-checkbox input').first().click(); // Disable first filter - assert.strictEqual(calendar.$('.fc-event').length, 4, "should now only display 4 event"); - calendar.$('.o_calendar_filter .custom-checkbox input').eq(1).click(); // Disable second filter - assert.strictEqual(calendar.$('.fc-event').length, 0, "should not display any event anymore"); + testUtils.dom.click(calendar.$('.o_calendar_filter .custom-checkbox input').first()); + assert.containsN(calendar, '.fc-event', 4, "should now only display 4 event"); + testUtils.dom.click(calendar.$('.o_calendar_filter .custom-checkbox input').eq(1)); + assert.containsNone(calendar, '.fc-event', "should not display any event anymore"); // test search bar in filter $sidebar.find('input[type="text"]').trigger('click'); @@ -257,12 +257,12 @@ QUnit.module('Views', { 'Meetings Test (Dec 11 – 17, 2016)', "should display the current week"); // switch to day mode - actionManager.controlPanel.$('.o_calendar_button_day').click(); + testUtils.dom.click(actionManager.controlPanel.$('.o_calendar_button_day')); assert.strictEqual(actionManager.controlPanel.$('.breadcrumb-item').text(), 'Meetings Test (December 12, 2016)', "should display the current day"); // switch to month mode - actionManager.controlPanel.$('.o_calendar_button_month').click(); + testUtils.dom.click(actionManager.controlPanel.$('.o_calendar_button_month')); assert.strictEqual(actionManager.controlPanel.$('.breadcrumb-item').text(), 'Meetings Test (December 2016)', "should display the current month"); @@ -308,7 +308,7 @@ QUnit.module('Views', { assert.ok($('.modal-body').length, "should switch the modal in edit mode"); assert.notOk($('.modal-footer button.btn:contains(Delete)').length, "formViewDialog should not have a delete button in edit mode"); - $('.modal-body input:first').val('event 4 modified').trigger('input'); + testUtils.fields.editInput($('.modal-body input:first'), 'event 4 modified'); $('.modal-footer button.btn:contains(Save)').trigger('click'); assert.notOk($('.modal-body').length, "save button should close the modal"); @@ -318,21 +318,21 @@ QUnit.module('Views', { var $cell = calendar.$('.fc-day-grid .fc-row:eq(2) .fc-day:eq(2)'); - testUtils.triggerMouseEvent($cell, "mousedown"); - testUtils.triggerMouseEvent($cell, "mouseup"); + testUtils.dom.triggerMouseEvent($cell, "mousedown"); + testUtils.dom.triggerMouseEvent($cell, "mouseup"); assert.ok($('.modal-sm').length, "should open the quick create dialog"); - $('.modal-body input:first').val('new event in quick create').trigger('input'); + testUtils.fields.editInput($('.modal-body input:first'), 'new event in quick create'); $('.modal-footer button.btn:contains(Create)').trigger('click').trigger('click'); assert.strictEqual(calendar.$('.fc-event:contains(new event in quick create)').length, 1, "should display the new record after quick create"); - assert.strictEqual(calendar.$('td.fc-event-container[colspan]').length, 2, "should the new record have only one day"); + assert.containsN(calendar, 'td.fc-event-container[colspan]', 2, "should the new record have only one day"); // create a new event, quick create only (validated by pressing enter key) - testUtils.triggerMouseEvent($cell, "mousedown"); - testUtils.triggerMouseEvent($cell, "mouseup"); + testUtils.dom.triggerMouseEvent($cell, "mousedown"); + testUtils.dom.triggerMouseEvent($cell, "mouseup"); assert.ok($('.modal-sm').length, "should open the quick create dialog"); @@ -348,12 +348,12 @@ QUnit.module('Views', { $cell = calendar.$('.fc-day-grid .fc-row:eq(4) .fc-day:eq(2)'); - testUtils.triggerMouseEvent($cell, "mousedown"); - testUtils.triggerMouseEvent($cell, "mouseup"); + testUtils.dom.triggerMouseEvent($cell, "mousedown"); + testUtils.dom.triggerMouseEvent($cell, "mouseup"); assert.strictEqual($('.modal-sm').length, 1, "should open the quick create dialog"); - $('.modal-body input:first').val('coucou').trigger('input'); + testUtils.fields.editInput($('.modal-body input:first'), 'coucou'); $('.modal-footer button.btn:contains(Edit)').trigger('click'); assert.strictEqual($('.modal-lg .o_form_view').length, 1, "should open the slow create dialog"); @@ -370,11 +370,11 @@ QUnit.module('Views', { $cell = calendar.$('.fc-day-grid .fc-row:eq(3) .fc-day:eq(2)'); - testUtils.triggerMouseEvent($cell, "mousedown"); - testUtils.triggerMouseEvent($cell.next(), "mousemove"); - testUtils.triggerMouseEvent($cell.next(), "mouseup"); + testUtils.dom.triggerMouseEvent($cell, "mousedown"); + testUtils.dom.triggerMouseEvent($cell.next(), "mousemove"); + testUtils.dom.triggerMouseEvent($cell.next(), "mouseup"); - $('.modal-dialog input:first').val('new event in quick create 2').trigger('input'); + testUtils.fields.editInput($('.modal-dialog input:first'), 'new event in quick create 2'); $('.modal-footer button.btn:contains(Edit)').trigger('click'); assert.strictEqual($('.modal-lg input:first').val(), 'new event in quick create 2', "should open the formViewDialog with default values"); @@ -384,7 +384,7 @@ QUnit.module('Views', { assert.notOk($('.modal').length, "should close dialogs"); var $newevent2 = calendar.$('.fc-event:contains(new event in quick create 2)'); assert.ok($newevent2.length, "should display the 2 days new record"); - assert.strictEqual($newevent2.closest('.fc-event-container').attr('colspan'), "2", "the new record should have 2 days"); + assert.hasAttrValue($newevent2.closest('.fc-event-container'), 'colspan', "2", "the new record should have 2 days"); // delete the a record @@ -394,11 +394,11 @@ QUnit.module('Views', { $('.modal-footer button.btn:contains(Ok)').trigger('click'); assert.notOk(calendar.$('.fc-event:contains(event 4) .fc-content').length, "the record should be deleted"); - assert.strictEqual(calendar.$('.fc-event-container .fc-event').length, 10, "should display 10 events"); + assert.containsN(calendar, '.fc-event-container .fc-event', 10, "should display 10 events"); // move to next month - calendar.$buttons.find('.o_calendar_button_next').click(); + testUtils.dom.click(calendar.$buttons.find('.o_calendar_button_next')); - assert.strictEqual(calendar.$('.fc-event-container .fc-event').length, 0, "should display 0 events"); + assert.containsNone(calendar, '.fc-event-container .fc-event', "should display 0 events"); calendar.destroy(); }); @@ -440,13 +440,13 @@ QUnit.module('Views', { // create a new event var $cell = calendar.$('.fc-day-grid .fc-row:eq(2) .fc-day:eq(2)'); - testUtils.triggerMouseEvent($cell, "mousedown"); - testUtils.triggerMouseEvent($cell, "mouseup"); + testUtils.dom.triggerMouseEvent($cell, "mousedown"); + testUtils.dom.triggerMouseEvent($cell, "mouseup"); assert.strictEqual($('.modal-sm .modal-title').text(), 'Create: Events', "should open the quick create dialog"); - $('.modal-body input:first').val('new event in quick create').trigger('input'); + testUtils.fields.editInput($('.modal-body input:first'), 'new event in quick create'); $('.modal-footer button.btn:contains(Create)').trigger('click').trigger('click'); // If the event is not default-prevented, a traceback will be raised, which we do not want @@ -515,20 +515,20 @@ QUnit.module('Views', { var left = calendar.$('.fc-day:eq(2)').offset().left + 5; try { - testUtils.triggerPositionalMouseEvent(left, top, "mousedown"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mousedown"); } catch (e) { calendar.destroy(); $view.remove(); throw new Error('The test fails to simulate a click in the screen. Your screen is probably too small or your dev tools is open.'); } - testUtils.triggerPositionalMouseEvent(left, top + 60, "mousemove"); + testUtils.dom.triggerPositionalMouseEvent(left, top + 60, "mousemove"); assert.strictEqual(calendar.$('.fc-content .fc-time').text(), "08:00 - 10:00", "should display the time in the calendar sticker"); - testUtils.triggerPositionalMouseEvent(left, top + 60, "mouseup"); - $('.modal input:first').val('new event').trigger('input'); + testUtils.dom.triggerPositionalMouseEvent(left, top + 60, "mouseup"); + testUtils.fields.editInput($('.modal input:first'), 'new event'); $('.modal button.btn:contains(Create)').trigger('click'); var $newevent = calendar.$('.fc-event:contains(new event)'); @@ -551,7 +551,7 @@ QUnit.module('Views', { $newevent.trigger('click'); $('.modal button.btn-secondary:contains(Delete)').trigger('click'); $('.modal button.btn-primary:contains(Ok)').trigger('click'); - assert.strictEqual(calendar.$('.fc-content').length, 0, "should delete the record"); + assert.containsNone(calendar, '.fc-content', "should delete the record"); calendar.destroy(); $view.remove(); @@ -624,15 +624,15 @@ QUnit.module('Views', { var left = calendar.$('.fc-day:eq(2)').offset().left + 5; try { - testUtils.triggerPositionalMouseEvent(left, top, "mousedown"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mousedown"); } catch (e) { calendar.destroy(); $view.remove(); throw new Error('The test fails to simulate a click in the screen. Your screen is probably too small or your dev tools is open.'); } - testUtils.triggerPositionalMouseEvent(left, top + 60, "mousemove"); - testUtils.triggerPositionalMouseEvent(left, top + 60, "mouseup"); - $('.modal input:first').val('new event').trigger('input'); + testUtils.dom.triggerPositionalMouseEvent(left, top + 60, "mousemove"); + testUtils.dom.triggerPositionalMouseEvent(left, top + 60, "mouseup"); + testUtils.fields.editInput($('.modal input:first'), 'new event'); $('.modal button.btn:contains(Edit)').trigger('click'); assert.strictEqual($('.o_field_widget[name="start"] input').val(), "12/13/2016 08:00:00", @@ -649,14 +649,14 @@ QUnit.module('Views', { "should display the datetime from the date with the timezone"); // use datepicker to enter a date: 12/13/2016 08:00:00 - testUtils.openDatepicker($('.o_field_widget[name="start"].o_datepicker')); + testUtils.dom.openDatepicker($('.o_field_widget[name="start"].o_datepicker')); $('.bootstrap-datetimepicker-widget .picker-switch a[data-action="togglePicker"]').trigger('click'); $('.bootstrap-datetimepicker-widget .timepicker .timepicker-hour').trigger('click'); $('.bootstrap-datetimepicker-widget .timepicker-hours td.hour:contains(08)').trigger('click'); $('.bootstrap-datetimepicker-widget .picker-switch a[data-action="close"]').trigger('click'); // use datepicker to enter a date: 12/13/2016 10:00:00 - testUtils.openDatepicker($('.o_field_widget[name="stop"].o_datepicker')); + testUtils.dom.openDatepicker($('.o_field_widget[name="stop"].o_datepicker')); $('.bootstrap-datetimepicker-widget .picker-switch a[data-action="togglePicker"]').trigger('click'); $('.bootstrap-datetimepicker-widget .timepicker .timepicker-hour').trigger('click'); $('.bootstrap-datetimepicker-widget .timepicker-hours td.hour:contains(10)').trigger('click'); @@ -689,10 +689,10 @@ QUnit.module('Views', { "start": "2016-12-12 06:00:00", "stop": "2016-12-12 08:00:00" }; - testUtils.triggerPositionalMouseEvent(left, top, "mousedown"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mousedown"); left = calendar.$('.fc-day:eq(1)').offset().left + 5; - testUtils.triggerPositionalMouseEvent(left, top, "mousemove"); - testUtils.triggerPositionalMouseEvent(left, top, "mouseup"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mousemove"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mouseup"); // Move to "All day" expectedEvent = { @@ -700,10 +700,10 @@ QUnit.module('Views', { "start": "2016-12-12 00:00:00", "stop": "2016-12-12 00:00:00" }; - testUtils.triggerPositionalMouseEvent(left, top, "mousedown"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mousedown"); top = calendar.$('.fc-day:eq(1)').offset().top + 5; - testUtils.triggerPositionalMouseEvent(left, top, "mousemove"); - testUtils.triggerPositionalMouseEvent(left, top, "mouseup"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mousemove"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mouseup"); calendar.destroy(); $view.remove(); @@ -764,20 +764,20 @@ QUnit.module('Views', { var left = calendar.$('.fc-day:eq(2)').offset().left + 5; try { - testUtils.triggerPositionalMouseEvent(left, top, "mousedown"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mousedown"); } catch (e) { calendar.destroy(); $view.remove(); throw new Error('The test fails to simulate a click in the screen. Your screen is probably too small or your dev tools is open.'); } - testUtils.triggerPositionalMouseEvent(left, top + 60, "mousemove"); + testUtils.dom.triggerPositionalMouseEvent(left, top + 60, "mousemove"); assert.strictEqual(calendar.$('.fc-content .fc-time').text(), "8:00am - 10:00am", "should display the time in the calendar sticker"); - testUtils.triggerPositionalMouseEvent(left, top + 60, "mouseup"); - $('.modal input:first').val('new event').trigger('input'); + testUtils.dom.triggerPositionalMouseEvent(left, top + 60, "mouseup"); + testUtils.fields.editInput($('.modal input:first'), 'new event'); $('.modal button.btn:contains(Create)').trigger('click'); var $newevent = calendar.$('.fc-event:contains(new event)'); @@ -800,7 +800,7 @@ QUnit.module('Views', { $newevent.trigger('click'); $('.modal button.btn-secondary:contains(Delete)').trigger('click'); $('.modal button.btn-primary:contains(Ok)').trigger('click'); - assert.strictEqual(calendar.$('.fc-content').length, 0, "should delete the record"); + assert.containsNone(calendar, '.fc-content', "should delete the record"); calendar.destroy(); $view.remove(); @@ -873,15 +873,15 @@ QUnit.module('Views', { var left = calendar.$('.fc-day:eq(2)').offset().left + 5; try { - testUtils.triggerPositionalMouseEvent(left, top, "mousedown"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mousedown"); } catch (e) { calendar.destroy(); $view.remove(); throw new Error('The test fails to simulate a click in the screen. Your screen is probably too small or your dev tools is open.'); } - testUtils.triggerPositionalMouseEvent(left, top + 60, "mousemove"); - testUtils.triggerPositionalMouseEvent(left, top + 60, "mouseup"); - $('.modal input:first').val('new event').trigger('input'); + testUtils.dom.triggerPositionalMouseEvent(left, top + 60, "mousemove"); + testUtils.dom.triggerPositionalMouseEvent(left, top + 60, "mouseup"); + testUtils.fields.editInput($('.modal input:first'), 'new event'); $('.modal button.btn:contains(Edit)').trigger('click'); assert.strictEqual($('.o_field_widget[name="start"] input').val(), "12/13/2016 08:00:00", @@ -898,14 +898,14 @@ QUnit.module('Views', { "should display the datetime from the date with the timezone"); // use datepicker to enter a date: 12/13/2016 08:00:00 - testUtils.openDatepicker($('.o_field_widget[name="start"].o_datepicker')); + testUtils.dom.openDatepicker($('.o_field_widget[name="start"].o_datepicker')); $('.bootstrap-datetimepicker-widget .picker-switch a[data-action="togglePicker"]').trigger('click'); $('.bootstrap-datetimepicker-widget .timepicker .timepicker-hour').trigger('click'); $('.bootstrap-datetimepicker-widget .timepicker-hours td.hour:contains(08)').trigger('click'); $('.bootstrap-datetimepicker-widget .picker-switch a[data-action="close"]').trigger('click'); // use datepicker to enter a date: 12/13/2016 10:00:00 - testUtils.openDatepicker($('.o_field_widget[name="stop"].o_datepicker')); + testUtils.dom.openDatepicker($('.o_field_widget[name="stop"].o_datepicker')); $('.bootstrap-datetimepicker-widget .picker-switch a[data-action="togglePicker"]').trigger('click'); $('.bootstrap-datetimepicker-widget .timepicker .timepicker-hour').trigger('click'); $('.bootstrap-datetimepicker-widget .timepicker-hours td.hour:contains(10)').trigger('click'); @@ -938,10 +938,10 @@ QUnit.module('Views', { "start": "2016-12-12 06:00:00", "stop": "2016-12-12 08:00:00" }; - testUtils.triggerPositionalMouseEvent(left, top, "mousedown"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mousedown"); left = calendar.$('.fc-day:eq(1)').offset().left + 5; - testUtils.triggerPositionalMouseEvent(left, top, "mousemove"); - testUtils.triggerPositionalMouseEvent(left, top, "mouseup"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mousemove"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mouseup"); // Move to "All day" expectedEvent = { @@ -949,10 +949,10 @@ QUnit.module('Views', { "start": "2016-12-12 00:00:00", "stop": "2016-12-12 00:00:00" }; - testUtils.triggerPositionalMouseEvent(left, top, "mousedown"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mousedown"); top = calendar.$('.fc-day:eq(1)').offset().top + 5; - testUtils.triggerPositionalMouseEvent(left, top, "mousemove"); - testUtils.triggerPositionalMouseEvent(left, top, "mouseup"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mousemove"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mouseup"); calendar.destroy(); $view.remove(); @@ -1021,23 +1021,23 @@ QUnit.module('Views', { var pos = calendar.$('.fc-bg td:eq(4)').offset(); try { - testUtils.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mousedown"); + testUtils.dom.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mousedown"); } catch (e) { calendar.destroy(); $view.remove(); throw new Error('The test fails to simulate a click in the screen. Your screen is probably too small or your dev tools is open.'); } pos = calendar.$('.fc-bg td:eq(5)').offset(); - testUtils.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mousemove"); - testUtils.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mouseup"); + testUtils.dom.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mousemove"); + testUtils.dom.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mouseup"); - $('.modal input:first').val('new event').trigger('input'); + testUtils.fields.editInput($('.modal input:first'), 'new event'); $('.modal button.btn:contains(Create)').trigger('click'); var $newevent = calendar.$('.fc-event:contains(new event)'); assert.strictEqual($newevent.text().replace(/[\s\n\r]+/g, ''), "newevent", "should display the new event with time and title"); - assert.strictEqual($newevent.parent().attr('colspan'), "2", + assert.hasAttrValue($newevent.parent(), 'colspan', "2", "should appear over two days."); assert.deepEqual($newevent.data('fcSeg').event.record, @@ -1100,15 +1100,15 @@ QUnit.module('Views', { var pos = calendar.$('.fc-bg td:eq(4)').offset(); try { - testUtils.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mousedown"); + testUtils.dom.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mousedown"); } catch (e) { calendar.destroy(); $view.remove(); throw new Error('The test fails to simulate a click in the screen. Your screen is probably too small or your dev tools is open.'); } pos = calendar.$('.fc-bg td:eq(5)').offset(); - testUtils.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mousemove"); - testUtils.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mouseup"); + testUtils.dom.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mousemove"); + testUtils.dom.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mouseup"); calendar.destroy(); $view.remove(); @@ -1159,23 +1159,23 @@ QUnit.module('Views', { var pos = calendar.$('.fc-bg td:eq(20)').offset(); try { - testUtils.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mousedown"); + testUtils.dom.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mousedown"); } catch (e) { calendar.destroy(); $view.remove(); throw new Error('The test fails to simulate a click in the screen. Your screen is probably too small or your dev tools is open.'); } pos = calendar.$('.fc-bg td:eq(21)').offset(); - testUtils.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mousemove"); - testUtils.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mouseup"); + testUtils.dom.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mousemove"); + testUtils.dom.triggerPositionalMouseEvent(pos.left+15, pos.top+15, "mouseup"); - $('.modal input:first').val('new event').trigger('input'); + testUtils.fields.editInput($('.modal input:first'), 'new event'); $('.modal button.btn:contains(Create)').trigger('click'); var $newevent = calendar.$('.fc-event:contains(new event)'); assert.strictEqual($newevent.text().replace(/[\s\n\r]+/g, ''), "newevent", "should display the new event with time and title"); - assert.strictEqual($newevent.parent().attr('colspan'), "2", + assert.hasAttrValue($newevent.parent(), 'colspan', "2", "should appear over two days."); assert.deepEqual($newevent.data('fcSeg').event.record, { @@ -1218,26 +1218,26 @@ QUnit.module('Views', { }, }); - assert.strictEqual(calendar.$('.fc-agendaWeek-view').length, 1, "should be in week mode"); - assert.strictEqual(calendar.$('.fc-event').length, 9, "should display 9 events on the week (4 event + 5 days event)"); - calendar.$('.o_calendar_mini a:contains(19)').click(); + assert.containsOnce(calendar, '.fc-agendaWeek-view', "should be in week mode"); + assert.containsN(calendar, '.fc-event', 9, "should display 9 events on the week (4 event + 5 days event)"); + testUtils.dom.click(calendar.$('.o_calendar_mini a:contains(19)')); // Clicking on a day in another week should switch to the other week view - assert.strictEqual(calendar.$('.fc-agendaWeek-view').length, 1, "should be in week mode"); - assert.strictEqual(calendar.$('.fc-event').length, 4, "should display 4 events on the week (1 event + 3 days event)"); + assert.containsOnce(calendar, '.fc-agendaWeek-view', "should be in week mode"); + assert.containsN(calendar, '.fc-event', 4, "should display 4 events on the week (1 event + 3 days event)"); // Clicking on a day in the same week should switch to that particular day view - calendar.$('.o_calendar_mini a:contains(18)').click(); - assert.strictEqual(calendar.$('.fc-agendaDay-view').length, 1, "should be in day mode"); - assert.strictEqual(calendar.$('.fc-event').length, 2, "should display 2 events on the day"); + testUtils.dom.click(calendar.$('.o_calendar_mini a:contains(18)')); + assert.containsOnce(calendar, '.fc-agendaDay-view', "should be in day mode"); + assert.containsN(calendar, '.fc-event', 2, "should display 2 events on the day"); // Clicking on the same day should toggle between day, month and week views - calendar.$('.o_calendar_mini a:contains(18)').click(); - assert.strictEqual(calendar.$('.fc-month-view').length, 1, "should be in month mode"); - assert.strictEqual(calendar.$('.fc-event').length, 7, "should display 7 events on the month (event 5 is on multiple weeks and generates to .fc-event)"); - calendar.$('.o_calendar_mini a:contains(18)').click(); - assert.strictEqual(calendar.$('.fc-agendaWeek-view').length, 1, "should be in week mode"); - assert.strictEqual(calendar.$('.fc-event').length, 4, "should display 4 events on the week (1 event + 3 days event)"); - calendar.$('.o_calendar_mini a:contains(18)').click(); - assert.strictEqual(calendar.$('.fc-agendaDay-view').length, 1, "should be in day mode"); - assert.strictEqual(calendar.$('.fc-event').length, 2, "should display 2 events on the day"); + testUtils.dom.click(calendar.$('.o_calendar_mini a:contains(18)')); + assert.containsOnce(calendar, '.fc-month-view', "should be in month mode"); + assert.containsN(calendar, '.fc-event', 7, "should display 7 events on the month (event 5 is on multiple weeks and generates to .fc-event)"); + testUtils.dom.click(calendar.$('.o_calendar_mini a:contains(18)')); + assert.containsOnce(calendar, '.fc-agendaWeek-view', "should be in week mode"); + assert.containsN(calendar, '.fc-event', 4, "should display 4 events on the week (1 event + 3 days event)"); + testUtils.dom.click(calendar.$('.o_calendar_mini a:contains(18)')); + assert.containsOnce(calendar, '.fc-agendaDay-view', "should be in day mode"); + assert.containsN(calendar, '.fc-event', 2, "should display 2 events on the day"); calendar.destroy(); }); @@ -1267,7 +1267,7 @@ QUnit.module('Views', { }, }); - assert.strictEqual(calendar.$('.o_calendar_filter_items .o_cal_avatar').length, 3, + assert.containsN(calendar, '.o_calendar_filter_items .o_cal_avatar', 3, "should have 3 avatars in the side bar"); var $event1Avatars = calendar.$('.fc-event .o_calendar_avatars').first(); @@ -1313,7 +1313,7 @@ QUnit.module('Views', { // click on an existing event to open the form view - testUtils.intercept(calendar, 'do_action', function (event) { + testUtils.mock.intercept(calendar, 'do_action', function (event) { assert.deepEqual(event.data.action, { type: "ir.actions.act_window", @@ -1330,11 +1330,11 @@ QUnit.module('Views', { // create a new event and edit it var $cell = calendar.$('.fc-day-grid .fc-row:eq(4) .fc-day:eq(2)'); - testUtils.triggerMouseEvent($cell, "mousedown"); - testUtils.triggerMouseEvent($cell, "mouseup"); - $('.modal-body input:first').val('coucou').trigger('input'); + testUtils.dom.triggerMouseEvent($cell, "mousedown"); + testUtils.dom.triggerMouseEvent($cell, "mouseup"); + testUtils.fields.editInput($('.modal-body input:first'), 'coucou'); - testUtils.intercept(calendar, 'do_action', function (event) { + testUtils.mock.intercept(calendar, 'do_action', function (event) { assert.deepEqual(event.data.action, { type: "ir.actions.act_window", @@ -1387,11 +1387,11 @@ QUnit.module('Views', { // create a new event and edit it var $cell = calendar.$('.fc-day-grid .fc-row:eq(4) .fc-day:eq(2)'); - testUtils.triggerMouseEvent($cell, "mousedown"); - testUtils.triggerMouseEvent($cell, "mouseup"); - $('.modal-body input:first').val('coucou').trigger('input'); + testUtils.dom.triggerMouseEvent($cell, "mousedown"); + testUtils.dom.triggerMouseEvent($cell, "mouseup"); + testUtils.fields.editInput($('.modal-body input:first'), 'coucou'); - testUtils.intercept(calendar, 'do_action', function (event) { + testUtils.mock.intercept(calendar, 'do_action', function (event) { assert.deepEqual(event.data.action, { type: "ir.actions.act_window", @@ -1444,11 +1444,11 @@ QUnit.module('Views', { }, }); - assert.strictEqual(calendar.$('.fc-resizer').length, 0, "should not have resize button"); + assert.containsNone(calendar, '.fc-resizer', "should not have resize button"); // click on an existing event to open the form view - testUtils.intercept(calendar, 'do_action', function (event) { + testUtils.mock.intercept(calendar, 'do_action', function (event) { assert.deepEqual(event.data.action, { type: "ir.actions.act_window", @@ -1465,11 +1465,11 @@ QUnit.module('Views', { // create a new event and edit it var $cell = calendar.$('.fc-day-grid .fc-row:eq(4) .fc-day:eq(2)'); - testUtils.triggerMouseEvent($cell, "mousedown"); - testUtils.triggerMouseEvent($cell, "mouseup"); - $('.modal-body input:first').val('coucou').trigger('input'); + testUtils.dom.triggerMouseEvent($cell, "mousedown"); + testUtils.dom.triggerMouseEvent($cell, "mouseup"); + testUtils.fields.editInput($('.modal-body input:first'), 'coucou'); - testUtils.intercept(calendar, 'do_action', function (event) { + testUtils.mock.intercept(calendar, 'do_action', function (event) { assert.deepEqual(event.data.action, { type: "ir.actions.act_window", @@ -1538,17 +1538,17 @@ QUnit.module('Views', { }, }); - assert.strictEqual(calendar.$('.fc-event').length, 9, + assert.containsN(calendar, '.fc-event', 9, "should display 9 events on the week"); // Select the events only associated with partner 2 - calendar.$('.o_calendar_filter_item[data-id=2] input').click(); - assert.strictEqual(calendar.$('.fc-event').length, 4, + testUtils.dom.click(calendar.$('.o_calendar_filter_item[data-id=2] input')); + assert.containsN(calendar, '.fc-event', 4, "should display 4 events on the week"); // Click on the 'all' filter to reload all events - calendar.$('.o_calendar_filter_item[data-value=all] input').click(); - assert.strictEqual(calendar.$('.fc-event').length, 9, + testUtils.dom.click(calendar.$('.o_calendar_filter_item[data-value=all] input')); + assert.containsN(calendar, '.fc-event', 9, "should display 9 events on the week"); calendar.destroy(); @@ -1586,29 +1586,29 @@ QUnit.module('Views', { var $view = $('#qunit-fixture').contents(); $view.prependTo('body'); // => select with click position - calendar.$('.o_calendar_filter_item[data-value=4] input').click(); + testUtils.dom.click(calendar.$('.o_calendar_filter_item[data-value=4] input')); - assert.strictEqual(calendar.$('.o_calendar_filter_item').length, 5, "should display 5 filter items"); - assert.strictEqual(calendar.$('.fc-event').length, 3, "should display 3 events"); + assert.containsN(calendar, '.o_calendar_filter_item', 5, "should display 5 filter items"); + assert.containsN(calendar, '.fc-event', 3, "should display 3 events"); // quick create a record var left = calendar.$('.fc-bg td:eq(4)').offset().left+15; var top = calendar.$('.fc-slats tr:eq(4) td:first').offset().top+15; try { - testUtils.triggerPositionalMouseEvent(left, top, "mousedown"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mousedown"); } catch (e) { calendar.destroy(); $view.remove(); throw new Error('The test fails to simulate a click in the screen. Your screen is probably too small or your dev tools is open.'); } - testUtils.triggerPositionalMouseEvent(left, top + 200, "mousemove"); - testUtils.triggerPositionalMouseEvent(left, top + 200, "mouseup"); + testUtils.dom.triggerPositionalMouseEvent(left, top + 200, "mousemove"); + testUtils.dom.triggerPositionalMouseEvent(left, top + 200, "mouseup"); - $('.modal-body input:first').val('coucou').trigger('input'); + testUtils.fields.editInput($('.modal-body input:first'), 'coucou'); $('.modal-footer button.btn:contains(Create)').trigger('click'); - assert.strictEqual(calendar.$('.o_calendar_filter_item').length, 6, "should add the missing filter (active)"); - assert.strictEqual(calendar.$('.fc-event').length, 4, "should display the created item"); + assert.containsN(calendar, '.o_calendar_filter_item', 6, "should add the missing filter (active)"); + assert.containsN(calendar, '.fc-event', 4, "should display the created item"); // change default value for quick create an hide record this.data.event.fields.user_id.default = 4; @@ -1617,19 +1617,19 @@ QUnit.module('Views', { // quick create and other record left = calendar.$('.fc-bg td:eq(3)').offset().left+15; top = calendar.$('.fc-slats tr:eq(4) td:first').offset().top+15; - testUtils.triggerPositionalMouseEvent(left, top, "mousedown"); - testUtils.triggerPositionalMouseEvent(left, top + 200, "mousemove"); - testUtils.triggerPositionalMouseEvent(left, top + 200, "mouseup"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mousedown"); + testUtils.dom.triggerPositionalMouseEvent(left, top + 200, "mousemove"); + testUtils.dom.triggerPositionalMouseEvent(left, top + 200, "mouseup"); - $('.modal-body input:first').val('coucou 2').trigger('input'); + testUtils.fields.editInput($('.modal-body input:first'), 'coucou 2'); $('.modal-footer button.btn:contains(Create)').trigger('click'); - assert.strictEqual(calendar.$('.o_calendar_filter_item').length, 6, "should have the same filters"); - assert.strictEqual(calendar.$('.fc-event').length, 4, "should not display the created item"); + assert.containsN(calendar, '.o_calendar_filter_item', 6, "should have the same filters"); + assert.containsN(calendar, '.fc-event', 4, "should not display the created item"); - calendar.$('.o_calendar_filter_item[data-value=4] input').click(); + testUtils.dom.click(calendar.$('.o_calendar_filter_item[data-value=4] input')); - assert.strictEqual(calendar.$('.fc-event').length, 11, "should display all records"); + assert.containsN(calendar, '.fc-event', 11, "should display all records"); calendar.destroy(); $view.remove(); @@ -1683,31 +1683,31 @@ QUnit.module('Views', { var $view = $('#qunit-fixture').contents(); $view.prependTo('body'); // => select with click position - calendar.$('.o_calendar_filter_item[data-value=4] input').click(); + testUtils.dom.click(calendar.$('.o_calendar_filter_item[data-value=4] input')); - assert.strictEqual(calendar.$('.o_calendar_filter_item').length, 5, "should display 5 filter items"); - assert.strictEqual(calendar.$('.fc-event').length, 3, "should display 3 events"); + assert.containsN(calendar, '.o_calendar_filter_item', 5, "should display 5 filter items"); + assert.containsN(calendar, '.fc-event', 3, "should display 3 events"); // quick create a record var left = calendar.$('.fc-bg td:eq(4)').offset().left+15; var top = calendar.$('.fc-slats tr:eq(4) td:first').offset().top+15; try { - testUtils.triggerPositionalMouseEvent(left, top, "mousedown"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mousedown"); } catch (e) { calendar.destroy(); $view.remove(); throw new Error('The test fails to simulate a click in the screen. Your screen is probably too small or your dev tools is open.'); } - testUtils.triggerPositionalMouseEvent(left, top + 200, "mousemove"); - testUtils.triggerPositionalMouseEvent(left, top + 200, "mouseup"); + testUtils.dom.triggerPositionalMouseEvent(left, top + 200, "mousemove"); + testUtils.dom.triggerPositionalMouseEvent(left, top + 200, "mouseup"); - $('.modal-body input:first').val('coucou').trigger('input'); + testUtils.fields.editInput($('.modal-body input:first'), 'coucou'); $('.modal-footer button.btn:contains(Edit)').trigger('click'); $('.modal-footer button.btn:contains(Save)').trigger('click'); - assert.strictEqual(calendar.$('.o_calendar_filter_item').length, 6, "should add the missing filter (active)"); - assert.strictEqual(calendar.$('.fc-event').length, 4, "should display the created item"); + assert.containsN(calendar, '.o_calendar_filter_item', 6, "should add the missing filter (active)"); + assert.containsN(calendar, '.fc-event', 4, "should display the created item"); calendar.destroy(); $view.remove(); @@ -1763,10 +1763,10 @@ QUnit.module('Views', { }, }); - calendar.$('.o_calendar_filter_item[data-value=4] input').click(); + testUtils.dom.click(calendar.$('.o_calendar_filter_item[data-value=4] input')); - assert.strictEqual(calendar.$('.o_calendar_filter_item').length, 5, "should display 5 filter items"); - assert.strictEqual(calendar.$('.fc-event').length, 3, "should display 3 events"); + assert.containsN(calendar, '.o_calendar_filter_item', 5, "should display 5 filter items"); + assert.containsN(calendar, '.fc-event', 3, "should display 3 events"); calendar.$('.fc-event:contains(event 2) .fc-content').trigger('click'); $('.modal button.btn:contains(Edit)').trigger('click'); @@ -1774,8 +1774,8 @@ QUnit.module('Views', { $('.ui-menu-item a:contains(user 5)').trigger('mouseenter').trigger('click'); $('.modal button.btn:contains(Save)').trigger('click'); - assert.strictEqual(calendar.$('.o_calendar_filter_item').length, 6, "should add the missing filter (active)"); - assert.strictEqual(calendar.$('.fc-event').length, 3, "should display the updated item"); + assert.containsN(calendar, '.o_calendar_filter_item', 6, "should add the missing filter (active)"); + assert.containsN(calendar, '.fc-event', 3, "should display the updated item"); calendar.destroy(); }); @@ -1842,11 +1842,11 @@ QUnit.module('Views', { }, }); - calendar.$('.o_calendar_filter_item[data-value=4] input').click(); - $('.o_calendar_button_prev').click(); + testUtils.dom.click(calendar.$('.o_calendar_filter_item[data-value=4] input')); + testUtils.dom.click($('.o_calendar_button_prev')); - assert.strictEqual(calendar.$('.o_calendar_filter_item').length, 6, "should display 6 filter items"); - assert.strictEqual(calendar.$('.fc-event').length, 2, "should display 2 events"); + assert.containsN(calendar, '.o_calendar_filter_item', 6, "should display 6 filter items"); + assert.containsN(calendar, '.fc-event', 2, "should display 2 events"); assert.strictEqual(calendar.$('.fc-event .o_field_name').text().replace(/\s/g, ''), "event7event8", "should display 2 events"); @@ -1868,10 +1868,10 @@ QUnit.module('Views', { }, }); - assert.strictEqual(calendar.$('.fc-event').length, 5, + assert.containsN(calendar, '.fc-event', 5, "should display 5 events"); - calendar.$('.o_calendar_filter_item[data-value=all] input[type=checkbox]').click(); - assert.strictEqual(calendar.$('.fc-event').length, 5, + testUtils.dom.click(calendar.$('.o_calendar_filter_item[data-value=all] input[type=checkbox]')); + assert.containsN(calendar, '.fc-event', 5, "should display 5 events"); calendar.destroy(); }); @@ -1898,8 +1898,8 @@ QUnit.module('Views', { var top = calendar.$('.fc-axis:contains(0:00)').offset().top + 5; var left = calendar.$('.fc-day:eq(2)').offset().left + 5; try { - testUtils.triggerPositionalMouseEvent(left, top, "mousedown"); - testUtils.triggerPositionalMouseEvent(left, top, "mouseup"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mousedown"); + testUtils.dom.triggerPositionalMouseEvent(left, top, "mouseup"); } catch (e) { calendar.destroy(); $view.remove(); @@ -1910,7 +1910,7 @@ QUnit.module('Views', { "should open the quick create dialog"); // Creating the event - $('.modal-body input:first').val('new event in quick create').trigger('input'); + testUtils.fields.editInput($('.modal-body input:first'), 'new event in quick create'); $('.modal-footer button.btn:contains(Create)').trigger('click').trigger('click'); assert.strictEqual(calendar.$('.fc-event:contains(new event in quick create)').length, 1, "should display the new record after quick create dialog"); @@ -1950,7 +1950,7 @@ QUnit.module('Views', { } }, }); - assert.strictEqual(calendar.$('.fc-day-grid .fc-event-container').length, 1, + assert.containsOnce(calendar, '.fc-day-grid .fc-event-container', "should be one event in the all day row"); assert.strictEqual(calendar.model.data.data[0].r_start.date(), 14, "the date should be 14"); @@ -1991,16 +1991,16 @@ QUnit.module('Views', { // create a new event var $cell = calendar.$('.fc-day-grid .fc-row:eq(2) .fc-day:eq(2)'); - testUtils.triggerMouseEvent($cell, "mousedown"); - testUtils.triggerMouseEvent($cell, "mouseup"); + testUtils.dom.triggerMouseEvent($cell, "mousedown"); + testUtils.dom.triggerMouseEvent($cell, "mouseup"); var $input = $('.modal input:first'); - $input.val('new event in quick create').trigger('input'); + testUtils.fields.editInput($input, 'new event in quick create'); // Simulate ENTER pressed on Create button (after a TAB) $input.trigger($.Event('keyup', { which: $.ui.keyCode.ENTER, keyCode: $.ui.keyCode.ENTER, })); - $('.modal-footer button:first').click(); + testUtils.dom.click($('.modal-footer button:first')); def.resolve(); assert.strictEqual(createCount, 1, "should create only one event"); @@ -2012,7 +2012,7 @@ QUnit.module('Views', { assert.expect(1); var instanceNumber = 0; - testUtils.patch(mixins.ParentedMixin, { + testUtils.mock.patch(mixins.ParentedMixin, { init: function () { instanceNumber++; return this._super.apply(this, arguments); @@ -2062,14 +2062,14 @@ QUnit.module('Views', { calendar.destroy(); - testUtils.unpatch(mixins.ParentedMixin); + testUtils.mock.unpatch(mixins.ParentedMixin); }); QUnit.test('create an event (async dialog) [REQUIRE FOCUS]', function (assert) { assert.expect(3); var def = $.Deferred(); - testUtils.patch(Dialog, { + testUtils.mock.patch(Dialog, { open: function () { var _super = this._super.bind(this); def.then(_super); @@ -2099,8 +2099,8 @@ QUnit.module('Views', { // create an event var $cell = calendar.$('.fc-day-grid .fc-row:eq(2) .fc-day:eq(2)'); - testUtils.triggerMouseEvent($cell, "mousedown"); - testUtils.triggerMouseEvent($cell, "mouseup"); + testUtils.dom.triggerMouseEvent($cell, "mousedown"); + testUtils.dom.triggerMouseEvent($cell, "mouseup"); assert.strictEqual($('.modal').length, 0, "should not have opened the dialog yet"); @@ -2113,7 +2113,7 @@ QUnit.module('Views', { "should focus the input in the dialog"); calendar.destroy(); - testUtils.unpatch(Dialog); + testUtils.mock.unpatch(Dialog); }); QUnit.test('calendar is configured to hide the groupby menu', function (assert) { @@ -2178,7 +2178,7 @@ QUnit.module('Views', { assert.strictEqual($sidebar.find('.ui-datepicker-current-day').text(), "12", "should highlight the target day"); // go to previous day - $sidebar.find('.ui-datepicker-current-day').prev().click(); + testUtils.dom.click($sidebar.find('.ui-datepicker-current-day').prev()); assert.strictEqual($sidebar.find('.ui-datepicker-current-day').text(), "11", "should highlight the selected day"); @@ -2223,10 +2223,10 @@ QUnit.module('Views', { }); var $cell = calendar.$('.fc-day-grid .fc-row:eq(2) .fc-day:eq(2)'); - testUtils.triggerMouseEvent($cell, "mousedown"); - testUtils.triggerMouseEvent($cell, "mouseup"); + testUtils.dom.triggerMouseEvent($cell, "mousedown"); + testUtils.dom.triggerMouseEvent($cell, "mouseup"); var $input = $('.modal-body input:first'); - $input.val("It's just a fleshwound").trigger('input'); + testUtils.fields.editInput($input, "It's just a fleshwound"); $('.modal button.btn:contains(Create)').trigger('click'); calendar.destroy(); @@ -2270,10 +2270,10 @@ QUnit.module('Views', { }); var $cell = calendar.$('.fc-day-grid .fc-row:eq(2) .fc-day:eq(2)'); - testUtils.triggerMouseEvent($cell, "mousedown"); - testUtils.triggerMouseEvent($cell, "mouseup"); + testUtils.dom.triggerMouseEvent($cell, "mousedown"); + testUtils.dom.triggerMouseEvent($cell, "mouseup"); var $input = $('.modal-body input:first'); - $input.val("It's just a fleshwound").trigger('input'); + testUtils.fields.editInput($input, "It's just a fleshwound"); $('.modal button.btn:contains(Create)').trigger('click'); calendar.destroy(); diff --git a/addons/web/static/tests/views/form_benchmarks.js b/addons/web/static/tests/views/form_benchmarks.js index d664859ba2f..c6127f847ec 100644 --- a/addons/web/static/tests/views/form_benchmarks.js +++ b/addons/web/static/tests/views/form_benchmarks.js @@ -85,7 +85,7 @@ QUnit.module('Form View', { '</field>' '</form>'; this.run(assert, done, function (form) { - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); form.$('.o_data_cell:first').click(); form.$('input:first').val("tralala").trigger('input'); }); diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index ada27d09afc..b73a1438f13 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -144,34 +144,25 @@ QUnit.module('Views', { '</form>', res_id: 2, }); - assert.strictEqual(form.$('div.test').length, 1, - "should contain a div with some html"); - assert.strictEqual(form.$('div.test').css('opacity'), "0.5", - "should keep the inline style on html elements"); - assert.strictEqual(form.$('label:contains(Foo)').length, 1, - "should contain label Foo"); - assert.strictEqual(form.$('span:contains(blip)').length, 1, - "should contain span with field value"); - assert.strictEqual(form.$('.o_group .o_group:first').attr('style'), 'background-color: red', - "should apply style attribute on groups"); - assert.strictEqual(form.$('.o_field_widget[name=foo]').attr('style'), 'color: blue', - "should apply style attribute on fields"); - assert.strictEqual(form.$('label:contains(something_id)').length, 0, - "should not contain f3 string description"); - assert.strictEqual(form.$('label:contains(f3_description)').length, 1, - "should contain custom f3 string description"); - assert.strictEqual(form.$('div.o_field_one2many table').length, 1, - "should render a one2many relation"); + assert.containsOnce(form, 'div.test'); + assert.strictEqual(form.$('div.test').css('opacity'), '0.5', + "should keep the inline style on html elements"); + assert.containsOnce(form, 'label:contains(Foo)'); + assert.containsOnce(form, 'span:contains(blip)'); + assert.hasAttrValue(form.$('.o_group .o_group:first'), 'style', 'background-color: red', + "should apply style attribute on groups"); + assert.hasAttrValue(form.$('.o_field_widget[name=foo]'), 'style', 'color: blue', + "should apply style attribute on fields"); + assert.containsNone(form, 'label:contains(something_id)'); + assert.containsOnce(form, 'label:contains(f3_description)'); + assert.containsOnce(form, 'div.o_field_one2many table'); + assert.containsOnce(form, 'tbody td:not(.o_list_record_selector) .custom-checkbox input:checked'); + assert.strictEqual(form.get('title'), 'second record', + "title should be display_name of record"); + assert.containsNone(form, 'label.o_form_label_empty:contains(timmy)'); - assert.strictEqual(form.$('tbody td:not(.o_list_record_selector) .custom-checkbox input:checked').length, 1, - "1 checkboxes should be checked"); - - assert.strictEqual(form.get('title'), "second record", - "title should be display_name of record"); - assert.strictEqual(form.$('label.o_form_label_empty:contains(timmy)').length, 0, - "the many2many label shouldn't be marked as empty"); form.destroy(); }); @@ -198,7 +189,7 @@ QUnit.module('Views', { '</form>', res_id: 2, }).then(function (form) { - assert.strictEqual(form.$('.o_field_widget[name=foo]').attr('style'), 'color: blue', + assert.hasAttrValue(form.$('.o_field_widget[name=foo]'), 'style', 'color: blue', "should apply style attribute on fields"); form.destroy(); delete fieldRegistry.map.asyncwidget; @@ -220,10 +211,8 @@ QUnit.module('Views', { '</form>', res_id: 2, }); - assert.ok(!form.$('span[name="display_name"]').hasClass('text-danger'), - 'field display name should not have decoration'); - assert.ok(form.$('span[name="foo"]').hasClass('text-danger'), - 'field foo should have decoration'); + assert.doesNotHaveClass(form.$('span[name="display_name"]'), 'text-danger'); + assert.hasClass(form.$('span[name="foo"]'), 'text-danger'); form.destroy(); }); @@ -241,11 +230,9 @@ QUnit.module('Views', { res_id: 2, viewOptions: {mode: 'edit'}, }); - assert.ok(!form.$('input[name="display_name"]').hasClass('text-danger'), - 'field display name should not have decoration'); - form.$('input[name="int_field"]').val(3).trigger('input'); - assert.ok(form.$('input[name="display_name"]').hasClass('text-danger'), - 'field display name should now have decoration'); + assert.doesNotHaveClass(form.$('input[name="display_name"]'), 'text-danger'); + testUtils.fields.editInput(form.$('input[name=int_field]'), 3); + assert.hasClass(form.$('input[name="display_name"]'), 'text-danger'); form.destroy(); }); @@ -262,11 +249,9 @@ QUnit.module('Views', { res_id: 2, viewOptions: {mode: 'edit'}, }); - assert.ok(!form.$('input[name="int_field"]').hasClass('text-danger'), - 'field should not have decoration'); - form.$('input[name="int_field"]').val(3).trigger('input'); - assert.ok(form.$('input[name="int_field"]').hasClass('text-danger'), - 'field should now have decoration'); + assert.doesNotHaveClass(form.$('input[name="int_field"]'), 'text-danger'); + testUtils.fields.editInput(form.$('input[name=int_field]'), 3); + assert.hasClass(form.$('input[name="int_field"]'), 'text-danger'); form.destroy(); }); @@ -311,8 +296,8 @@ QUnit.module('Views', { res_id: 1, }); - assert.strictEqual(form.$('table.o_inner_group').length, 1, - "should contain an inner group"); + assert.containsOnce(form, 'table.o_inner_group'); + form.destroy(); }); @@ -339,14 +324,10 @@ QUnit.module('Views', { res_id: 1, }); - assert.strictEqual(form.$('label.o_invisible_modifier:contains(Foo)').length, 1, - "should not contain label Foo"); - assert.strictEqual(form.$('span.o_invisible_modifier:contains(yop)').length, 1, - "should not contain span with field value"); - assert.strictEqual(form.$('.o_field_widget.o_invisible_modifier:contains(0.4)').length, 1, - "field qux should be invisible"); - assert.ok(form.$('.o_field_widget[name=p]').hasClass('o_invisible_modifier'), - "field p should be invisible"); + assert.containsOnce(form, 'label.o_invisible_modifier:contains(Foo)'); + assert.containsOnce(form, 'span.o_invisible_modifier:contains(yop)'); + assert.containsOnce(form, '.o_field_widget.o_invisible_modifier:contains(0.4)'); + assert.hasClass(form.$('.o_field_widget[name=p]'), 'o_invisible_modifier'); form.destroy(); }); @@ -375,21 +356,17 @@ QUnit.module('Views', { '</form>', res_id: 1, }); - assert.strictEqual(form.$('.o_form_statusbar.o_invisible_modifier button:contains(coucou)').length, 1, - "should not display invisible header"); - assert.strictEqual(form.$('.o_notebook li.o_invisible_modifier a:contains(invisible)').length, 1, - "should not display tab invisible"); - assert.strictEqual(form.$('table.o_inner_group.o_invisible_modifier td:contains(invgroup)').length, 1, - "should not display invisible groups"); + assert.containsOnce(form, '.o_form_statusbar.o_invisible_modifier button:contains(coucou)'); + assert.containsOnce(form, '.o_notebook li.o_invisible_modifier a:contains(invisible)'); + assert.containsOnce(form, 'table.o_inner_group.o_invisible_modifier td:contains(invgroup)'); form.destroy(); }); - QUnit.test('invisible attrs on fields are re-evaluated on field change', function (assert) { + QUnit.test('invisible attrs on fields are re-evaluated on field change', async function (assert) { assert.expect(3); // we set the value bar to simulate a falsy boolean value. this.data.partner.records[0].bar = false; - var form = createView({ View: FormView, model: 'partner', @@ -405,16 +382,14 @@ QUnit.module('Views', { res_id: 1, }); - - form.$buttons.find('.o_form_button_edit').click(); - assert.ok(form.$('.foo_field').hasClass('o_invisible_modifier'), 'should not display foo field'); - assert.ok(form.$('.bar_field').hasClass('o_invisible_modifier'), 'should not display bar field'); + testUtils.form.clickEdit(form); + assert.hasClass(form.$('.foo_field'), 'o_invisible_modifier'); + assert.hasClass(form.$('.bar_field'), 'o_invisible_modifier'); // set a value on the m2o - var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); - form.$('.o_field_many2one input').click(); - $dropdown.find('li:first()').click(); - assert.ok(!form.$('.foo_field').hasClass('o_invisible_modifier'), 'should display foo field'); + await testUtils.fields.many2one.searchAndClickItem('product_id'); + assert.doesNotHaveClass(form.$('.foo_field'), 'o_invisible_modifier'); + form.destroy(); }); @@ -444,8 +419,7 @@ QUnit.module('Views', { '</form>', res_id: 1, }).then(function (form) { - assert.ok(form.$('.o_field_widget[name="int_field"]').hasClass('o_invisible_modifier'), - 'int_field is invisible'); + assert.hasClass(form.$('.o_field_widget[name="int_field"]'), 'o_invisible_modifier'); form.destroy(); delete fieldRegistry.map.asyncwidget; }); @@ -473,10 +447,8 @@ QUnit.module('Views', { res_id: 1, }); - assert.ok(form.$('.o_notebook').hasClass('o_invisible_modifier'), - 'the notebook should handle modifiers (invisible)'); - assert.ok(form.$('.o_notebook').hasClass('new_class'), - 'the notebook should handle attributes'); + assert.hasClass(form.$('.o_notebook'), 'o_invisible_modifier'); + assert.hasClass(form.$('.o_notebook'), 'new_class'); form.destroy(); }); @@ -503,24 +475,16 @@ QUnit.module('Views', { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); - assert.ok(form.$('.o_notebook .nav .nav-link:first()').hasClass('active'), - 'first tab should be active'); - assert.ok(!form.$('.o_notebook .nav .nav-item:first()').hasClass('o_invisible_modifier'), - 'first tab should be visible'); + testUtils.form.clickEdit(form); + assert.hasClass(form.$('.o_notebook .nav .nav-link:first()'), 'active'); + assert.doesNotHaveClass(form.$('.o_notebook .nav .nav-item:first()'), 'o_invisible_modifier'); // set a value on the m2o - var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); - form.$('.o_field_many2one input').click(); - $dropdown.find('li:first()').click(); - assert.ok(!form.$('.o_notebook .nav .nav-link:first()').hasClass('active'), - 'first tab should not be active'); - assert.ok(form.$('.o_notebook .nav .nav-item:first()').hasClass('o_invisible_modifier'), - 'first tab should be invisible'); - assert.ok(form.$('.o_notebook .nav .nav-link:nth(1)').hasClass('active'), - 'second tab should be active'); - assert.ok(form.$('.o_notebook .tab-content .tab-pane:nth(1)').hasClass('active'), - 'second page should be active'); + testUtils.fields.many2one.searchAndClickItem('product_id'); + assert.doesNotHaveClass(form.$('.o_notebook .nav .nav-link:first()'), 'active'); + assert.hasClass(form.$('.o_notebook .nav .nav-item:first()'), 'o_invisible_modifier'); + assert.hasClass(form.$('.o_notebook .nav .nav-link:nth(1)'), 'active'); + assert.hasClass(form.$('.o_notebook .tab-content .tab-pane:nth(1)'), 'active'); form.destroy(); }); @@ -549,8 +513,7 @@ QUnit.module('Views', { assert.notOk(form.$('.o_notebook .nav .nav-item:first()').is(':visible'), 'first tab should be invisible'); - assert.ok(form.$('.o_notebook .nav .nav-link:nth(1)').hasClass('active'), - 'second tab should be active'); + assert.hasClass(form.$('.o_notebook .nav .nav-link:nth(1)'), 'active'); form.destroy(); }); @@ -578,10 +541,8 @@ QUnit.module('Views', { res_id: 1, }); - assert.notOk(form.$('.o_notebook .nav .nav-link:first()').hasClass('active'), - 'first tab should not active'); - assert.ok(form.$('.o_notebook .nav .nav-link:nth(1)').hasClass('active'), - 'second tab should be active'); + assert.doesNotHaveClass(form.$('.o_notebook .nav .nav-link:first()'), 'active'); + assert.hasClass(form.$('.o_notebook .nav .nav-link:nth(1)'), 'active'); form.destroy(); }); @@ -606,10 +567,10 @@ QUnit.module('Views', { res_id: 1 }); - assert.strictEqual(form.$('div.o_group:visible').length, 1, "should display the group"); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_boolean input').click(); - assert.strictEqual(form.$('div.o_group:hidden').length, 1, "should not display the group"); + assert.containsOnce(form, 'div.o_group:visible'); + testUtils.form.clickEdit(form); + testUtils.dom.click('.o_field_boolean input', form); + assert.containsOnce(form, 'div.o_group:hidden'); form.destroy(); }); @@ -633,8 +594,7 @@ QUnit.module('Views', { '</form>', }); - assert.notOk(form.$('div.hello').is(':visible'), - "attrs invisible should have been computed and applied"); + assert.isNotVisible(form.$('div.hello')); form.destroy(); }); @@ -663,16 +623,14 @@ QUnit.module('Views', { res_id: 2, }); - assert.strictEqual(form.$('button.oe_stat_button').length, 2, - "should have 2 stat buttons"); - assert.strictEqual(form.$('button.oe_stat_button.o_invisible_modifier').length, 1, - "should have 1 invisible stat buttons"); + assert.containsN(form, 'button.oe_stat_button', 2); + assert.containsOnce(form, 'button.oe_stat_button.o_invisible_modifier'); var count = 0; - testUtils.intercept(form, "execute_action", function () { + testUtils.mock.intercept(form, "execute_action", function () { count++; }); - form.$('.oe_stat_button').first().click(); + testUtils.dom.click('.oe_stat_button'); assert.strictEqual(count, 1, "should have triggered a execute action"); form.destroy(); }); @@ -695,8 +653,7 @@ QUnit.module('Views', { res_id: 2, }); - assert.strictEqual(form.$('label.o_form_label:contains(customstring)').length, 1, - "should have 1 label with correct string"); + assert.containsOnce(form, 'label.o_form_label:contains(customstring)'); form.destroy(); }); @@ -717,18 +674,18 @@ QUnit.module('Views', { '</form>', res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('span[name="foo"]').length, 1, + assert.containsOnce(form, 'span[name="foo"]', "the foo field widget should be readonly"); - form.$('.o_field_boolean input').click(); - assert.strictEqual(form.$('input[name="foo"]').length, 1, + testUtils.dom.click(form.$('.o_field_boolean input')); + assert.containsOnce(form, 'input[name="foo"]', "the foo field widget should have been rerendered to now be editable"); - form.$('.o_field_boolean input').click(); - assert.strictEqual(form.$('span[name="foo"]').length, 1, + testUtils.dom.click(form.$('.o_field_boolean input')); + assert.containsOnce(form, 'span[name="foo"]', "the foo field widget should have been rerendered to now be readonly again"); - form.$('.o_field_boolean input').click(); - assert.strictEqual(form.$('input[name="foo"]').length, 1, + testUtils.dom.click(form.$('.o_field_boolean input')); + assert.containsOnce(form, 'input[name="foo"]', "the foo field widget should have been rerendered to now be editable again"); form.destroy(); @@ -763,30 +720,30 @@ QUnit.module('Views', { res_id: 2, }); - assert.strictEqual(form.$('.o_field_widget.o_field_empty').length, 2, + assert.containsN(form, '.o_field_widget.o_field_empty', 2, "should have 2 empty fields with correct class"); - assert.strictEqual(form.$('.o_form_label_empty').length, 2, + assert.containsN(form, '.o_form_label_empty', 2, "should have 2 muted labels (for the empty fieds) in readonly"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('.o_field_empty').length, 1, + assert.containsOnce(form, '.o_field_empty', "in edit mode, only empty readonly fields should have the o_field_empty class"); - assert.strictEqual(form.$('.o_form_label_empty').length, 1, + assert.containsOnce(form, '.o_form_label_empty', "in edit mode, only labels associated to empty readonly fields should have the o_form_label_empty class"); - form.$('input[name="foo"]').val("test").trigger("input"); + testUtils.fields.editInput(form.$('input[name=foo]'), 'test'); - assert.strictEqual(form.$('.o_field_empty').length, 0, + assert.containsNone(form, '.o_field_empty', "after readonly modifier change, the o_field_empty class should have been removed"); - assert.strictEqual(form.$('.o_form_label_empty').length, 0, + assert.containsNone(form, '.o_form_label_empty', "after readonly modifier change, the o_form_label_empty class should have been removed"); - form.$('input[name="foo"]').val("hello").trigger("input"); + testUtils.fields.editInput(form.$('input[name=foo]'), 'hello'); - assert.strictEqual(form.$('.o_field_empty').length, 1, + assert.containsOnce(form, '.o_field_empty', "after value changed to false for a readonly field, the o_field_empty class should have been added"); - assert.strictEqual(form.$('.o_form_label_empty').length, 1, + assert.containsOnce(form, '.o_form_label_empty', "after value changed to false for a readonly field, the o_form_label_empty class should have been added"); form.destroy(); @@ -804,36 +761,33 @@ QUnit.module('Views', { model: 'partner', data: this.data, arch: '<form>' + - '<sheet>' + - '<group>' + - '<field name="foo"/>' + - '<field name="display_name" attrs="{\'readonly\': [[\'foo\', \'=\', \'readonly\']]}"/>' + - '</group>' + - '</sheet>' + + '<group>' + + '<field name="foo"/>' + + '<field name="display_name" attrs="{\'readonly\': [[\'foo\', \'=\', \'readonly\']]}"/>' + + '</group>' + '</form>', res_id: 2, }); - assert.strictEqual(form.$('.o_field_widget.o_field_empty').length, 2, - "should have 1 empty field with correct class"); - assert.strictEqual(form.$('.o_form_label_empty').length, 2, + assert.containsN(form, '.o_field_widget.o_field_empty', 2) + assert.containsN(form, '.o_form_label_empty', 2, "should have 1 muted label (for the empty fied) in readonly"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('.o_field_empty').length, 0, + assert.containsNone(form, '.o_field_empty', "in edit mode, only empty readonly fields should have the o_field_empty class"); - assert.strictEqual(form.$('.o_form_label_empty').length, 0, + assert.containsNone(form, '.o_form_label_empty', "in edit mode, only labels associated to empty readonly fields should have the o_form_label_empty class"); - form.$('input[name="foo"]').val("readonly").trigger("input"); // display_name is now rerendered as readonly - form.$('input[name="foo"]').val("edit").trigger("input"); // display_name is now rerendered as editable - form.$('input[name="display_name"]').val('1').trigger("input"); // display_name is now set - form.$('input[name="foo"]').val("readonly").trigger("input"); // display_name is now rerendered as readonly + testUtils.fields.editInput(form.$('input[name=foo]'), 'readonly'); + testUtils.fields.editInput(form.$('input[name=foo]'), 'edit'); + testUtils.fields.editInput(form.$('input[name=display_name]'), 'some name'); + testUtils.fields.editInput(form.$('input[name=foo]'), 'readonly'); - assert.strictEqual(form.$('.o_field_empty').length, 0, + assert.containsNone(form, '.o_field_empty', "there still should not be any empty class on fields as the readonly one is now set"); - assert.strictEqual(form.$('.o_form_label_empty').length, 0, + assert.containsNone(form, '.o_form_label_empty', "there still should not be any empty class on labels as the associated readonly field is now set"); form.destroy(); @@ -857,9 +811,9 @@ QUnit.module('Views', { '</sheet>' + '</form>', }); - assert.strictEqual(form.$('.o_form_label_empty').length, 0, + assert.containsNone(form, '.o_form_label_empty', "no empty class on label"); - assert.strictEqual(form.$('.o_field_empty').length, 0, + assert.containsNone(form, '.o_field_empty', "no empty class on field"); form.destroy(); }); @@ -871,33 +825,24 @@ QUnit.module('Views', { View: FormView, model: 'partner', data: this.data, - arch: '<form string="Partners">' + - '<sheet>' + - '<group>' + - '<field name="foo"/>' + - '</group>' + - '</sheet>' + + arch: '<form>' + + '<field name="foo"/>' + '</form>', res_id: 1, }); assert.strictEqual(form.mode, 'readonly', 'form view should be in readonly mode'); - assert.ok(form.$('.o_form_view').hasClass('o_form_readonly'), - 'form view should be .o_form_readonly'); - assert.ok(form.$buttons.find('.o_form_buttons_view').is(':visible'), - 'readonly buttons should be visible'); - assert.ok(!form.$buttons.find('.o_form_buttons_edit').is(':visible'), - 'edit buttons should not be visible'); - form.$buttons.find('.o_form_button_edit').click(); + assert.hasClass(form.$('.o_form_view'), 'o_form_readonly'); + assert.isVisible(form.$buttons.find('.o_form_buttons_view')); + assert.isNotVisible(form.$buttons.find('.o_form_buttons_edit')); + + testUtils.form.clickEdit(form); + assert.strictEqual(form.mode, 'edit', 'form view should be in edit mode'); - assert.ok(form.$('.o_form_view').hasClass('o_form_editable'), - 'form view should be .o_form_editable'); - assert.ok(!form.$('.o_form_view').hasClass('o_form_readonly'), - 'form view should not be .o_form_readonly'); - assert.ok(!form.$buttons.find('.o_form_buttons_view').is(':visible'), - 'readonly buttons should not be visible'); - assert.ok(form.$buttons.find('.o_form_buttons_edit').is(':visible'), - 'edit buttons should be visible'); + assert.hasClass(form.$('.o_form_view'), 'o_form_editable'); + assert.doesNotHaveClass(form.$('.o_form_view'), 'o_form_readonly'); + assert.isNotVisible(form.$buttons.find('.o_form_buttons_view')); + assert.isVisible(form.$buttons.find('.o_form_buttons_edit')); form.destroy(); }); @@ -918,15 +863,15 @@ QUnit.module('Views', { '</form>', res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('input[name="foo"].o_required_modifier').length, 1, + assert.containsOnce(form, 'input[name="foo"].o_required_modifier', "the foo field widget should be required"); - form.$('.o_field_boolean input').click(); - assert.strictEqual(form.$('input[name="foo"]:not(.o_required_modifier)').length, 1, + testUtils.dom.click('.o_field_boolean input'); + assert.containsOnce(form, 'input[name="foo"]:not(.o_required_modifier)', "the foo field widget should now have been marked as non-required"); - form.$('.o_field_boolean input').click(); - assert.strictEqual(form.$('input[name="foo"].o_required_modifier').length, 1, + testUtils.dom.click('.o_field_boolean input'); + assert.containsOnce(form, 'input[name="foo"].o_required_modifier', "the foo field widget should now have been marked as required again"); form.destroy(); @@ -950,12 +895,11 @@ QUnit.module('Views', { res_id: 1, }); - assert.strictEqual(form.$('span.o_required_modifier').length, 1, - "should have 1 span with o_required_modifier class"); + assert.containsOnce(form, 'span.o_required_modifier', form); - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('input.o_required_modifier').length, 1, - "in edit mode, should have 1 input with o_required_modifier"); + testUtils.form.clickEdit(form); + assert.containsOnce(form, 'input.o_required_modifier', + "in edit mode, should have 1 input with o_required_modifier"); form.destroy(); }); @@ -980,23 +924,21 @@ QUnit.module('Views', { }, }); - assert.ok(form.$('input[name="qux"]').hasClass('o_required_modifier'), - "qux input is flagged as required"); + assert.hasClass(form.$('input[name="qux"]'), 'o_required_modifier'); assert.strictEqual(form.$('input[name="qux"]').val(), "0.0", "qux input is 0 by default (float field)"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); - assert.notOk(form.$('input[name="qux"]').hasClass('o_field_invalid'), - "qux input is not displayed as invalid"); + assert.containsNone(form.$('input[name="qux"]'), "should have switched to readonly"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - form.$('input[name="qux"]').val("1").trigger('input'); + testUtils.fields.editInput(form.$('input[name=qux]'), '1'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('input[name="qux"]').val(), "1.0", "qux input is properly formatted"); @@ -1023,8 +965,7 @@ QUnit.module('Views', { res_id: 1, }); - assert.strictEqual(form.$('div.o_horizontal_separator').length, 1, - "should contain a separator div"); + assert.containsOnce(form, 'div.o_horizontal_separator'); form.destroy(); }); @@ -1045,8 +986,9 @@ QUnit.module('Views', { '</form>', res_id: 1, }); - assert.strictEqual(form.$('div.o_horizontal_separator').hasClass('o_invisible_modifier'), true, - "separator div should be hidden"); + + assert.hasClass(form.$('div.o_horizontal_separator'), 'o_invisible_modifier'); + form.destroy(); }); @@ -1062,8 +1004,9 @@ QUnit.module('Views', { arch: '<form string="Partners">' + '<field name="state" invisible="1"/>' + '<header>' + - '<button name="post" class="p" states="ab,ef" string="Confirm" type="object"/>' + + '<button name="post" class="p" string="Confirm" type="object"/>' + '<button name="some_method" class="s" string="Do it" type="object"/>' + + '<button name="some_other_method" states="ab,ef" string="Do not" type="object"/>' + '</header>' + '<sheet>' + '<group>' + @@ -1077,35 +1020,31 @@ QUnit.module('Views', { return this._super.apply(this, arguments); }, }); - assert.strictEqual(form.$('button.btn i.fa.fa-check').length, 1, - "should contain a button with correct content"); - - assert.strictEqual(form.$('.o_form_statusbar button').length, 2, - "should have 2 buttons in the statusbar"); - assert.strictEqual(form.$('button[name="post"]').length, 1, - "'name' attribute of buttons is transmitted to the rendered html element"); + assert.containsOnce(form, 'button.btn i.fa.fa-check'); + assert.containsN(form, '.o_form_statusbar button', 3); + assert.containsOnce(form, 'button.p[name="post"]:contains(Confirm)'); + assert.containsN(form, '.o_form_statusbar button:visible', 2); - assert.strictEqual(form.$('.o_form_statusbar button:visible').length, 1, - "should have only 1 visible button in the statusbar"); - - testUtils.intercept(form, 'execute_action', function (event) { - assert.strictEqual(event.data.action_data.name, "post", + testUtils.mock.intercept(form, 'execute_action', function (ev) { + assert.strictEqual(ev.data.action_data.name, 'post', "should trigger execute_action with correct method name"); - assert.deepEqual(event.data.env.currentID, 2, "should have correct id in event data"); - event.data.on_success(); - event.data.on_closed(); + assert.deepEqual(ev.data.env.currentID, 2, "should have correct id in ev data"); + ev.data.on_success(); + ev.data.on_closed(); }); rpcCount = 0; - form.$('.o_form_statusbar button.p').click(); + testUtils.dom.click('.o_form_statusbar button.p', form); assert.strictEqual(rpcCount, 1, "should have done 1 rpcs to reload"); - testUtils.intercept(form, 'execute_action', function (event) { - event.data.on_fail(); + testUtils.mock.intercept(form, 'execute_action', function (ev) { + ev.data.on_fail(); }); - form.$('.o_form_statusbar button.s').click(); + testUtils.dom.click('.o_form_statusbar button.s', form); + + assert.strictEqual(rpcCount, 1, + "should have done 1 rpc, because we do not reload anymore if the server action fails"); - assert.strictEqual(rpcCount, 1, "should have done 1 rpc, because we do not reload anymore if the server action fails"); form.destroy(); }); @@ -1142,38 +1081,22 @@ QUnit.module('Views', { res_id: 2, }); - assert.strictEqual(form.$('button[name="0"]').attr('class'), 'btn btn-secondary', - "header buttons without any class should receive the correct classes"); - assert.strictEqual(form.$('button[name="1"]').attr('class'), 'btn btn-primary', - "header buttons with bootstrap primary class should receive the correct classes"); - assert.strictEqual(form.$('button[name="2"]').attr('class'), 'btn btn-primary', - "header buttons with oe_highlight class should receive the correct classes"); - assert.strictEqual(form.$('button[name="3"]').attr('class'), 'btn btn-secondary', - "header buttons with bootstrap default class should receive the correct classes"); - assert.strictEqual(form.$('button[name="4"]').attr('class'), 'btn btn-link', - "header buttons with bootstrap link class should receive the correct classes"); - assert.strictEqual(form.$('button[name="5"]').attr('class'), 'btn btn-link', - "header buttons with oe_link class should receive the correct classes"); - assert.strictEqual(form.$('button[name="6"]').attr('class'), 'btn btn-success', - "header buttons with bootstrap state class should receive the correct classes"); - assert.strictEqual(form.$('button[name="7"]').attr('class'), 'btn o_this_is_a_button btn-secondary', - "header buttons with custom classes should receive the correct classes"); - assert.strictEqual(form.$('button[name="8"]').attr('class'), 'btn btn-secondary', - "sheet header buttons without any class should receive the correct classes"); - assert.strictEqual(form.$('button[name="9"]').attr('class'), 'btn btn-primary', - "sheet buttons with bootstrap primary class should receive the correct classes"); - assert.strictEqual(form.$('button[name="10"]').attr('class'), 'btn btn-primary', - "sheet buttons with oe_highlight class should receive the correct classes"); - assert.strictEqual(form.$('button[name="11"]').attr('class'), 'btn btn-secondary', - "sheet buttons with bootstrap default class should receive the correct classes"); - assert.strictEqual(form.$('button[name="12"]').attr('class'), 'btn btn-link', - "sheet buttons with bootstrap link class should receive the correct classes"); - assert.strictEqual(form.$('button[name="13"]').attr('class'), 'btn btn-link', - "sheet buttons with oe_link class should receive the correct classes"); - assert.strictEqual(form.$('button[name="14"]').attr('class'), 'btn btn-success', - "sheet buttons with bootstrap state class should receive the correct classes"); - assert.strictEqual(form.$('button[name="15"]').attr('class'), 'btn o_this_is_a_button', - "sheet buttons with custom classes should receive the correct classes"); + assert.hasAttrValue(form.$('button[name="0"]'), 'class', 'btn btn-secondary'); + assert.hasAttrValue(form.$('button[name="1"]'), 'class', 'btn btn-primary'); + assert.hasAttrValue(form.$('button[name="2"]'), 'class', 'btn btn-primary'); + assert.hasAttrValue(form.$('button[name="3"]'), 'class', 'btn btn-secondary'); + assert.hasAttrValue(form.$('button[name="4"]'), 'class', 'btn btn-link'); + assert.hasAttrValue(form.$('button[name="5"]'), 'class', 'btn btn-link'); + assert.hasAttrValue(form.$('button[name="6"]'), 'class', 'btn btn-success'); + assert.hasAttrValue(form.$('button[name="7"]'), 'class', 'btn o_this_is_a_button btn-secondary'); + assert.hasAttrValue(form.$('button[name="8"]'), 'class', 'btn btn-secondary'); + assert.hasAttrValue(form.$('button[name="9"]'), 'class', 'btn btn-primary'); + assert.hasAttrValue(form.$('button[name="10"]'), 'class', 'btn btn-primary'); + assert.hasAttrValue(form.$('button[name="11"]'), 'class', 'btn btn-secondary'); + assert.hasAttrValue(form.$('button[name="12"]'), 'class', 'btn btn-link'); + assert.hasAttrValue(form.$('button[name="13"]'), 'class', 'btn btn-link'); + assert.hasAttrValue(form.$('button[name="14"]'), 'class', 'btn btn-success'); + assert.hasAttrValue(form.$('button[name="15"]'), 'class', 'btn o_this_is_a_button'); form.destroy(); }); @@ -1211,14 +1134,14 @@ QUnit.module('Views', { }, }); - testUtils.intercept(form, 'execute_action', function (event) { + testUtils.mock.intercept(form, 'execute_action', function (event) { assert.step('execute_action'); assert.deepEqual(event.data.env.currentID, resID, "execute action should be done on correct record id"); event.data.on_success(); event.data.on_closed(); }); - form.$('.o_form_statusbar button.p').click(); + testUtils.dom.click('.o_form_statusbar button.p', form); assert.verifySteps(['default_get', 'create', 'read', 'execute_action', 'read']); form.destroy(); @@ -1261,14 +1184,14 @@ QUnit.module('Views', { }, }); - testUtils.intercept(form, 'execute_action', function (event) { + testUtils.mock.intercept(form, 'execute_action', function (event) { assert.step('execute_action'); assert.deepEqual(event.data.env.currentID, resID, "execute action should be done on correct record id"); event.data.on_success(); event.data.on_closed(); }); - form.$('.o_form_statusbar button.p').click(); + testUtils.dom.click('.o_form_statusbar button.p', form); assert.verifySteps(['default_get', 'create', 'read', 'execute_action', 'read']); form.destroy(); @@ -1293,17 +1216,17 @@ QUnit.module('Views', { }); assert.strictEqual(form.mode, 'readonly', 'form view should be in readonly mode'); - assert.strictEqual(form.$('span:contains(blip)').length, 1, + assert.containsOnce(form, 'span:contains(blip)', "should contain span with field value"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.mode, 'edit', 'form view should be in edit mode'); - form.$('input').val("tralala").trigger('input'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); + testUtils.form.clickSave(form); assert.strictEqual(form.mode, 'readonly', 'form view should be in readonly mode'); - assert.strictEqual(form.$('span:contains(tralala)').length, 1, + assert.containsOnce(form, 'span:contains(tralala)', "should contain span with field value"); form.destroy(); }); @@ -1327,17 +1250,16 @@ QUnit.module('Views', { res_id: 2, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('input').val("tralala").trigger('input'); - form.$buttons.find('.o_form_button_save').click(); - assert.strictEqual(form.$('span:contains(apple)').length, 1, + testUtils.form.clickEdit(form); + testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); + testUtils.form.clickSave(form); + assert.containsOnce(form, 'span:contains(apple)', "should contain span with field value"); form.destroy(); }); QUnit.test('disable buttons until reload data from server', function (assert) { assert.expect(2); - var def; var form = createView({ View: FormView, @@ -1360,22 +1282,17 @@ QUnit.module('Views', { }); var def = $.Deferred(); - form.$buttons.find('.o_form_button_edit').click(); - form.$('input').val("tralala").trigger('input'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickEdit(form); + testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); + testUtils.form.clickSave(form); // Save button should be disabled - assert.strictEqual( - form.$buttons.find('.o_form_button_save').attr('disabled'), - 'disabled', 'buttons should be disabled') - + assert.hasAttrValue(form.$buttons.find('.o_form_button_save'), 'disabled', 'disabled'); // Release the 'read' call def.resolve(); // Edit button should be enabled after the reload - assert.strictEqual( - form.$buttons.find('.o_form_button_edit').attr('disabled'), - undefined, 'buttons should be enabled') + assert.hasAttrValue(form.$buttons.find('.o_form_button_edit'), 'disabled', undefined); form.destroy(); }); @@ -1398,14 +1315,14 @@ QUnit.module('Views', { res_id: 2, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('input').eq(1).val(), "9", + assert.strictEqual(form.$('input[name=int_field]').val(), "9", "should contain input with initial value"); - form.$('input').first().val("tralala").trigger('input'); + testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); - assert.strictEqual(form.$('input').eq(1).val(), "1007", + assert.strictEqual(form.$('input[name=int_field]').val(), "1007", "should contain input with onchange applied"); form.destroy(); }); @@ -1430,15 +1347,15 @@ QUnit.module('Views', { }); - assert.strictEqual(form.$('input').val(), "9", + assert.strictEqual(form.$('input[name=int_field]').val(), "9", "should contain input with initial value"); - form.$('input').val("666").trigger('input'); + testUtils.fields.editInput(form.$('input[name=int_field]'), '666'); - assert.strictEqual(form.$('input').val(), "14", + assert.strictEqual(form.$('input[name=int_field]').val(), "14", "value should have been set to 14 by onchange"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_widget[name=int_field]').text(), "14", "value should still be 14"); @@ -1481,8 +1398,8 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('input:first').val("tralala").trigger('input'); + testUtils.form.clickEdit(form); + testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); form.destroy(); }); @@ -1519,17 +1436,17 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // add a o2m row - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click('.o_field_x2many_list_row_add a'); form.$('.o_field_one2many input:first').focus(); - form.$('.o_field_one2many input:first').val('valid line').trigger('input'); + testUtils.fields.editInput(form.$('.o_field_one2many input[name=display_name]'), 'valid line'); form.$('.o_field_one2many input:last').focus(); - form.$('.o_field_one2many input:last').val('12.4').trigger('input'); + testUtils.fields.editInput(form.$('.o_field_one2many input[name=qux]'), '12.4'); // trigger an onchange by modifying foo - form.$('input[name="foo"]:first').val("tralala").trigger('input'); + testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); form.destroy(); }); @@ -1590,12 +1507,12 @@ QUnit.module('Views', { }); var n = this.data.partner.records.length; - form.$buttons.find('.o_form_button_create').click(); + testUtils.form.clickCreate(form); assert.strictEqual(form.mode, 'edit', 'form view should be in edit mode'); assert.strictEqual(form.$('input:first').val(), "My little Foo Value", "should have correct default_get value"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.mode, 'readonly', 'form view should be in readonly mode'); assert.strictEqual(this.data.partner.records.length, n + 1, "should have created a record"); form.destroy(); @@ -1648,11 +1565,12 @@ QUnit.module('Views', { res_id: 1, }); - assert.ok(!form.sidebar.$el.hasClass('o_hidden'), 'sidebar should be visible'); - form.$buttons.find('.o_form_button_edit').click(); - assert.ok(form.sidebar.$el.hasClass('o_hidden'), 'sidebar should be invisible'); - form.$buttons.find('.o_form_button_cancel').click(); - assert.ok(!form.sidebar.$el.hasClass('o_hidden'), 'sidebar should be visible'); + assert.isVisible(form.sidebar); + testUtils.form.clickEdit(form); + assert.isNotVisible(form.sidebar); + testUtils.form.clickDiscard(form); + assert.isVisible(form.sidebar); + form.destroy(); }); @@ -1675,7 +1593,7 @@ QUnit.module('Views', { }, }); - assert.strictEqual(form.$('input').val(), "default foo value", "should have correct default"); + assert.strictEqual(form.$('input[name=foo]').val(), "default foo value", "should have correct default"); assert.strictEqual(count, 1, "should do only one rpc"); form.destroy(); }); @@ -1710,11 +1628,11 @@ QUnit.module('Views', { return this._super(route, args); }, }); - assert.ok(form.$('td:contains(new foo1)').length, + assert.containsOnce(form, 'td:contains(new foo1)', "should have new foo1 value in one2many"); - assert.ok(form.$('td:contains(new foo2)').length, + assert.containsOnce(form, 'td:contains(new foo2)', "should have new foo2 value in one2many"); - assert.ok(form.$('td:contains(xphone)').length, + assert.containsOnce(form, 'td:contains(xphone)', "should have a cell with the name field 'product_id', set to xphone"); assert.strictEqual(nameGetCount, 1, "should have done only 1 nameget"); form.destroy(); @@ -1767,7 +1685,7 @@ QUnit.module('Views', { assert.strictEqual(form.get('title'), 'first record', "should have the display name of the record as title"); - form.$buttons.find('.o_form_button_create').click(); + testUtils.form.clickCreate(form); assert.strictEqual(form.get('title'), _t("New"), "should have the display name of the record as title"); form.destroy(); @@ -1789,7 +1707,9 @@ QUnit.module('Views', { assert.strictEqual(form.get('title'), 'first record', "should have the display name of the record as title"); - form.sidebar.$('a:contains(Duplicate)').click(); + + testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + testUtils.dom.click(form.sidebar.$('a:contains(Duplicate)')); assert.strictEqual(form.get('title'), 'first record (copy)', "should have duplicated the record"); @@ -1821,7 +1741,8 @@ QUnit.module('Views', { }, }); - form.sidebar.$('a:contains(Duplicate)').click(); + testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + testUtils.dom.click(form.sidebar.$('a:contains(Duplicate)')); form.destroy(); }); @@ -1842,7 +1763,7 @@ QUnit.module('Views', { assert.strictEqual(form.get('title'), 'first record', "should have the display name of the record as title"); - assert.ok(form.sidebar.$('a:contains(Duplicate)').length === 0, + assert.containsNone(form.sidebar, 'a:contains(Duplicate)', "should not contains a 'Duplicate' action"); form.destroy(); }); @@ -1865,8 +1786,8 @@ QUnit.module('Views', { viewOptions: {footerToButtons: true}, }); - assert.ok(form.$buttons.find('button.infooter').length, "footer button should be in footer"); - assert.ok(!form.$('button.infooter').length, "footer button should not be in form"); + assert.containsOnce(form.$buttons, 'button.infooter', "footer button should be in footer"); + assert.containsNone(form, 'button.infooter', "footer button should not be in form"); form.destroy(); }); @@ -1899,20 +1820,19 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); var count = 0; - testUtils.intercept(form, "execute_action", function (event) { + testUtils.mock.intercept(form, "execute_action", function (event) { event.stopPropagation(); count++; }); - form.$('.oe_stat_button').first().click(); + testUtils.dom.click('.oe_stat_button'); assert.strictEqual(count, 1, "should have triggered a execute action"); assert.strictEqual(form.mode, "edit", "form view should be in edit mode"); - - form.$('input').val("tralala").trigger('input'); - form.$('.oe_stat_button').first().click(); + testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); + testUtils.dom.click('.oe_stat_button:first'); assert.strictEqual(form.mode, "edit", "form view should be in edit mode"); assert.strictEqual(count, 2, "should have triggered a execute action"); @@ -1952,10 +1872,10 @@ QUnit.module('Views', { assert.strictEqual(form.getTitle(), 'second record', "should have correct display_name"); - form.$buttons.find('.o_form_button_edit').click(); - form.$('input[name="name"]').val('some other name').trigger('input'); + testUtils.form.clickEdit(form); + testUtils.fields.editInput(form.$('input[name=name]'), 'some other name'); - form.$('.oe_stat_button').first().click(); + testUtils.dom.click('.oe_stat_button'); assert.strictEqual(form.getTitle(), 'GOLDORAK', "should have correct display_name"); @@ -1985,24 +1905,22 @@ QUnit.module('Views', { return this._super(route, args); } }); - testUtils.intercept(form, "execute_action", function () { + testUtils.mock.intercept(form, "execute_action", function () { executeActionCount++; }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // make the record dirty - form.$('input').val("tralala").trigger('input'); - + testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); - form.$('button').eq(0).click(); + testUtils.dom.clickFirst(form.$('button')); assert.strictEqual(writeCount, 1, "should have triggered a write"); assert.strictEqual(executeActionCount, 1, "should have triggered a execute action"); - form.$buttons.find('.o_form_button_edit').click(); - form.$('input').val("abcdef").trigger('input'); + testUtils.fields.editInput(form.$('input[name=foo]'), 'abcdef'); - form.$('button').eq(1).click(); + testUtils.dom.click(form.$('button').eq(1)); assert.strictEqual(writeCount, 1, "should not have triggered a write"); assert.strictEqual(executeActionCount, 2, "should have triggered a execute action"); @@ -2035,8 +1953,8 @@ QUnit.module('Views', { }, }); - form.$('input').val("tralala").trigger('input'); // make the record dirty - form.$('button').click(); // click on Save + testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); + testUtils.dom.click(form.$('button')); assert.verifySteps(['read', 'write', 'read', 'execute_action']); form.destroy(); @@ -2055,7 +1973,7 @@ QUnit.module('Views', { '</form>', res_id: 1, }); - assert.strictEqual(form.$('.o_field_widget').length, 1, "should have rendered an abstract field"); + assert.containsOnce(form, '.o_field_widget'); form.destroy(); }); @@ -2081,18 +1999,18 @@ QUnit.module('Views', { res_id: 1, }); - assert.strictEqual(form.$("label.o_form_label").length, 2, "should have rendered only two label"); + assert.containsN(form, "label.o_form_label", 2); assert.strictEqual(form.$("label.o_form_label").first().text(), "Product", "one should be the one for the product field"); assert.strictEqual(form.$("label.o_form_label").eq(1).text(), "Bar", "one should be the one for the bar field"); - assert.strictEqual(form.$('.firstgroup td').first().attr('colspan'), undefined, + assert.hasAttrValue(form.$('.firstgroup td').first(), 'colspan', undefined, "foo td should have a default colspan (1)"); - assert.strictEqual(form.$('.secondgroup tr').length, 2, + assert.containsN(form, '.secondgroup tr', 2, "int_field and qux should have same tr"); - assert.strictEqual(form.$('.secondgroup tr:first td').length, 2, + assert.containsN(form, '.secondgroup tr:first td', 2, "product_id field should be on its own tr"); form.destroy(); }); @@ -2116,8 +2034,7 @@ QUnit.module('Views', { '</form>', res_id: 1, }); - assert.strictEqual(form.$('td:contains(xphone)').length, 1, - "should display the name of the many2one"); + assert.containsOnce(form, 'td:contains(xphone)', "should display the name of the many2one"); form.destroy(); }); @@ -2151,18 +2068,17 @@ QUnit.module('Views', { res_id: 1, }); - assert.strictEqual(form.$('td:contains(gold)').length, 1, + assert.containsOnce(form, 'td:contains(gold)', "should display the name of the many2many on the original form"); - form.$('td:contains(gold)').click(); + testUtils.dom.click(form.$('td:contains(gold)')); - assert.strictEqual($('.modal').length, 1, - 'The partner_type modal should have opened'); - assert.strictEqual($('.modal').find('td:contains(first record)').length, 1, + assert.containsOnce(document.body, '.modal'); + assert.containsOnce($('.modal'), 'td:contains(first record)', "should display the name of the many2many on the modal form"); - $('.modal').find('td:contains(first record)').click(); - assert.strictEqual($('.modal').length, 2, - 'There should be 2 modals (partner on top of partner_type) opened'); + testUtils.dom.click('.modal td:contains(first record)'); + assert.containsN(document.body, '.modal', 2, + "there should be 2 modals (partner on top of partner_type) opened"); form.destroy(); }); @@ -2186,12 +2102,12 @@ QUnit.module('Views', { }); // switch to edit mode - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('input').val(), 'yop', 'input should contain yop'); // click on discard - form.$buttons.find('.o_form_button_cancel').click(); - assert.ok(!$('.modal:visible').length, 'no confirm modal should be displayed'); + testUtils.form.clickDiscard(form); + assert.containsNone(document.body, '.modal', 'no confirm modal should be displayed'); assert.strictEqual(form.$('.o_field_widget').text(), 'yop', 'field in readonly should display yop'); assert.strictEqual(nbWrite, 0, 'no write RPC should have been done'); @@ -2217,21 +2133,21 @@ QUnit.module('Views', { }); // switch to edit mode and edit the foo field - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('input').val(), 'yop', 'input should contain yop'); - form.$('input').val('new value').trigger('input'); + testUtils.fields.editInput(form.$('input[name=foo]'), 'new value'); assert.strictEqual(form.$('input').val(), 'new value', 'input should contain new value'); // click on discard and cancel the confirm request - form.$buttons.find('.o_form_button_cancel').click(); - assert.ok($('.modal').length, 'a confirm modal should be displayed'); - $('.modal-footer .btn-secondary').click(); // click on cancel + testUtils.form.clickDiscard(form); + assert.containsOnce(document.body, '.modal', "a confirm modal should be displayed"); + testUtils.dom.click('.modal-footer .btn-secondary'); assert.strictEqual(form.$('input').val(), 'new value', 'input should still contain new value'); // click on discard and confirm - form.$buttons.find('.o_form_button_cancel').click(); - assert.ok($('.modal').length, 'a confirm modal should be displayed'); - $('.modal-footer .btn-primary').click(); // click on confirm + testUtils.form.clickDiscard(form); + assert.containsOnce(document.body, '.modal', "a confirm modal should be displayed"); + testUtils.dom.click('.modal-footer .btn-primary'); assert.strictEqual(form.$('.o_field_widget').text(), 'yop', 'field in readonly should display yop'); assert.strictEqual(nbWrite, 0, 'no write RPC should have been done'); @@ -2263,10 +2179,11 @@ QUnit.module('Views', { // really happens (mostly because the datepicker lib need that focus // event to properly focusout the input, otherwise it crashes later on // when the 'blur' event is triggered by the re-rendering) - form.$buttons.find('.o_form_button_cancel').focus().click(); - form.$buttons.find('.o_form_button_save').focus().click(); - assert.strictEqual(form.$('span:contains(2017)').length, 1, - "should have a span with the year somewhere"); + form.$buttons.find('.o_form_button_cancel').focus(); + testUtils.dom.click('.o_form_button_cancel'); + form.$buttons.find('.o_form_button_save').focus(); + testUtils.dom.click('.o_form_button_save'); + assert.containsOnce(form, 'span:contains(2017)'); form.destroy(); }); @@ -2274,7 +2191,6 @@ QUnit.module('Views', { QUnit.test('discard changes on relational data on new record', function (assert) { assert.expect(3); - var nbWrite = 0; var form = createView({ View: FormView, model: 'partner', @@ -2286,12 +2202,6 @@ QUnit.module('Views', { '</tree>' + '</field>' + '</group></sheet></form>', - mockRPC: function (route) { - if (route === '/web/dataset/call_kw/partner/write') { - nbWrite++; - } - return this._super.apply(this, arguments); - }, intercepts: { history_back: function () { assert.ok(true, "should have sent correct event"); @@ -2304,18 +2214,16 @@ QUnit.module('Views', { }, }); - // switch to edit mode and edit the p field - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_field_many2one input').click(); - var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); - $dropdown.find('li:first()').click(); + // edit the p field + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.many2one.clickOpenDropdown('product_id'); + testUtils.fields.many2one.clickHighlightedItem('product_id'); assert.strictEqual(form.$('input').val(), 'xphone', 'input should contain xphone'); // click on discard and confirm - form.$buttons.find('.o_form_button_cancel').click(); - $('.modal-footer .btn-primary').click(); // click on confirm + testUtils.form.clickDiscard(form); + testUtils.dom.click('.modal-footer .btn-primary'); // click on confirm assert.notOk(form.$el.prop('outerHTML').match('xphone'), "the string xphone should not be present after discarding"); @@ -2339,14 +2247,12 @@ QUnit.module('Views', { } }); - // switch to edit mode and edit the foo field - form.$buttons.find('.o_form_button_edit').click(); + // edit the foo field assert.strictEqual(form.$('input').val(), 'ABC', 'input should contain ABC'); - form.$buttons.find('.o_form_button_cancel').click(); + testUtils.form.clickDiscard(form); - assert.strictEqual($('.modal').length, 0, - 'there should not be a confirm modal'); + assert.containsNone(document.body, '.modal', 'there should not be a confirm modal'); form.destroy(); }); @@ -2374,22 +2280,21 @@ QUnit.module('Views', { }); // edit the foo field - assert.strictEqual(form.$('input').val(), 'ABC', 'input should contain ABC'); - form.$('input').val('DEF').trigger('input'); + assert.strictEqual(form.$('input').val(), 'ABC', 'input should contain ABC'); + testUtils.fields.editInput(form.$('input[name=foo]'), 'DEF'); // discard the changes and check it has properly been discarded - form.$buttons.find('.o_form_button_cancel').click(); - assert.strictEqual($('.modal').length, 1, - 'there should be a confirm modal'); + testUtils.form.clickDiscard(form); + assert.containsOnce(document.body, '.modal', 'there should be a confirm modal'); assert.strictEqual(form.$('input').val(), 'DEF', 'input should be DEF'); - $('.modal-footer .btn-primary').click(); // click on confirm + testUtils.dom.click('.modal-footer .btn-primary'); // click on confirm assert.strictEqual(form.$('input').val(), 'ABC', 'input should now be ABC'); // redirty and discard the field foo (to make sure initial changes haven't been lost) - form.$('input').val('GHI').trigger('input'); - form.$buttons.find('.o_form_button_cancel').click(); + testUtils.fields.editInput(form.$('input[name=foo]'), 'GHI'); + testUtils.form.clickDiscard(form); assert.strictEqual(form.$('input').val(), 'GHI', 'input should be GHI'); - $('.modal-footer .btn-primary').click(); // click on confirm + testUtils.dom.click('.modal-footer .btn-primary') // click on confirm assert.strictEqual(form.$('input').val(), 'ABC', 'input should now be ABC'); form.destroy(); @@ -2406,19 +2311,18 @@ QUnit.module('Views', { res_id: 1, viewOptions: {hasSidebar: true}, }); + testUtils.form.clickEdit(form); + testUtils.fields.editInput(form.$('input[name=foo]'), 'tralala'); + testUtils.form.clickSave(form); - form.$buttons.find('.o_form_button_edit').click(); - form.$('input').val("tralala").trigger('input'); - form.$buttons.find('.o_form_button_save').click(); - - form.sidebar.$('a:contains(Duplicate)').click(); + testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + testUtils.dom.click(form.sidebar.$('a:contains(Duplicate)')); assert.strictEqual(form.$('input').val(), 'tralala', 'input should contain ABC'); - form.$buttons.find('.o_form_button_cancel').click(); + testUtils.form.clickDiscard(form); - assert.strictEqual($('.modal').length, 0, - 'there should not be a confirm modal'); + assert.containsNone(document.body, '.modal', 'there should not be a confirm modal'); form.destroy(); }); @@ -2449,24 +2353,24 @@ QUnit.module('Views', { assert.strictEqual(form.pager.$('.o_pager_limit').text(), "2", 'pager limit should be 2'); // switch to edit mode - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('input').val(), 'yop', 'input should contain yop'); // edit the foo field - form.$('input').val('new value').trigger('input'); + testUtils.fields.editInput(form.$('input[name=foo]'), 'new value'); assert.strictEqual(form.$('input').val(), 'new value', 'input should contain new value'); // click on the pager to switch to the next record and cancel the confirm request - form.pager.$('.o_pager_next').click(); // click on next - assert.ok($('.modal').length, 'a confirm modal should be displayed'); - $('.modal-footer .btn-secondary').click(); // click on cancel + testUtils.dom.click('.o_pager_next'); // click on next + assert.containsOnce(document.body, '.modal', 'a confirm modal should be displayed'); + testUtils.dom.click('.modal-footer .btn-secondary'); // click on cancel assert.strictEqual(form.$('input').val(), 'new value', 'input should still contain new value'); assert.strictEqual(form.pager.$('.o_pager_value').text(), "1", 'pager value should still be 1'); // click on the pager to switch to the next record and confirm - form.pager.$('.o_pager_next').click(); // click on next - assert.ok($('.modal').length, 'a confirm modal should be displayed'); - $('.modal-footer .btn-primary').click(); // click on confirm + testUtils.dom.click('.o_pager_next'); // click on next + assert.containsOnce(document.body, '.modal', 'a confirm modal should be displayed'); + testUtils.dom.click('.modal-footer .btn-primary'); // click on confirm assert.strictEqual(form.$('input').val(), 'blip', 'input should contain blip'); assert.strictEqual(form.pager.$('.o_pager_value').text(), "2", 'pager value should be 2'); @@ -2494,43 +2398,43 @@ QUnit.module('Views', { assert.strictEqual(form.pager.$('.o_pager_value').text(), "1", 'pager value should be 1'); // switch to edit mode - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('input').val(), 'yop', 'input should contain yop'); // edit the foo field - form.$('input').val('new value').trigger('input'); + testUtils.fields.editInput(form.$('input[name=foo]'), 'new value'); assert.strictEqual(form.$('input').val(), 'new value', 'input should contain new value'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); // click on the pager to switch to the next record and cancel the confirm request - form.pager.$('.o_pager_next').click(); // click on next - assert.strictEqual($('.modal:visible').length, 0, 'no confirm modal should be displayed'); + testUtils.dom.click('.o_pager_next'); // click on next + assert.containsNone(document.body, '.modal:visible', 'no confirm modal should be displayed'); assert.strictEqual(form.pager.$('.o_pager_value').text(), "2", 'pager value should be 2'); - assert.strictEqual(form.$('.o_priority .fa-star-o').length, 2, + assert.containsN(form, '.o_priority .fa-star-o', 2, 'priority widget should have been rendered with correct value'); // edit the value in readonly - form.$('.o_priority .fa-star-o:first').click(); // click on the first star - assert.strictEqual(form.$('.o_priority .fa-star').length, 1, + testUtils.dom.click(form.$('.o_priority .fa-star-o:first')); // click on the first star + assert.containsOnce(form, '.o_priority .fa-star', 'priority widget should have been updated'); - form.pager.$('.o_pager_next').click(); // click on next - assert.strictEqual($('.modal:visible').length, 0, 'no confirm modal should be displayed'); + testUtils.dom.click('.o_pager_next'); // click on next + assert.containsNone(document.body, '.modal:visible', 'no confirm modal should be displayed'); assert.strictEqual(form.pager.$('.o_pager_value').text(), "1", 'pager value should be 1'); // switch to edit mode - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('input').val(), 'new value', 'input should contain yop'); // edit the foo field - form.$('input').val('wrong value').trigger('input'); + testUtils.fields.editInput(form.$('input[name=foo]'), 'wrong value'); - form.$buttons.find('.o_form_button_cancel').click(); - assert.strictEqual($('.modal').length, 1, 'a confirm modal should be displayed'); - $('.modal-footer .btn-primary').click(); // click on confirm - form.pager.$('.o_pager_next').click(); // click on next + testUtils.form.clickDiscard(form); + assert.containsOnce(document.body, '.modal', 'a confirm modal should be displayed'); + testUtils.dom.click('.modal-footer .btn-primary'); // click on confirm + testUtils.dom.click('.o_pager_next'); // click on next assert.strictEqual(form.pager.$('.o_pager_value').text(), "2", 'pager value should be 2'); form.destroy(); }); @@ -2560,20 +2464,16 @@ QUnit.module('Views', { }); // click on second page tab - form.$('.o_notebook .nav-link:eq(1)').click(); + testUtils.dom.click(form.$('.o_notebook .nav-link:eq(1)')); - assert.notOk(form.$('.o_notebook .nav-link:eq(0)').hasClass('active'), - "first tab should not be active"); - assert.ok(form.$('.o_notebook .nav-link:eq(1)').hasClass('active'), - "second tab should be active"); + assert.doesNotHaveClass(form.$('.o_notebook .nav-link:eq(0)'), 'active'); + assert.hasClass(form.$('.o_notebook .nav-link:eq(1)'), 'active'); // click on the pager to switch to the next record - form.pager.$('.o_pager_next').click(); + testUtils.dom.click('.o_pager_next'); - assert.notOk(form.$('.o_notebook .nav-link:eq(0)').hasClass('active'), - "first tab should not be active"); - assert.ok(form.$('.o_notebook .nav-link:eq(1)').hasClass('active'), - "second tab should be active"); + assert.doesNotHaveClass(form.$('.o_notebook .nav-link:eq(0)'), 'active'); + assert.hasClass(form.$('.o_notebook .nav-link:eq(1)'), 'active'); form.destroy(); }); @@ -2594,21 +2494,22 @@ QUnit.module('Views', { }, }); - assert.ok(form.pager.$el.is(':visible'), "pager should be visible"); + assert.isVisible(form.pager); assert.strictEqual(form.pager.$('.o_pager_value').text(), "1", "current pager value should be 1"); assert.strictEqual(form.pager.$('.o_pager_limit').text(), "2", "current pager limit should be 1"); - form.$buttons.find('.o_form_button_create').click(); - assert.notOk(form.pager.$el.is(':visible'), "pager should not be visible"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickCreate(form); + assert.isNotVisible(form.pager); - assert.ok(form.pager.$el.is(':visible'), "pager should be visible"); + testUtils.form.clickSave(form); + assert.isVisible(form.pager); assert.strictEqual(form.pager.$('.o_pager_value').text(), "3", "current pager value should be 3"); assert.strictEqual(form.pager.$('.o_pager_limit').text(), "3", "current pager limit should be 3"); + form.destroy(); }); @@ -2636,7 +2537,7 @@ QUnit.module('Views', { assert.strictEqual(form.mode, 'readonly', 'form view should be in readonly mode'); assert.strictEqual(form.pager.$('.o_pager_value').text(), "1", 'pager value should be 1'); - form.pager.$('.o_pager_next').click(); // click on next + testUtils.dom.click(form.pager.$('.o_pager_next')); assert.strictEqual(form.pager.$('.o_pager_value').text(), "2", 'pager value should be 2'); assert.strictEqual(form.mode, 'readonly', 'form view should be in readonly mode'); @@ -2661,18 +2562,14 @@ QUnit.module('Views', { res_id: 1, }); - assert.strictEqual(form.$('span.foo_field').length, 1, "should have a span foo field"); - - assert.ok(!form.$('span.foo_field').is(':visible'), - "foo field should not be visible"); + assert.containsOnce(form, 'span.foo_field'); + assert.isNotVisible(form.$('span.foo_field')); - form.$buttons.find('.o_form_button_create').click(); + testUtils.form.clickCreate(form); - assert.strictEqual(form.$('input.foo_field').length, 1, - "should have a visible input for foo field"); + assert.containsOnce(form, 'input.foo_field'); + assert.isVisible(form.$('input.foo_field')); - assert.ok(form.$('input.foo_field').is(':visible'), - "foo field should be visible"); form.destroy(); }); @@ -2695,13 +2592,11 @@ QUnit.module('Views', { res_id: 1, }); - assert.strictEqual(form.$('.o_field_empty').length, 1, - 'readonly field should be invisible on an existing record'); + assert.containsOnce(form, '.o_field_empty'); - form.$buttons.find('.o_form_button_create').click(); + testUtils.form.clickCreate(form); - assert.strictEqual(form.$('.o_field_empty').length, 0, - 'readonly field should be visible on a new record'); + assert.containsNone(form, '.o_field_empty'); form.destroy(); }); @@ -2725,10 +2620,8 @@ QUnit.module('Views', { res_id: 1, }); - assert.ok(form.$('.inner_group').hasClass('o_group_col_6'), - "inner groups should have classname 'o_group_col_6'"); - assert.ok(form.$('.inner_div').hasClass('o_group_col_6'), - "divs inside groups should have classname 'o_group_col_6'"); + assert.hasClass(form.$('.inner_group'), 'o_group_col_6'), + assert.hasClass(form.$('.inner_div'), 'o_group_col_6'), form.destroy(); }); @@ -2754,14 +2647,14 @@ QUnit.module('Views', { 'should have a field with foo value for record 1'); assert.ok(!$('.modal:visible').length, 'no confirm modal should be displayed'); - // open sidebar - form.sidebar.$('button.o_dropdown_toggler_btn').click(); - form.sidebar.$('a:contains(Delete)').click(); + // open sidebar and delete + testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + testUtils.dom.click(form.sidebar.$('a:contains(Delete)')); assert.ok($('.modal').length, 'a confirm modal should be displayed'); // confirm the delete - $('.modal-footer button.btn-primary').click(); + testUtils.dom.click($('.modal-footer button.btn-primary')); assert.strictEqual(form.pager.$('.o_pager_value').text(), "1", 'pager value should be 1'); assert.strictEqual(form.pager.$('.o_pager_limit').text(), "2", 'pager limit should be 2'); @@ -2791,14 +2684,14 @@ QUnit.module('Views', { }); // open sidebar, click on delete and confirm - form.sidebar.$('button.o_dropdown_toggler_btn').click(); - form.sidebar.$('a:contains(Delete)').click(); + testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + testUtils.dom.click(form.sidebar.$('a:contains(Delete)')); - testUtils.intercept(form, 'history_back', function () { + testUtils.mock.intercept(form, 'history_back', function () { assert.step('history_back'); }); assert.strictEqual($('.modal').length, 1, 'a confirm modal should be displayed'); - $('.modal-footer button.btn-primary').click(); + testUtils.dom.click($('.modal-footer button.btn-primary')); assert.strictEqual($('.modal').length, 0, 'no confirm modal should be displayed'); assert.verifySteps(['read', 'unlink', 'history_back']); @@ -2833,15 +2726,15 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_save').click(); - assert.ok(form.$('label').hasClass('o_field_invalid'), + testUtils.form.clickSave(form); + assert.hasClass(form.$('label'),'o_field_invalid', "label should be tagged as invalid"); - assert.ok(form.$('input').hasClass('o_field_invalid'), + assert.hasClass(form.$('input'),'o_field_invalid', "input should be tagged as invalid"); - form.$('input').val("tralala").trigger('input'); + testUtils.fields.editInput(form.$('input'), "tralala"); - assert.strictEqual(form.$('.o_field_invalid').length, 0, + assert.containsNone(form, '.o_field_invalid', "nothing should be marked as invalid"); form.destroy(); }); @@ -2869,32 +2762,32 @@ QUnit.module('Views', { res_id: 1, }); - assert.strictEqual(form.$('.o_priority .o_priority_star').length, 2, + assert.containsN(form, '.o_priority .o_priority_star', 2, 'priority widget should have been rendered'); - assert.strictEqual(form.$('.o_priority .fa-star-o').length, 2, + assert.containsN(form, '.o_priority .fa-star-o', 2, 'priority widget should have been rendered with correct value'); // edit the value in readonly - form.$('.o_priority .fa-star-o:first').click(); // click on the first star + testUtils.dom.click(form.$('.o_priority .fa-star-o:first')); assert.strictEqual(nbWrite, 1, 'should have saved directly'); - assert.strictEqual(form.$('.o_priority .fa-star').length, 1, + assert.containsOnce(form, '.o_priority .fa-star', 'priority widget should have been updated'); // switch to edit mode and edit the value again - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('.o_priority .o_priority_star').length, 2, + testUtils.form.clickEdit(form); + assert.containsN(form, '.o_priority .o_priority_star', 2, 'priority widget should have been correctly rendered'); - assert.strictEqual(form.$('.o_priority .fa-star').length, 1, + assert.containsOnce(form, '.o_priority .fa-star', 'priority widget should have correct value'); - form.$('.o_priority .fa-star-o:first').click(); // click on the second star + testUtils.dom.click(form.$('.o_priority .fa-star-o:first')); assert.strictEqual(nbWrite, 1, 'should not have saved directly'); - assert.strictEqual(form.$('.o_priority .fa-star').length, 2, + assert.containsN(form, '.o_priority .fa-star', 2, 'priority widget should have been updated'); // save - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(nbWrite, 2, 'should not have saved directly'); - assert.strictEqual(form.$('.o_priority .fa-star').length, 2, + assert.containsN(form, '.o_priority .fa-star', 2, 'priority widget should have correct value'); form.destroy(); }); @@ -2936,12 +2829,12 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('input[name=int_field]').val(), '9', "'int_field' value should be 9 before the change"); - form.$('input').first().val("tralala").trigger('input'); + testUtils.fields.editInput(form.$('input').first(), "tralala"); assert.strictEqual(form.$('input[name=int_field]').val(), '10', "the onchange should have been correctly applied"); @@ -3022,9 +2915,9 @@ QUnit.module('Views', { }); // go to edit mode, click to add a record in the o2m - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); - assert.strictEqual(form.$('tr.o_data_row').length, 0, + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + assert.containsNone(form, 'tr.o_data_row', "should not have added a line"); form.destroy(); }); @@ -3095,7 +2988,7 @@ QUnit.module('Views', { assert.strictEqual(form.$('.o_stat_text.o_not_hover:contains(Production Environment)').length, 1, "button should contain correct string"); - form.$buttons.find('.o_form_button_create').click(); + testUtils.form.clickCreate(form); assert.strictEqual(form.$('.o_stat_text.o_not_hover:contains(Test Environment)').length, 1, "button should contain correct string"); @@ -3121,19 +3014,19 @@ QUnit.module('Views', { }); // readonly mode - assert.strictEqual(form.$('.oe_stat_button').length, 1, + assert.containsOnce(form, '.oe_stat_button', "button box should be displayed in readonly"); // edit mode - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('.oe_stat_button').length, 1, + assert.containsOnce(form, '.oe_stat_button', "button box should be displayed in edit on an existing record"); // create mode (leave edition first!) - form.$buttons.find('.o_form_button_cancel').click(); - form.$buttons.find('.o_form_button_create').click(); - assert.strictEqual(form.$('.oe_stat_button').length, 1, + testUtils.form.clickDiscard(form); + testUtils.form.clickCreate(form); + assert.containsOnce(form, '.oe_stat_button', "button box should be displayed when creating a new record as well"); form.destroy(); @@ -3167,14 +3060,14 @@ QUnit.module('Views', { res_id: 1, }); - assert.strictEqual(form.$('.o_field_one2many .o_data_row').length, 1, + assert.containsOnce(form, '.o_field_one2many .o_data_row', "there should be one one2many record linked at first"); assert.strictEqual(form.$('.o_field_one2many .o_data_row td:first').text(), 'aaa', "the 'display_name' of the one2many record should be correct"); // switch to edit mode - form.$buttons.find('.o_form_button_edit').click(); - form.$('input').val('let us trigger an onchange').trigger('input'); + testUtils.form.clickEdit(form); + testUtils.fields.editInput(form.$('input'), 'let us trigger an onchange'); var $o2m = form.$('.o_field_one2many'); assert.strictEqual($o2m.find('.o_data_row').length, 2, "there should be two linked record"); @@ -3218,9 +3111,9 @@ QUnit.module('Views', { }); assert.strictEqual($('div[name="p"] .o_data_row td').text().trim(), "aaaNo records", "should have proper initial content"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - form.$('input').val("tralala").trigger('input'); + testUtils.fields.editInput(form.$('input'), "tralala"); assert.strictEqual($('div[name="p"] .o_data_row td').text().trim(), "goldNo records", "should have proper initial content"); @@ -3246,19 +3139,19 @@ QUnit.module('Views', { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_data_cell').first().click(); // edit first row - form.$('input').val('').trigger('input'); - form.$('.fa-trash-o').eq(1).click(); // delete second row + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_data_cell').first()); + testUtils.fields.editInput(form.$('input'), ''); + testUtils.dom.click(form.$('.fa-trash-o').eq(1)); assert.strictEqual($('.modal').find('.modal-title').first().text(), "Warning", "Clicking out of a dirty line while editing should trigger a warning modal."); - $('.modal').find('.btn-primary').click(); // discard changes + testUtils.dom.click($('.modal').find('.btn-primary')); assert.strictEqual(form.$('.o_data_cell').first().text(), "first record", "Value should have been reset to what it was before editing began."); - assert.strictEqual(form.$('.o_data_row').length, 1, + assert.containsOnce(form, '.o_data_row', "The other line should have been deleted."); form.destroy(); }); @@ -3303,12 +3196,12 @@ QUnit.module('Views', { res_id: 2, }); - assert.strictEqual(form.$('.o_field_many2many .o_data_row').length, 0, + assert.containsNone(form, '.o_field_many2many .o_data_row', "there should be no many2many record linked at first"); // switch to edit mode - form.$buttons.find('.o_form_button_edit').click(); - form.$('input').val('let us trigger an onchange').trigger('input'); + testUtils.form.clickEdit(form); + testUtils.fields.editInput(form.$('input'), 'let us trigger an onchange'); var $m2m = form.$('.o_field_many2many'); assert.strictEqual($m2m.find('.o_data_row').length, 2, "there should be two linked records"); @@ -3317,7 +3210,7 @@ QUnit.module('Views', { assert.strictEqual($m2m.find('.o_data_row:nth(1) td:first').text(), 'silver', "the 'display_name' of the second m2m record should be correctly displayed"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.verifySteps(['read', 'onchange', 'read', 'write', 'read', 'read']); @@ -3400,12 +3293,12 @@ QUnit.module('Views', { }); // trigger the onchange - form.$('.o_field_widget[name=foo]').val("coucou").trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name=foo]'), "coucou"); // open a subrecord and trigger an onchange readInModal = true; - form.$('.o_data_row .o_data_cell:first').click(); - $('.modal .o_field_widget[name=name]').val("new name").trigger('input'); + testUtils.dom.click(form.$('.o_data_row .o_data_cell:first')); + testUtils.fields.editInput($('.modal .o_field_widget[name=name]'), "new name"); form.destroy(); }); @@ -3443,7 +3336,7 @@ QUnit.module('Views', { assert.strictEqual(form.$('.o_field_widget[name=datetime]').text(), '12/12/2016 12:55:05', "the initial datetime should be correct"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_field_widget[name=date] input').val(), '01/25/2017', "the initial date should be correct in edit"); @@ -3451,7 +3344,7 @@ QUnit.module('Views', { '12/12/2016 12:55:05', "the initial datetime should be correct in edit"); // trigger the onchange - form.$('.o_field_widget[name="foo"]').val("coucou").trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name="foo"]'), "coucou"); assert.strictEqual(form.$('.o_field_widget[name=date] input').val(), '12/12/2021', "the initial date should be correct in edit"); @@ -3495,18 +3388,18 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - form.$('input').first().val("1").trigger('input'); + testUtils.fields.editInput(form.$('input').first(), "1"); assert.strictEqual(onchangeNbr, 0, "no onchange has been called yet"); - form.$('input').first().val("12").trigger('input'); + testUtils.fields.editInput(form.$('input').first(), "12"); assert.strictEqual(onchangeNbr, 0, "no onchange has been called yet"); return waitForFinishedOnChange().then(function () { assert.strictEqual(onchangeNbr, 1, "one onchange has been called"); // add something in the input, then focus another input - form.$('input').first().val("123").trigger('input'); + testUtils.fields.editInput(form.$('input').first(), "123"); form.$('input').first().change(); assert.strictEqual(onchangeNbr, 2, "one onchange has been called immediately"); @@ -3550,22 +3443,22 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // edit int_field, and check that an onchange has been applied - form.$('input[name="int_field"]').val("123").trigger('input'); + testUtils.fields.editInput(form.$('input[name="int_field"]'), "123"); assert.strictEqual(form.$('input[name="foo"]').val(), "123", "the onchange has been applied"); // enter an invalid value in a float, and check that no onchange has // been applied - form.$('input[name="int_field"]').val("123a").trigger('input'); + testUtils.fields.editInput(form.$('input[name="int_field"]'), "123a"); assert.strictEqual(form.$('input[name="foo"]').val(), "123", "the onchange has not been applied"); // save, and check that the int_field input is marked as invalid - form.$buttons.find('.o_form_button_save').click(); - assert.ok(form.$('input[name="int_field"]').hasClass('o_field_invalid'), + testUtils.form.clickSave(form); + assert.hasClass(form.$('input[name="int_field"]'),'o_field_invalid', "input int_field is marked as invalid"); assert.verifySteps(['read', 'onchange']); @@ -3590,7 +3483,7 @@ QUnit.module('Views', { } } }); - form.$('.o_form_button_update').click(); + testUtils.dom.click(form.$('.o_form_button_update')); }); QUnit.test('onchanges that complete after discarding', function (assert) { @@ -3626,14 +3519,14 @@ QUnit.module('Views', { // go into edit mode assert.strictEqual(form.$('span[name="foo"]').text(), "blip", "field foo should be displayed to initial value"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // edit a value - form.$('input').first().val("1234").trigger('input'); + testUtils.fields.editInput(form.$('input').first(), "1234"); // discard changes - form.$buttons.find('.o_form_button_cancel').click(); - $('.modal-footer .btn-primary').click(); + testUtils.form.clickDiscard(form); + testUtils.dom.click($('.modal-footer .btn-primary')); assert.strictEqual(form.$('span[name="foo"]').text(), "blip", "field foo should still be displayed to initial value"); @@ -3670,10 +3563,10 @@ QUnit.module('Views', { }, }); - form.$('input').val("1234").trigger('input'); + testUtils.fields.editInput(form.$('input'), "1234"); // save the value and discard directly - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); form.discardChanges(); // Simulate click on breadcrumb assert.strictEqual(form.$('.o_field_widget[name="foo"]').val(), "1234", @@ -3727,8 +3620,8 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('input:first').val('trigger an onchange').trigger('input'); + testUtils.form.clickEdit(form); + testUtils.fields.editInput(form.$('input:first'), 'trigger an onchange'); form.destroy(); }); @@ -3788,13 +3681,13 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('input:first').val('trigger an onchange').trigger('input'); + testUtils.form.clickEdit(form); + testUtils.fields.editInput(form.$('input:first'), 'trigger an onchange'); assert.strictEqual(form.$('.o_data_row td:first').text(), 'foo changed', "onchange should have been correctly applied on field in o2m list"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); form.destroy(); }); @@ -3844,17 +3737,17 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_data_row td:first').text(), 'My little Foo Value', "the initial value should be the default one"); - form.$('input:first').val('trigger an onchange').trigger('input'); + testUtils.fields.editInput(form.$('input:first'), 'trigger an onchange'); assert.strictEqual(form.$('.o_data_row td:first').text(), 'foo changed', "onchange should have been correctly applied on field in o2m list"); - form.$('.o_data_row').click(); // edit the o2m in the dialog + testUtils.dom.click(form.$('.o_data_row')); assert.strictEqual($('.modal .modal-title').text().trim(), 'Open: one2many field', "the field string is displayed in the modal title"); assert.strictEqual($('.modal .o_field_widget').val(), 'foo changed', @@ -3892,19 +3785,19 @@ QUnit.module('Views', { res_id: 2, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_data_row td:first').text(), 'My little Foo Value', "the initial value should be the default one"); - form.$('.o_data_row td:nth(1)').click(); // edit the o2m inline - form.$('.o_data_row input:nth(1)').val(77).trigger('input'); + testUtils.dom.click(form.$('.o_data_row td:nth(1)')); + testUtils.fields.editInput(form.$('.o_data_row input:nth(1)'), 77); assert.strictEqual(form.$('.o_data_row input:first').val(), '[blip] 77', "onchange should have been correctly applied"); // create a new o2m record - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual(form.$('.o_data_row input:first').val(), '[blip] 14', "onchange should have been correctly applied after default get"); @@ -3943,26 +3836,26 @@ QUnit.module('Views', { res_id: 2, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('.o_data_row td:first').text(), 'My little Foo Value', "the initial value should be the default one"); - form.$('.o_data_row td:first').click(); // edit the o2m in a dialog - $('.modal input:nth(1)').val(77).trigger('input'); + testUtils.dom.click(form.$('.o_data_row td:first')); + testUtils.fields.editInput($('.modal input:nth(1)'), 77); assert.strictEqual($('.modal input:first').val(), '[blip] 77', "onchange should have been correctly applied"); - $('.modal-footer .btn-primary').click(); // save the dialog + testUtils.dom.click($('.modal-footer .btn-primary')); assert.strictEqual(form.$('.o_data_row td:first').text(), '[blip] 77', "onchange should have been correctly applied"); // create a new o2m record - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual($('.modal .modal-title').text().trim(), 'Create custom label', "the custom field label is applied in the modal title"); assert.strictEqual($('.modal input:first').val(), '[blip] 14', "onchange should have been correctly applied after default get"); - $('.modal-footer .btn-primary').click(); // save the dialog + testUtils.dom.clickFirst($('.modal-footer .btn-primary')); assert.strictEqual(form.$('.o_data_row:nth(1) td:first').text(), '[blip] 14', "onchange should have been correctly applied after default get"); @@ -3997,8 +3890,8 @@ QUnit.module('Views', { res_id: 2, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('input:first').val('coucou').trigger('input'); + testUtils.form.clickEdit(form); + testUtils.fields.editInput(form.$('input:first'), 'coucou'); form.destroy(); }); @@ -4023,7 +3916,7 @@ QUnit.module('Views', { }); // go to edit mode - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // focus first input, trigger tab form.$('input[name="foo"]').focus(); @@ -4110,7 +4003,7 @@ QUnit.module('Views', { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); form.$('input[name="foo"]').focus(); form.$('input[name="foo"]').trigger($.Event('keydown', {which: $.ui.keyCode.TAB})); assert.strictEqual(form.$('input[name="int_field"]')[0], document.activeElement, @@ -4149,7 +4042,7 @@ QUnit.module('Views', { }, }); - form.$('.oe_stat_button').click(); + testUtils.dom.click(form.$('.oe_stat_button')); form.destroy(); }); @@ -4183,7 +4076,7 @@ QUnit.module('Views', { }, }); - form.$('.oe_stat_button').click(); + testUtils.dom.click(form.$('.oe_stat_button')); form.destroy(); }); @@ -4206,7 +4099,7 @@ QUnit.module('Views', { res_id: 2, }); - assert.strictEqual(form.$('button .o_field_widget').length, 1, + assert.containsOnce(form, 'button .o_field_widget', "a field widget should be display inside the button"); assert.strictEqual(form.$('button .o_field_widget').children().length, 2, "the field widget should have 2 children, the text and the value"); @@ -4235,9 +4128,9 @@ QUnit.module('Views', { assert.strictEqual(form.$('.oe_button_box').children().length, 2, "button box should contain two children"); - assert.strictEqual(form.$('.oe_button_box > .oe_stat_button').length, 1, + assert.containsOnce(form, '.oe_button_box > .oe_stat_button', "button box should only contain one button"); - assert.strictEqual(form.$('.oe_button_box > label').length, 1, + assert.containsOnce(form, '.oe_button_box > label', "button box should only contain one label"); form.destroy(); @@ -4309,7 +4202,7 @@ QUnit.module('Views', { return this._super.apply(this, arguments); }, }); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); form.destroy(); }); @@ -4341,13 +4234,11 @@ QUnit.module('Views', { }); // add a o2m subrecord with a m2m tag - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_many2many_tags_cell').click(); - form.$('.o_field_many2one input').click(); - var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); - $dropdown.find('li:first()').click(); // select the first tag + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.many2one.clickOpenDropdown('timmy'); + testUtils.fields.many2one.clickHighlightedItem('timmy'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); form.destroy(); }); @@ -4390,10 +4281,10 @@ QUnit.module('Views', { }); // add a o2m subrecord - form.$('.o_field_x2many_list_row_add a').click(); - $('.modal-body .o_field_one2many .o_field_x2many_list_row_add a').click(); - $('.modal-body input').val('xtv').trigger('input'); - $('.modal-footer button:first').click(); // save & close + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.dom.click($('.modal-body .o_field_one2many .o_field_x2many_list_row_add a')); + testUtils.fields.editInput($('.modal-body input'), 'xtv'); + testUtils.dom.click($('.modal-footer button:first')); assert.strictEqual($('.modal').length, 0, "dialog should be closed"); @@ -4401,7 +4292,7 @@ QUnit.module('Views', { assert.strictEqual(row.children()[0].textContent, '1 record', "the cell should contains the number of record: 1"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); form.destroy(); }); @@ -4476,13 +4367,13 @@ QUnit.module('Views', { // bar being set to true, foo shouldn't be readonly and thus its value // could be saved, even if in its field description it is readonly - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); - assert.strictEqual(form.$('input[name="foo"]').length, 1, + assert.containsOnce(form, 'input[name="foo"]', "foo field should be editable"); - form.$('input[name="foo"]').val('New foo value').trigger('input'); + testUtils.fields.editInput(form.$('input[name="foo"]'), 'New foo value'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.strictEqual(form.$('.o_field_widget[name=foo]').text(), 'New foo value', "new value for foo field should have been saved"); @@ -4520,8 +4411,7 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); form.destroy(); }); @@ -4553,7 +4443,7 @@ QUnit.module('Views', { assert.deepEqual(getVisibleButtonTexts(), ["Hello", "World"], "only the first button section should be visible"); - form.$(".o_field_boolean input").click(); + testUtils.dom.click(form.$(".o_field_boolean input")); assert.deepEqual(getVisibleButtonTexts(), ["Foo"], "only the second button section should be visible"); @@ -4588,10 +4478,10 @@ QUnit.module('Views', { }, }); - assert.strictEqual(form.$('footer').length, 0, + assert.containsNone(form, 'footer', "footer should have been moved outside of the form view"); form.reload(); - assert.strictEqual(form.$('footer').length, 0, + assert.containsNone(form, 'footer', "footer should still have been moved outside of the form view"); form.destroy(); }); @@ -4633,7 +4523,7 @@ QUnit.module('Views', { '</form>', res_id: 1, }).then(function (form) { - assert.strictEqual(form.$('.ace_editor').length, 1, + assert.containsOnce(form, '.ace_editor', "should have waited for ace to load its dependencies"); form.destroy(); done(); @@ -4689,7 +4579,7 @@ QUnit.module('Views', { var row = form.$('.o_field_one2many .o_list_view .o_data_row'); assert.strictEqual(row.children()[1].textContent, '1 record', "the cell should contains the number of record: 1"); - row.click(); + testUtils.dom.click(row); var modal_row = $('.modal-body .o_form_sheet .o_field_one2many .o_list_view .o_data_row'); assert.strictEqual(modal_row.children().length, 2, "the row should contains the 2 fields defined in the form view"); @@ -4713,7 +4603,7 @@ QUnit.module('Views', { '</form>', res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(document.activeElement, form.$('input[name="foo"]')[0], "foo field should have focus"); @@ -4736,7 +4626,7 @@ QUnit.module('Views', { '</form>', res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(document.activeElement, form.$('input[name="foo"]')[0], "foo field should have focus"); @@ -4779,7 +4669,7 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); form.destroy(); }); @@ -4870,7 +4760,7 @@ QUnit.module('Views', { }, }); var row = form.$('.o_field_one2many .o_list_view .o_data_row'); - row.click(); + testUtils.dom.click(row); assert.verifySteps(['read', 'read', 'read'], "there should be 3 read rpcs"); form.destroy(); @@ -4913,9 +4803,9 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('input[name="foo"]').val('').trigger("input"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickEdit(form); + testUtils.fields.editInput(form.$('input[name="foo"]'), ''); + testUtils.form.clickSave(form); def.resolve(); @@ -4969,14 +4859,15 @@ QUnit.module('Views', { var $customAction = $('.o_web_client .o_control_panel .btn-group .dropdown-menu:last .dropdown-item:nth(2)'); assert.strictEqual($customAction.text().trim(), 'Action partner', "the custom action should have 'Action partner' as name"); - testUtils.intercept(form, 'do_action', function (event) { + testUtils.mock.intercept(form, 'do_action', function (event) { var context = event.data.action.context.__contexts[1]; assert.strictEqual(context.active_id, 1, "the active_id shoud be 1."); assert.deepEqual(context.active_ids, [1], "the active_ids should be an array with 1 inside."); }); - $customAction.click(); + testUtils.dom.click($dropdowns); + testUtils.dom.click($customAction); form.destroy(); }); @@ -5027,9 +4918,9 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); // Open first dialog - form.$('.o_external_button').click(); + testUtils.dom.click(form.$('.o_external_button')); assert.strictEqual($('.modal').length, 1, "One FormViewDialog should be opened"); var $firstModal = $('.modal'); @@ -5039,20 +4930,20 @@ QUnit.module('Views', { "display_name should be correctly displayed"); // Open second dialog - $firstModal.find('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click($firstModal.find('.o_field_x2many_list_row_add a')); assert.strictEqual($('.modal').length, 2, "two FormViewDialogs should be opened"); var $secondModal = $('.modal:nth(1)'); // Add new value - $secondModal.find('input').val('xtv').trigger('input'); - $secondModal.find('.modal-footer button:first').click(); // Save & close + testUtils.fields.editInput($secondModal.find('input'), 'xtv'); + testUtils.dom.click($secondModal.find('.modal-footer button:first')); assert.strictEqual($('.modal').length, 1, "last opened dialog should be closed"); // Check that data in first dialog is correctly updated assert.strictEqual($firstModal.find('tr.o_data_row td').text(), 'xtv', "should have added a line with xtv as new record"); - $firstModal.find('.modal-footer button:first').click(); // Save & close + testUtils.dom.click($firstModal.find('.modal-footer button:first')); form.destroy(); }); @@ -5084,7 +4975,7 @@ QUnit.module('Views', { }, }); - form.$('input:first').click(); // trigger the name_search + testUtils.dom.click(form.$('input:first')); form.destroy(); }); @@ -5117,21 +5008,21 @@ QUnit.module('Views', { assert.strictEqual(form.$('.o_notebook .nav-item:not(.o_invisible_modifier)').length, 2, "both tabs should be visible"); - assert.ok(form.$('.o_notebook .nav-link:first').hasClass('active'), + assert.hasClass(form.$('.o_notebook .nav-link:first'),'active', "first tab should be active"); // click on the pager to switch to the next record - form.pager.$('.o_pager_next').click(); + testUtils.dom.click(form.pager.$('.o_pager_next')); assert.strictEqual(form.$('.o_notebook .nav-item:not(.o_invisible_modifier)').length, 1, "only the second tab should be visible"); - assert.ok(form.$('.o_notebook .nav-item:not(.o_invisible_modifier) .nav-link').hasClass('active'), + assert.hasClass(form.$('.o_notebook .nav-item:not(.o_invisible_modifier) .nav-link'),'active', "the visible tab should be active"); // click on the pager to switch back to the previous record - form.pager.$('.o_pager_previous').click(); + testUtils.dom.click(form.pager.$('.o_pager_previous')); assert.strictEqual(form.$('.o_notebook .nav-item:not(.o_invisible_modifier)').length, 2, "both tabs should be visible again"); - assert.ok(form.$('.o_notebook .nav-link:nth(1)').hasClass('active'), + assert.hasClass(form.$('.o_notebook .nav-link:nth(1)'),'active', "second tab should be active"); form.destroy(); @@ -5155,7 +5046,7 @@ QUnit.module('Views', { } } }); - form.$('a[type="action"]').click(); + testUtils.dom.click(form.$('a[type="action"]')); form.destroy(); }); @@ -5252,14 +5143,14 @@ QUnit.module('Views', { assert.ok(form.$('.o_field_one2many tbody tr:first td:contains(yop)').length, "record 1 should be first"); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual($('.modal').length, 1, "FormViewDialog should be opened"); - $('.modal input[name="foo"]').val('xop').trigger("input"); - $('.modal-footer button:eq(1)').click(); // Save & new - $('.modal input[name="foo"]').val('zop').trigger("input"); - $('.modal-footer button:first').click(); // Save & close + testUtils.fields.editInput($('.modal input[name="foo"]'), 'xop') + testUtils.dom.click($('.modal-footer button:eq(1)')); + testUtils.fields.editInput($('.modal input[name="foo"]'), 'zop') + testUtils.dom.click($('.modal-footer button:first')); // client-side sort assert.ok(form.$('.o_field_one2many tbody tr:eq(0) td:contains(zop)').length, @@ -5270,7 +5161,7 @@ QUnit.module('Views', { "record xop should be third"); // server-side sort - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.ok(form.$('.o_field_one2many tbody tr:eq(0) td:contains(zop)').length, "record zop should be first"); assert.ok(form.$('.o_field_one2many tbody tr:eq(1) td:contains(yop)').length, @@ -5279,10 +5170,10 @@ QUnit.module('Views', { "record xop should be third"); // client-side sort on edit - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_one2many tbody tr:eq(1) td:contains(yop)').click(); - $('.modal input[name="foo"]').val('zzz').trigger("input"); - $('.modal-footer button:first').click(); // Save + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_one2many tbody tr:eq(1) td:contains(yop)')); + testUtils.fields.editInput($('.modal input[name="foo"]'), 'zzz') + testUtils.dom.click($('.modal-footer button:first')); assert.ok(form.$('.o_field_one2many tbody tr:eq(0) td:contains(zzz)').length, "record zzz should be first"); assert.ok(form.$('.o_field_one2many tbody tr:eq(1) td:contains(zop)').length, @@ -5317,8 +5208,8 @@ QUnit.module('Views', { return this._super.apply(this, arguments); }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('div[name="trululu"] input').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('div[name="trululu"] input')); form.destroy(); }); @@ -5391,18 +5282,18 @@ QUnit.module('Views', { assert.strictEqual($group4rows.length, 3, "there should be 3 rows in .group_4"); var $group4firstRowTd = $group4rows.eq(0).children('td'); assert.strictEqual($group4firstRowTd.length, 1, "there should be 1 td in first row"); - assert.strictEqual($group4firstRowTd.attr('colspan'), "3", "the first td colspan should be 3"); + assert.hasAttrValue($group4firstRowTd, 'colspan', "3", "the first td colspan should be 3"); assert.strictEqual($group4firstRowTd.attr('style').substr(0, 9), "width: 75", "the first td should be 75% width"); assert.strictEqual($group4firstRowTd.children()[0].tagName, "DIV", "the first td should contain a div"); var $group4secondRowTds = $group4rows.eq(1).children('td'); assert.strictEqual($group4secondRowTds.length, 2, "there should be 2 tds in second row"); - assert.strictEqual($group4secondRowTds.eq(0).attr('colspan'), "2", "the first td colspan should be 2"); + assert.hasAttrValue($group4secondRowTds.eq(0), 'colspan', "2", "the first td colspan should be 2"); assert.strictEqual($group4secondRowTds.eq(0).attr('style').substr(0, 9), "width: 50", "the first td be 50% width"); - assert.strictEqual($group4secondRowTds.eq(1).attr('colspan'), undefined, "the second td colspan should be default one (1)"); + assert.hasAttrValue($group4secondRowTds.eq(1), 'colspan', undefined, "the second td colspan should be default one (1)"); assert.strictEqual($group4secondRowTds.eq(1).attr('style').substr(0, 9), "width: 25", "the second td be 75% width"); var $group4thirdRowTd = $group4rows.eq(2).children('td'); assert.strictEqual($group4thirdRowTd.length, 1, "there should be 1 td in third row"); - assert.strictEqual($group4thirdRowTd.attr('colspan'), "4", "the first td colspan should be 4"); + assert.hasAttrValue($group4thirdRowTd, 'colspan', "4", "the first td colspan should be 4"); assert.strictEqual($group4thirdRowTd.attr('style').substr(0, 10), "width: 100", "the first td should be 100% width"); // Verify .group_3 content @@ -5417,32 +5308,32 @@ QUnit.module('Views', { assert.strictEqual($fieldGroupRows.length, 5, "there should be 5 rows in .field_group"); var $fieldGroupFirstRowTds = $fieldGroupRows.eq(0).children('td'); assert.strictEqual($fieldGroupFirstRowTds.length, 2, "there should be 2 tds in first row"); - assert.ok($fieldGroupFirstRowTds.eq(0).hasClass('o_td_label'), "first td should be a label td"); - assert.strictEqual($fieldGroupFirstRowTds.eq(1).attr('colspan'), "2", "second td colspan should be given colspan (3) - 1 (label)"); + assert.hasClass($fieldGroupFirstRowTds.eq(0),'o_td_label', "first td should be a label td"); + assert.hasAttrValue($fieldGroupFirstRowTds.eq(1), 'colspan', "2", "second td colspan should be given colspan (3) - 1 (label)"); assert.strictEqual($fieldGroupFirstRowTds.eq(1).attr('style').substr(0, 10), "width: 100", "second td width should be 100%"); var $fieldGroupSecondRowTds = $fieldGroupRows.eq(1).children('td'); assert.strictEqual($fieldGroupSecondRowTds.length, 2, "there should be 2 tds in second row"); - assert.strictEqual($fieldGroupSecondRowTds.eq(0).attr('colspan'), undefined, "first td colspan should be default one (1)"); + assert.hasAttrValue($fieldGroupSecondRowTds.eq(0), 'colspan', undefined, "first td colspan should be default one (1)"); assert.strictEqual($fieldGroupSecondRowTds.eq(0).attr('style').substr(0, 9), "width: 33", "first td width should be 33.3333%"); - assert.strictEqual($fieldGroupSecondRowTds.eq(1).attr('colspan'), undefined, "second td colspan should be default one (1)"); + assert.hasAttrValue($fieldGroupSecondRowTds.eq(1), 'colspan', undefined, "second td colspan should be default one (1)"); assert.strictEqual($fieldGroupSecondRowTds.eq(1).attr('style').substr(0, 9), "width: 33", "second td width should be 33.3333%"); var $fieldGroupThirdRowTds = $fieldGroupRows.eq(2).children('td'); // new row as label/field pair colspan is greater than remaining space assert.strictEqual($fieldGroupThirdRowTds.length, 2, "there should be 2 tds in third row"); - assert.ok($fieldGroupThirdRowTds.eq(0).hasClass('o_td_label'), "first td should be a label td"); - assert.strictEqual($fieldGroupThirdRowTds.eq(1).attr('colspan'), undefined, "second td colspan should be default one (1)"); + assert.hasClass($fieldGroupThirdRowTds.eq(0),'o_td_label', "first td should be a label td"); + assert.hasAttrValue($fieldGroupThirdRowTds.eq(1), 'colspan', undefined, "second td colspan should be default one (1)"); assert.strictEqual($fieldGroupThirdRowTds.eq(1).attr('style').substr(0, 9), "width: 50", "second td should be 50% width"); var $fieldGroupFourthRowTds = $fieldGroupRows.eq(3).children('td'); assert.strictEqual($fieldGroupFourthRowTds.length, 1, "there should be 1 td in fourth row"); - assert.strictEqual($fieldGroupFourthRowTds.attr('colspan'), "3", "the td should have a colspan equal to 3"); + assert.hasAttrValue($fieldGroupFourthRowTds, 'colspan', "3", "the td should have a colspan equal to 3"); assert.strictEqual($fieldGroupFourthRowTds.attr('style').substr(0, 10), "width: 100", "the td should have 100% width"); var $fieldGroupFifthRowTds = $fieldGroupRows.eq(4).children('td'); // label/field pair can be put after the 1-colspan span assert.strictEqual($fieldGroupFifthRowTds.length, 3, "there should be 3 tds in fourth row"); assert.strictEqual($fieldGroupFifthRowTds.eq(0).attr('style').substr(0, 9), "width: 50", "the first td should 50% width"); - assert.ok($fieldGroupFifthRowTds.eq(1).hasClass('o_td_label'), "the second td should be a label td"); + assert.hasClass($fieldGroupFifthRowTds.eq(1),'o_td_label', "the second td should be a label td"); assert.strictEqual($fieldGroupFifthRowTds.eq(2).attr('style').substr(0, 9), "width: 50", "the third td should 50% width"); // Verify that one2many list table hasn't been impacted - assert.strictEqual(form.$('.o_field_one2many th:first').attr('style'), undefined, + assert.hasAttrValue(form.$('.o_field_one2many th:first'), 'style', undefined, "o2m list columns should have no width harcoded"); form.destroy(); @@ -5474,7 +5365,7 @@ QUnit.module('Views', { var $group1 = form.$('.group_1'); var $group2 = form.$('.group_2'); - assert.strictEqual(form.$('table.o_inner_group').length, 2, + assert.containsN(form, 'table.o_inner_group', 2, "should contain two inner groups"); assert.strictEqual($group1.find('.o_horizontal_separator').length, 1, "inner group should contain one string separator"); @@ -5527,15 +5418,15 @@ QUnit.module('Views', { }); // Inner group - assert.strictEqual(form.$('.main_inner_group > tbody > tr').length, 2, + assert.containsN(form, '.main_inner_group > tbody > tr', 2, "there should be 2 rows in the group"); - assert.strictEqual(form.$('.main_inner_group > tbody > tr:first > .o_td_label').length, 1, + assert.containsOnce(form, '.main_inner_group > tbody > tr:first > .o_td_label', "there should be only one label in the first row"); - assert.strictEqual(form.$('.main_inner_group > tbody > tr:first .o_field_widget').length, 1, + assert.containsOnce(form, '.main_inner_group > tbody > tr:first .o_field_widget', "there should be only one widget in the first row"); - assert.strictEqual(form.$('.main_inner_group > tbody > tr:last > .o_td_label').length, 2, + assert.containsN(form, '.main_inner_group > tbody > tr:last > .o_td_label', 2, "there should be two labels in the second row"); - assert.strictEqual(form.$('.main_inner_group > tbody > tr:last .o_field_widget').length, 2, + assert.containsN(form, '.main_inner_group > tbody > tr:last .o_field_widget', 2, "there should be two widgets in the second row"); // Outer group @@ -5567,7 +5458,7 @@ QUnit.module('Views', { res_id: 1, }); - form.$('.o_data_row:first').click(); + testUtils.dom.click(form.$('.o_data_row:first')); assert.strictEqual($('.modal .modal-title').first().text().trim(), 'Open: custom label', "modal should use the python field string as title"); @@ -5596,11 +5487,11 @@ QUnit.module('Views', { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('input[name="foo"]').val("test").trigger("input"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickEdit(form); + testUtils.fields.editInput(form.$('input[name="foo"]'), "test"); + testUtils.form.clickSave(form); - assert.strictEqual(form.$('.o_form_view > .alert > div').length, 1,"should have a translation alert"); + assert.containsOnce(form, '.o_form_view > .alert > div',"should have a translation alert"); form.destroy(); @@ -5651,13 +5542,13 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('[name="product_id"] .o_external_button').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('[name="product_id"] .o_external_button')); assert.strictEqual($('.modal-body .o_field_translate').length, 1, "there should be a translate button in the modal"); - $('.modal-body .o_field_translate').click(); + testUtils.dom.click($('.modal-body .o_field_translate')); assert.strictEqual(nbTranslateCalls, 1, "should call_button translate once"); @@ -5707,14 +5598,14 @@ QUnit.module('Views', { assert.strictEqual(form.$('.oe_button_box button:not(:disabled)').length, 1, "stat buttons should be enabled"); - form.$('.o_form_statusbar button').click(); + testUtils.dom.clickFirst(form.$('.o_form_statusbar button')); // The unresolved deferred lets us check the state of the buttons assert.strictEqual(form.$buttons.find('button:disabled').length, 4, "control panel buttons should be disabled"); - assert.strictEqual(form.$('.o_form_statusbar button:disabled').length, 2, + assert.containsN(form, '.o_form_statusbar button:disabled', 2, "status bar buttons should be disabled"); - assert.strictEqual(form.$('.oe_button_box button:disabled').length, 1, + assert.containsOnce(form, '.oe_button_box button:disabled', "stat buttons should be disabled"); def.resolve(); @@ -5771,14 +5662,14 @@ QUnit.module('Views', { assert.strictEqual(form.$('.oe_button_box button:not(:disabled)').length, 1, "stat buttons should be enabled"); - form.$('.oe_button_box button').click(); + testUtils.dom.click(form.$('.oe_button_box button')); // The unresolved deferred lets us check the state of the buttons assert.strictEqual(form.$buttons.find('button:disabled').length, 4, "control panel buttons should be disabled"); - assert.strictEqual(form.$('.o_form_statusbar button:disabled').length, 2, + assert.containsN(form, '.o_form_statusbar button:disabled', 2, "status bar buttons should be disabled"); - assert.strictEqual(form.$('.oe_button_box button:disabled').length, 1, + assert.containsOnce(form, '.oe_button_box button:disabled', "stat buttons should be disabled"); def.resolve(); @@ -5821,19 +5712,19 @@ QUnit.module('Views', { }); // click on button, and cancel in confirm dialog - form.$('.o_statusbar_buttons button').click(); + testUtils.dom.click(form.$('.o_statusbar_buttons button')); assert.ok(form.$('.o_statusbar_buttons button').prop('disabled'), 'button should be disabled'); - $('.modal-footer button.btn-secondary').click(); + testUtils.dom.click($('.modal-footer button.btn-secondary')); assert.ok(!form.$('.o_statusbar_buttons button').prop('disabled'), 'button should no longer be disabled'); assert.verifySteps(['default_get']); // click on button, and click on ok in confirm dialog - form.$('.o_statusbar_buttons button').click(); + testUtils.dom.click(form.$('.o_statusbar_buttons button')); assert.verifySteps(['default_get']); - $('.modal-footer button.btn-primary').click(); + testUtils.dom.click($('.modal-footer button.btn-primary')); assert.verifySteps(['default_get', 'create', 'read', 'execute_action']); @@ -5887,12 +5778,12 @@ QUnit.module('Views', { }, }); - form.$('.o_external_button').click(); + testUtils.dom.click(form.$('.o_external_button')); assert.notOk($('.modal .oe_button_box button').attr('disabled'), "stat buttons should be enabled"); - $('.modal .oe_button_box button').click(); + testUtils.dom.click($('.modal .oe_button_box button')); assert.ok($('.modal .oe_button_box button').attr('disabled'), "stat buttons should be disabled"); @@ -5935,10 +5826,10 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('input[name="foo"]').val("test").trigger("input"); - form.$buttons.find('.o_form_button_save').click(); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickEdit(form); + testUtils.fields.editInput(form.$('input[name="foo"]'), "test"); + testUtils.form.clickSave(form); + testUtils.form.clickSave(form); def.resolve(); @@ -5975,13 +5866,13 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('input[name="foo"]').val("incorrect value").trigger("input"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickEdit(form); + testUtils.fields.editInput(form.$('input[name="foo"]'), "incorrect value"); + testUtils.form.clickSave(form); - form.$('input[name="foo"]').val("correct value").trigger("input"); + testUtils.fields.editInput(form.$('input[name="foo"]'), "correct value"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.verifySteps([ 'read', // initial read to render the view @@ -6008,7 +5899,7 @@ QUnit.module('Views', { assert.strictEqual(form.$('span[name="foo"]').text(), '***', "password should be displayed with stars"); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.strictEqual(form.$('input[name="foo"]').val(), 'yop', "input value should be the password"); assert.strictEqual(form.$('input[name="foo"]').prop('type'), 'password', @@ -6029,8 +5920,8 @@ QUnit.module('Views', { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); - assert.strictEqual(form.$('input[name="display_name"]').attr('autocomplete'), 'coucou', + testUtils.form.clickEdit(form); + assert.hasAttrValue(form.$('input[name="display_name"]'), 'autocomplete', 'coucou', "attribute autocomplete should be set"); form.destroy(); }); @@ -6071,18 +5962,17 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual($('.modal').length, 1, "One FormViewDialog should be opened"); // set a value on the m2o - var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); - $('.modal .o_field_many2one input').click(); - $dropdown.find('li:first()').click(); + testUtils.fields.many2one.clickOpenDropdown('partner_type_id'); + testUtils.fields.many2one.clickHighlightedItem('partner_type_id'); - $('.modal-footer button:eq(1)').click(); // Save & new - $('.modal .o_field_many2one input').click(); - $('.modal-footer button:first').click(); // Save & close + testUtils.dom.click($('.modal-footer button:eq(1)')); + testUtils.dom.click($('.modal .o_field_many2one input')); + testUtils.dom.click($('.modal-footer button:first')); form.destroy(); }); @@ -6119,7 +6009,7 @@ QUnit.module('Views', { assert.strictEqual(form.$('.o_field_widget[name="display_name"]').text(), "Select a model to add a filter.", "should contain an error message saying the model is missing"); - form.$('input[name="model_name"]').val("test").trigger("input"); + testUtils.fields.editInput(form.$('input[name="model_name"]'), "test"); assert.notStrictEqual(form.$('.o_field_widget[name="display_name"]').text(), "Select a model to add a filter.", "should not contain an error message anymore"); form.destroy(); @@ -6171,23 +6061,23 @@ QUnit.module('Views', { }, }); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual($('.modal input.o_field_widget[name=foo]').length, 1, 'foo should be editable'); checkOnchange = true; - $('.modal .o_field_widget[name=foo]').val('foo value').trigger('input'); - $('.modal .o_field_widget[name=display_name]').val('readonly').trigger('input'); + testUtils.fields.editInput($('.modal .o_field_widget[name=foo]'), 'foo value'); + testUtils.fields.editInput($('.modal .o_field_widget[name=display_name]'), 'readonly'); assert.strictEqual($('.modal span.o_field_widget[name=foo]').length, 1, 'foo should be readonly'); - $('.modal-footer .btn-primary').click(); // close the modal + testUtils.dom.clickFirst($('.modal-footer .btn-primary')); checkOnchange = false; - form.$('.o_data_row').click(); // re-open previous record + testUtils.dom.click(form.$('.o_data_row')); assert.strictEqual($('.modal .o_field_widget[name=foo]').text(), 'foo value', "the edited value should have been kept"); - $('.modal-footer .btn-primary').click(); // close the modal + testUtils.dom.clickFirst($('.modal-footer .btn-primary')); - form.$buttons.find('.o_form_button_save').click(); // save the record + testUtils.form.clickSave(form); // save the record form.destroy(); }); @@ -6205,13 +6095,13 @@ QUnit.module('Views', { '</form>', }); - assert.ok(form.$('.o_field_widget[name=foo]').hasClass('o_readonly_modifier'), + assert.hasClass(form.$('.o_field_widget[name=foo]'),'o_readonly_modifier', "foo should be readonly in 'Create' mode"); - form.$buttons.find('.o_form_button_save').click(); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickSave(form); + testUtils.form.clickEdit(form); - assert.notOk(form.$('.o_field_widget[name=foo]').hasClass('o_readonly_modifier'), + assert.doesNotHaveClass(form.$('.o_field_widget[name=foo]'), 'o_readonly_modifier', "foo should not be readonly anymore"); form.destroy(); @@ -6246,16 +6136,21 @@ QUnit.module('Views', { }, }); - form.sidebar.$('a:contains(Duplicate)').click(); // duplicate record 1 - assert.strictEqual(form.$('.o_form_editable').length, 1, + // duplicate record 1 + testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + testUtils.dom.click(form.sidebar.$('a:contains(Duplicate)')); + assert.containsOnce(form, '.o_form_editable', "form should be in edit mode"); assert.strictEqual(form.$('.o_field_widget').val(), 'first record (copy)', "duplicated record should have correct name"); - form.$buttons.find('.o_form_button_save').click(); // save duplicated record + testUtils.form.clickSave(form); // save duplicated record + + // delete duplicated record + testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + testUtils.dom.click(form.sidebar.$('a:contains(Delete)')); - form.sidebar.$('a:contains(Delete)').click(); // delete duplicated record assert.strictEqual($('.modal').length, 1, "should have opened a confirm dialog"); - $('.modal-footer .btn-primary').click(); // confirm + testUtils.dom.click($('.modal-footer .btn-primary')); assert.strictEqual(form.$('.o_field_widget').text(), 'first record', "should have come back to previous record"); @@ -6335,11 +6230,11 @@ QUnit.module('Views', { }, }); - form.$('.o_external_button').click(); // open the many2one record in a modal - $('.modal .o_external_button').click(); // in the modal, open the many2one record in another modal + testUtils.dom.click(form.$('.o_external_button')); + testUtils.dom.click($('.modal .o_external_button')); - $('.modal:nth(1) .o_field_widget[name=display_name]').val('new name').trigger('input'); - $('.modal:nth(1) footer .btn-primary').first().click(); // save changes + testUtils.fields.editInput($('.modal:nth(1) .o_field_widget[name=display_name]'), 'new name'); + testUtils.dom.click($('.modal:nth(1) footer .btn-primary').first()); assert.strictEqual($('.modal .o_field_widget[name=trululu] input').val(), 'new name', "record should have been reloaded"); @@ -6380,7 +6275,7 @@ QUnit.module('Views', { context: {hide_bar: true}, }, }); - assert.strictEqual(form.$('.o_list_view thead tr th').length, 1, + assert.containsOnce(form, '.o_list_view thead tr th', "there should be only one column"); form.destroy(); }); @@ -6408,7 +6303,7 @@ QUnit.module('Views', { context: {hide_bar: true}, }, }); - assert.strictEqual(form.$('.o_list_view thead tr th').length, 1, + assert.containsOnce(form, '.o_list_view thead tr th', "there should be only one column"); form.destroy(); }); @@ -6443,11 +6338,11 @@ QUnit.module('Views', { }, viewOptions: {mode: 'edit'}, }); - form.$('.o_external_button').click(); + testUtils.dom.click(form.$('.o_external_button')); assert.strictEqual($('.modal-body .o_form_view .o_list_view .o_data_cell').text(), "yopblip", "table has some initial order"); - $('.modal-body .o_form_view .o_list_view th').click(); + testUtils.dom.click($('.modal-body .o_form_view .o_list_view th')); assert.strictEqual($('.modal-body .o_form_view .o_list_view .o_data_cell').text(), "blipyop", "table is now sorted"); form.destroy(); @@ -6473,7 +6368,7 @@ QUnit.module('Views', { } }); - form.$('.o_form_statusbar .btn-secondary').click(); + testUtils.dom.click(form.$('.o_form_statusbar .btn-secondary')); form.destroy(); }); @@ -6522,7 +6417,7 @@ QUnit.module('Views', { '</form>', }); - assert.strictEqual(form.$('button.o_attachment_button').length, 1, + assert.containsOnce(form, 'button.o_attachment_button', "should have 1 attach_document widget in the statusbar"); assert.strictEqual(form.$('span.o_attach_document').text().trim(), 'Attach document', "widget should have been instantiated"); @@ -6556,7 +6451,7 @@ QUnit.module('Views', { '</form>', }); - form.$('input[name="foo"]').val("I am alive").trigger('input'); + testUtils.fields.editInput(form.$('input[name="foo"]'), "I am alive"); assert.strictEqual(form.$('.o_widget').text(), 'I am alive!', "widget should have been updated"); @@ -6586,12 +6481,12 @@ QUnit.module('Views', { }); // in readonly - form.$('[name="display_name"]').click(); + testUtils.dom.click(form.$('[name="display_name"]')); assert.verifySteps(['bounce']); // in edit - form.$buttons.find('.o_form_button_edit').click(); - form.$('[name="display_name"]').click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('[name="display_name"]')); assert.verifySteps(['bounce']); form.destroy(); @@ -6653,7 +6548,7 @@ QUnit.module('Views', { }); // switch to edit mode to ensure that autoresize is correctly done - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); var height = form.$('.o_field_widget[name=text_field]').height(); // focus the field to manually trigger autoresize form.$('.o_field_widget[name=text_field]').trigger('focus'); @@ -6664,8 +6559,8 @@ QUnit.module('Views', { assert.ok(height > 80, "textarea should have an height of at least 80px"); // save and create a new record to ensure that autoresize is correctly done - form.$buttons.find('.o_form_button_save').click(); - form.$buttons.find('.o_form_button_create').click(); + testUtils.form.clickSave(form); + testUtils.form.clickCreate(form); height = form.$('.o_field_widget[name=text_field]').height(); // focus the field to manually trigger autoresize form.$('.o_field_widget[name=text_field]').trigger('focus'); @@ -6680,7 +6575,7 @@ QUnit.module('Views', { assert.expect(1); var instanceNumber = 0; - testUtils.patch(mixins.ParentedMixin, { + testUtils.mock.patch(mixins.ParentedMixin, { init: function () { instanceNumber++; return this._super.apply(this, arguments); @@ -6751,7 +6646,7 @@ QUnit.module('Views', { form.destroy(); - testUtils.unpatch(mixins.ParentedMixin); + testUtils.mock.unpatch(mixins.ParentedMixin); }); QUnit.test('do not change pager when discarding current record', function (assert) { @@ -6774,8 +6669,8 @@ QUnit.module('Views', { assert.strictEqual(form.pager.$('.o_pager_counter').text().trim(), '2 / 2', 'pager should indicate that we are on second record'); - form.$buttons.find('.o_form_button_edit').click(); - form.$buttons.find('.o_form_button_cancel').click(); + testUtils.form.clickEdit(form); + testUtils.form.clickDiscard(form); assert.strictEqual(form.pager.$('.o_pager_counter').text().trim(), '2 / 2', 'pager should not have changed'); @@ -6786,7 +6681,7 @@ QUnit.module('Views', { QUnit.test('edition in form view on a "noCache" model', function (assert) { assert.expect(4); - testUtils.patch(BasicModel, { + testUtils.mock.patch(BasicModel, { noCacheModels: BasicModel.prototype.noCacheModels.concat(['partner']), }); @@ -6812,19 +6707,19 @@ QUnit.module('Views', { }); core.bus.on('clear_cache', form, assert.step.bind(assert, 'clear_cache')); - form.$('.o_field_widget[name=display_name]').val('new value').trigger('input'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.fields.editInput(form.$('.o_field_widget[name=display_name]'), 'new value'); + testUtils.form.clickSave(form); assert.verifySteps(['write', 'clear_cache']); form.destroy(); - testUtils.unpatch(BasicModel); + testUtils.mock.unpatch(BasicModel); }); QUnit.test('creation in form view on a "noCache" model', function (assert) { assert.expect(4); - testUtils.patch(BasicModel, { + testUtils.mock.patch(BasicModel, { noCacheModels: BasicModel.prototype.noCacheModels.concat(['partner']), }); @@ -6846,19 +6741,19 @@ QUnit.module('Views', { }); core.bus.on('clear_cache', form, assert.step.bind(assert, 'clear_cache')); - form.$('.o_field_widget[name=display_name]').val('value').trigger('input'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.fields.editInput(form.$('.o_field_widget[name=display_name]'), 'value'); + testUtils.form.clickSave(form); assert.verifySteps(['create', 'clear_cache']); form.destroy(); - testUtils.unpatch(BasicModel); + testUtils.mock.unpatch(BasicModel); }); QUnit.test('deletion in form view on a "noCache" model', function (assert) { assert.expect(4); - testUtils.patch(BasicModel, { + testUtils.mock.patch(BasicModel, { noCacheModels: BasicModel.prototype.noCacheModels.concat(['partner']), }); @@ -6877,19 +6772,21 @@ QUnit.module('Views', { } return this._super.apply(this, arguments); }, + res_id: 1, viewOptions: { hasSidebar: true, }, }); core.bus.on('clear_cache', form, assert.step.bind(assert, 'clear_cache')); - form.sidebar.$('a:contains(Delete)').click(); - $('.modal-footer .btn-primary').click(); // confirm + testUtils.dom.click(form.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + testUtils.dom.click(form.sidebar.$('a:contains(Delete)')); + testUtils.dom.click($('.modal-footer .btn-primary')); assert.verifySteps(['unlink', 'clear_cache']); form.destroy(); - testUtils.unpatch(BasicModel); + testUtils.mock.unpatch(BasicModel); }); QUnit.test('a popup window should automatically close after a do_action event', function (assert) { @@ -6926,10 +6823,10 @@ QUnit.module('Views', { }, }); // Open one2many - form.$('.o_data_row').click(); + testUtils.dom.click(form.$('.o_data_row')); assert.strictEqual($('.modal-content').length, 1, "a popup window should have opened"); // Click on many2one and trigger do_action - $('.modal-content a[name="partner_type_id"]').click(); + testUtils.dom.click($('.modal-content a[name="partner_type_id"]')); assert.strictEqual($('.modal-content').length, 0, "the popup window should have closed"); form.destroy(); @@ -6976,11 +6873,11 @@ QUnit.module('Views', { }, }); // Open two one2manys - form.$('.o_data_row').click(); - $('.modal-content .o_data_row').click(); + testUtils.dom.click(form.$('.o_data_row')); + testUtils.dom.click($('.modal-content .o_data_row')); assert.strictEqual($('.modal-content').length, 2, "Two popup windows should have opened."); // Click on many2one and trigger do_action - $('.modal-content a[name="partner_type_id"]').click(); + testUtils.dom.click($('.modal-content a[name="partner_type_id"]')); assert.strictEqual($('.modal-content').length, 0, "All popup windows should have closed."); form.destroy(); @@ -7070,7 +6967,7 @@ QUnit.module('Views', { '<widget name="test"/>' + '</form>', }).then(function(form) { - assert.strictEqual(form.$('div.o_widget').length, 1, + assert.containsOnce(form, 'div.o_widget', "there should be a div with widget class"); form.destroy(); delete widgetRegistry.map.test; @@ -7106,12 +7003,12 @@ QUnit.module('Views', { fieldDebounce: 5000, }); - form.$('input').val('some foo value').trigger('input'); + testUtils.fields.editInput(form.$('input'), 'some foo value'); // manually save the record, to prevent the field widget to notify the model of its new // value before being requested to form.saveRecord(); - assert.strictEqual(form.$('.o_form_readonly').length, 1, + assert.containsOnce(form, '.o_form_readonly', "form view should be in readonly"); assert.strictEqual(form.$el.text().trim(), 'some foo value', "foo field should have correct value"); @@ -7161,7 +7058,7 @@ QUnit.module('Views', { }, }); - form.$('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); assert.strictEqual(form.$('.o_field_widget[name=display_name]').val(), '', "display_name should be the empty string by default"); @@ -7170,9 +7067,9 @@ QUnit.module('Views', { onchangeDef = $.Deferred(); // delay the onchange - form.$('.o_field_widget[name=display_name]').val('some value').trigger('input'); + testUtils.fields.editInput(form.$('.o_field_widget[name=display_name]'), 'some value'); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.step('resolve'); onchangeDef.resolve(); @@ -7201,13 +7098,13 @@ QUnit.module('Views', { '</form>', }); - form.$('input[name=display_name]').click(); + testUtils.dom.click(form.$('input[name=display_name]')); assert.strictEqual(form.$('input[name="display_name"]')[0], document.activeElement, "display_name should be focused"); form.$('input[name="display_name"]').trigger($.Event('keydown', {which: $.ui.keyCode.TAB})); assert.strictEqual(form.$('input[name="display_name"]')[0], document.activeElement, "display_name should still be focused because it is empty and required"); - assert.strictEqual(form.$('input[name="display_name"]').hasClass("o_field_invalid"), true, + assert.hasClass(form.$('input[name="display_name"]'), 'o_field_invalid', "display_name should have the o_field_invalid class"); form.destroy(); }); @@ -7229,7 +7126,7 @@ QUnit.module('Views', { '</form>', }); - form.$('input[name=date]').click(); + testUtils.dom.click(form.$('input[name=date]')); assert.strictEqual(form.$('input[name="date"]')[0], document.activeElement, "display_name should be focused"); form.$('input[name="date"]').trigger($.Event('keydown', {which: $.ui.keyCode.TAB})); @@ -7255,7 +7152,7 @@ QUnit.module('Views', { }); // in edit - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); form.$('input[name="display_name"]').focus().trigger($.Event('keydown', {which: $.ui.keyCode.TAB})); assert.strictEqual(form.$buttons.find('.btn-primary:visible')[0], document.activeElement, "the first primary button (save) should be focused"); @@ -7401,7 +7298,7 @@ QUnit.module('Views', { }, }); - form.$('div[name="bar"]>input').click(); + testUtils.dom.click(form.$('div[name="bar"]>input')); form.$('input[name="foo"]').focus(); $(document.activeElement).trigger($.Event('keydown', {which: $.ui.keyCode.TAB})); diff --git a/addons/web/static/tests/views/graph_tests.js b/addons/web/static/tests/views/graph_tests.js index 6dcafc20072..30d295e1f8f 100644 --- a/addons/web/static/tests/views/graph_tests.js +++ b/addons/web/static/tests/views/graph_tests.js @@ -73,7 +73,7 @@ QUnit.module('Views', { var done = assert.async(); return concurrency.delay(0).then(function () { - assert.strictEqual(graph.$('div.o_graph_svg_container svg.nvd3-svg').length, 1, + assert.containsOnce(graph, 'div.o_graph_svg_container svg.nvd3-svg', "should contain a div with a svg element"); assert.strictEqual(graph.renderer.state.mode, "bar", @@ -134,15 +134,15 @@ QUnit.module('Views', { '</graph>', }); assert.strictEqual(graph.renderer.state.mode, "line", "should be in line chart mode by default"); - assert.notOk(graph.$buttons.find('button[data-mode="bar"]').hasClass('active'), + assert.doesNotHaveClass(graph.$buttons.find('button[data-mode="bar"]'), 'active', 'bar type button should not be active'); - assert.ok(graph.$buttons.find('button[data-mode="line"]').hasClass('active'), + assert.hasClass(graph.$buttons.find('button[data-mode="line"]'),'active', 'line type button should be active'); - graph.$buttons.find('button[data-mode="bar"]').click(); + testUtils.dom.click(graph.$buttons.find('button[data-mode="bar"]')); assert.strictEqual(graph.renderer.state.mode, "bar", "should be in bar chart mode by default"); - assert.notOk(graph.$buttons.find('button[data-mode="line"]').hasClass('active'), + assert.doesNotHaveClass(graph.$buttons.find('button[data-mode="line"]'), 'active', 'line type button should not be active'); - assert.ok(graph.$buttons.find('button[data-mode="bar"]').hasClass('active'), + assert.hasClass(graph.$buttons.find('button[data-mode="bar"]'),'active', 'bar type button should be active'); graph.destroy(); }); @@ -214,7 +214,8 @@ QUnit.module('Views', { "should have used the correct measure"); assert.ok(graph.$buttons.find('.dropdown-item[data-field="foo"]').length, "should have foo in the list of measures"); - graph.$buttons.find('.dropdown-item[data-field="foo"]').click(); + testUtils.dom.click(graph.$buttons.find('.dropdown-toggle:contains(Measures)')); + testUtils.dom.click(graph.$buttons.find('.dropdown-item[data-field="foo"]')); return concurrency.delay(0); }).then(function () { @@ -238,9 +239,9 @@ QUnit.module('Views', { '<field name="product_id"/>' + '</graph>', }); - assert.strictEqual(graph.$('div.o_graph_svg_container svg.nvd3-svg').length, 0, + assert.containsNone(graph, 'div.o_graph_svg_container svg.nvd3-svg', "should not contain a div with a svg element"); - assert.strictEqual(graph.$('div.o_view_nocontent').length, 1, + assert.containsOnce(graph, 'div.o_view_nocontent', "should display the no content helper"); graph.destroy(); }); @@ -257,9 +258,9 @@ QUnit.module('Views', { '<field name="product_id"/>' + '</graph>', }); - assert.strictEqual(graph.$('div.o_graph_svg_container svg.nvd3-svg').length, 0, + assert.containsNone(graph, 'div.o_graph_svg_container svg.nvd3-svg', "should not contain a div with a svg element"); - assert.strictEqual(graph.$('div.o_view_nocontent').length, 1, + assert.containsOnce(graph, 'div.o_view_nocontent', "should display the no content helper"); graph.destroy(); }); @@ -286,7 +287,7 @@ QUnit.module('Views', { '</graph>', }); - assert.strictEqual(graph.$('div.o_view_nocontent').length, 0, + assert.containsNone(graph, 'div.o_view_nocontent', "should not display the no content helper"); assert.strictEqual($('.o_graph_svg_container svg > text').text(), "No data to displayNo data to display", "should display two empty pie charts instead"); @@ -310,7 +311,7 @@ QUnit.module('Views', { "should contain a div with a svg element"); assert.notOk(graph.$('div.o_view_nocontent').length, "should not display the no content helper"); - graph.update({domain: [['product_id', '=', 4]]}); + testUtils.graph.reload(graph, {domain: [['product_id', '=', 4]]}); assert.notOk(graph.$('div.o_graph_svg_container svg.nvd3-svg').length, "should not contain a div with a svg element"); @@ -339,7 +340,7 @@ QUnit.module('Views', { assert.notOk(graph.$('text:contains(red)').length, "should not contain a text element with color in legend"); - graph.update({groupBy: ['color_id']}); + testUtils.graph.reload(graph, {groupBy: ['color_id']}); return concurrency.delay(0); }).then(function () { @@ -372,7 +373,8 @@ QUnit.module('Views', { graph_intervalMapping: {}, }, "context should be correct"); - graph.$buttons.find('.dropdown-item[data-field="foo"]').click(); // change measure + testUtils.dom.click(graph.$buttons.find('.dropdown-toggle:contains(Measures)')); + testUtils.dom.click(graph.$buttons.find('.dropdown-item[data-field="foo"]')); return concurrency.delay(0); }).then(function () { @@ -383,7 +385,7 @@ QUnit.module('Views', { graph_intervalMapping: {}, }, "context should be correct"); - graph.$buttons.find('button[data-mode="line"]').click(); // change mode + testUtils.dom.click(graph.$buttons.find('button[data-mode="line"]')); return concurrency.delay(0); }).then(function () { @@ -394,7 +396,7 @@ QUnit.module('Views', { graph_intervalMapping: {}, }, "context should be correct"); - graph.update({groupBy: ['product_id', 'color_id']}); // change groupbys + testUtils.graph.reload(graph, {groupBy: ['product_id', 'color_id']}); // change groupbys return concurrency.delay(0); }).then(function () { @@ -413,7 +415,7 @@ QUnit.module('Views', { QUnit.test('correctly uses graph_ keys from the context', function (assert) { var done = assert.async(); assert.expect(6); - + var lastOne = _.last(this.data.foo.records); lastOne.color_id = 14; @@ -437,9 +439,9 @@ QUnit.module('Views', { // check mode assert.strictEqual(graph.renderer.state.mode, "line", "should be in line chart mode"); - assert.notOk(graph.$buttons.find('button[data-mode="bar"]').hasClass('active'), + assert.doesNotHaveClass(graph.$buttons.find('button[data-mode="bar"]'), 'active', 'bar chart button should not be active'); - assert.ok(graph.$buttons.find('button[data-mode="line"]').hasClass('active'), + assert.hasClass(graph.$buttons.find('button[data-mode="line"]'),'active', 'line chart button should be active'); // check groupbys @@ -498,7 +500,7 @@ QUnit.module('Views', { }); assert.strictEqual(graph.renderer.state.mode, "bar", "should be in bar chart mode"); - assert.ok(graph.$buttons.find('button[data-mode="bar"]').hasClass('active'), + assert.hasClass(graph.$buttons.find('button[data-mode="bar"]'),'active', 'bar chart button should be active'); var reloadParams = { @@ -508,7 +510,7 @@ QUnit.module('Views', { graph_groupbys: ['color_id'], }, }; - graph.reload(reloadParams); + testUtils.graph.reload(graph, reloadParams); return concurrency.delay(0).then(function () { // check measure assert.strictEqual(graph.$('text.nv-legend-text:contains(Foo)').length, 1, @@ -516,9 +518,9 @@ QUnit.module('Views', { // check mode assert.strictEqual(graph.renderer.state.mode, "line", "should be in line chart mode"); - assert.notOk(graph.$buttons.find('button[data-mode="bar"]').hasClass('active'), + assert.doesNotHaveClass(graph.$buttons.find('button[data-mode="bar"]'), 'active', 'bar chart button should not be active'); - assert.ok(graph.$buttons.find('button[data-mode="line"]').hasClass('active'), + assert.hasClass(graph.$buttons.find('button[data-mode="line"]'),'active', 'line chart button should be active'); // check groupbys @@ -552,7 +554,7 @@ QUnit.module('Views', { }, }); - graph.reload({groupBy: []}); + testUtils.graph.reload(graph, {groupBy: []}); graph.destroy(); }); @@ -580,12 +582,12 @@ QUnit.module('Views', { return concurrency.delay(0).then(function () { - assert.strictEqual(graph.$('.nv-groups rect').length, 2, + assert.containsN(graph, '.nv-groups rect', 2, "should display two groups"); - graph.reload({groupBy: []}); + testUtils.graph.reload(graph, {groupBy: []}); return concurrency.delay(0).then(function () { - assert.strictEqual(graph.$('.nv-groups rect').length, 2, + assert.containsN(graph, '.nv-groups rect', 2, "should still display two groups"); graph.destroy(); @@ -607,7 +609,7 @@ QUnit.module('Views', { }); var done = assert.async(); return concurrency.delay(0).then(function () { - assert.strictEqual(graph.$('div.o_graph_svg_container svg.nvd3-svg').length, 1, + assert.containsOnce(graph, 'div.o_graph_svg_container svg.nvd3-svg', "should contain a div with a svg element"); assert.strictEqual(graph.renderer.state.mode, "bar", @@ -633,7 +635,7 @@ QUnit.module('Views', { }); var done = assert.async(); return concurrency.delay(0).then(function () { - assert.strictEqual(graph.$('div.o_graph_svg_container svg.nvd3-svg').length, 1, + assert.containsOnce(graph, 'div.o_graph_svg_container svg.nvd3-svg', "should contain a div with a svg element"); assert.strictEqual(graph.renderer.state.mode, "bar", @@ -665,7 +667,8 @@ QUnit.module('Views', { return concurrency.delay(0).then(function () { // need to set the measure this way because it cannot be set in the // arch. - graph.$buttons.find('.dropdown-item[data-field="product_id"]').click(); + testUtils.dom.click(graph.$buttons.find('.dropdown-toggle:contains(Measures)')); + testUtils.dom.click(graph.$buttons.find('.dropdown-item[data-field="product_id"]')); assert.strictEqual(graph.model.chart.data[0].value, 1, "should have first datapoint with value 1"); @@ -756,13 +759,13 @@ QUnit.module('Views', { "Bouh should be the first measure"); assert.strictEqual(graph.$buttons.find('.o_graph_measures_list .dropdown-item:last').data('field'), '__count__', "Count should be the last measure"); - + graph.destroy(); }); QUnit.test('Undefined should appear in bar, pie graph but not in line graph', function (assert) { assert.expect(4); - + var graph = createView({ View: GraphView, model: "foo", @@ -776,7 +779,7 @@ QUnit.module('Views', { assert.strictEqual(graph.$("svg.nvd3-svg:contains('Undefined')").length, 0); assert.strictEqual(graph.$("svg.nvd3-svg:contains('March')").length, 1); - graph.$buttons.find('.o_graph_button[data-mode=bar]').click(); + testUtils.dom.click(graph.$buttons.find('.o_graph_button[data-mode=bar]')); assert.strictEqual(graph.$("svg.nvd3-svg:contains('Undefined')").length, 1); assert.strictEqual(graph.$("svg.nvd3-svg:contains('January')").length, 1); diff --git a/addons/web/static/tests/views/kanban_mobile_tests.js b/addons/web/static/tests/views/kanban_mobile_tests.js index 0ee35c2c9c3..98e65d1ea9c 100644 --- a/addons/web/static/tests/views/kanban_mobile_tests.js +++ b/addons/web/static/tests/views/kanban_mobile_tests.js @@ -72,29 +72,29 @@ QUnit.module('Views', { }); // basic rendering tests - assert.strictEqual(kanban.$('.o_kanban_group').length, 2, "should have 2 columns" ); - assert.ok(kanban.$('.o_kanban_mobile_tab:first').hasClass('o_current'), + assert.containsN(kanban, '.o_kanban_group', 2, "should have 2 columns" ); + assert.hasClass(kanban.$('.o_kanban_mobile_tab:first'),'o_current', "first tab is the active tab with class 'o_current'"); - assert.strictEqual(kanban.$('.o_kanban_group:first > div.o_kanban_record').length, 2, + assert.containsN(kanban, '.o_kanban_group:first > div.o_kanban_record', 2, "there are 2 records in active tab"); assert.strictEqual(kanban.$('.o_kanban_group:nth(1) > div.o_kanban_record').length, 0, "there is no records in next tab. Records will be loaded when it will be opened"); // quick create in first column - kanban.$buttons.find('.o-kanban-button-new').click(); - assert.ok(kanban.$('.o_kanban_group:nth(0) > div:nth(1)').hasClass('o_kanban_quick_create'), + testUtils.dom.click(kanban.$buttons.find('.o-kanban-button-new')); + assert.hasClass(kanban.$('.o_kanban_group:nth(0) > div:nth(1)'),'o_kanban_quick_create', "clicking on create should open the quick_create in the first column"); // move to second column kanban.$('.o_kanban_mobile_tab:nth(1)').trigger('click'); - assert.ok(kanban.$('.o_kanban_mobile_tab:nth(1)').hasClass('o_current'), + assert.hasClass(kanban.$('.o_kanban_mobile_tab:nth(1)'),'o_current', "second tab is now active with class 'o_current'"); assert.strictEqual(kanban.$('.o_kanban_group:nth(1) > div.o_kanban_record').length, 2, "the 2 records of the second group have now been loaded"); // quick create in second column - kanban.$buttons.find('.o-kanban-button-new').click(); - assert.ok(kanban.$('.o_kanban_group:nth(1) > div:nth(1)').hasClass('o_kanban_quick_create'), + testUtils.dom.click(kanban.$buttons.find('.o-kanban-button-new')); + assert.hasClass(kanban.$('.o_kanban_group:nth(1) > div:nth(1)'),'o_kanban_quick_create', "clicking on create should open the quick_create in the second column"); // kanban column should match kanban mobile tabs @@ -120,8 +120,8 @@ QUnit.module('Views', { }); // first column should be undefined with framework unique identifier - assert.strictEqual(kanban.$('.o_kanban_group').length, 3, "should have 3 columns" ); - assert.strictEqual(kanban.$('.o_kanban_group:first-child[data-id^="partner_"]').length, 1, + assert.containsN(kanban, '.o_kanban_group', 3, "should have 3 columns" ); + assert.containsOnce(kanban, '.o_kanban_group:first-child[data-id^="partner_"]', "Undefined column should be first and have unique framework identifier as data-id") // kanban column should match kanban mobile tabs @@ -147,8 +147,8 @@ QUnit.module('Views', { }); // basic rendering tests - assert.strictEqual(kanban.$('.o_kanban_group').length, 4, "should have 4 columns" ); - assert.strictEqual(kanban.$('.o_kanban_group[data-id^="partner_"]').length, 4, + assert.containsN(kanban, '.o_kanban_group', 4, "should have 4 columns" ); + assert.containsN(kanban, '.o_kanban_group[data-id^="partner_"]', 4, "all column should have framework unique identifiers"); // kanban column should match kanban mobile tabs diff --git a/addons/web/static/tests/views/kanban_tests.js b/addons/web/static/tests/views/kanban_tests.js index 435c13cd3f1..bb66243fed8 100644 --- a/addons/web/static/tests/views/kanban_tests.js +++ b/addons/web/static/tests/views/kanban_tests.js @@ -84,16 +84,11 @@ QUnit.module('Views', { '</t></templates></kanban>', }); - assert.ok(kanban.$('.o_kanban_view').hasClass('o_kanban_ungrouped'), - "should have classname 'o_kanban_ungrouped'"); - assert.ok(kanban.$('.o_kanban_view').hasClass('o_kanban_test'), - "should have classname 'o_kanban_test'"); - - assert.strictEqual(kanban.$('.o_kanban_record:not(.o_kanban_ghost)').length, 4, - "should have 4 records"); - assert.strictEqual(kanban.$('.o_kanban_ghost').length, 6, "should have 6 ghosts"); - assert.strictEqual(kanban.$('.o_kanban_record:contains(gnap)').length, 1, - "should contain gnap"); + assert.hasClass(kanban.$('.o_kanban_view'), 'o_kanban_ungrouped'); + assert.hasClass(kanban.$('.o_kanban_view'), 'o_kanban_test'); + assert.containsN(kanban, '.o_kanban_record:not(.o_kanban_ghost)', 4); + assert.containsN(kanban,'.o_kanban_ghost', 6); + assert.containsOnce(kanban, '.o_kanban_record:contains(gnap)'); kanban.destroy(); }); @@ -120,31 +115,25 @@ QUnit.module('Views', { }, }); - assert.ok(kanban.$('.o_kanban_view').hasClass('o_kanban_grouped'), - "should have classname 'o_kanban_grouped'"); - assert.ok(kanban.$('.o_kanban_view').hasClass('o_kanban_test'), - "should have classname 'o_kanban_test'"); - assert.strictEqual(kanban.$('.o_kanban_group').length, 2, "should have " + 2 + " columns"); - assert.strictEqual(kanban.$('.o_kanban_group:nth-child(1) .o_kanban_record').length, 1, - "column should contain " + 1 + " record(s)"); - assert.strictEqual(kanban.$('.o_kanban_group:nth-child(2) .o_kanban_record').length, 3, - "column should contain " + 3 + " record(s)"); + assert.hasClass(kanban.$('.o_kanban_view'), 'o_kanban_grouped'); + assert.hasClass(kanban.$('.o_kanban_view'), 'o_kanban_test'); + assert.containsN(kanban, '.o_kanban_group', 2); + assert.containsOnce(kanban, '.o_kanban_group:nth-child(1) .o_kanban_record'); + assert.containsN(kanban, '.o_kanban_group:nth-child(2) .o_kanban_record', 3); + // check available actions in kanban header's config dropdown - assert.ok(kanban.$('.o_kanban_header:first .o_kanban_config .o_kanban_toggle_fold').length, - "should be able to fold the column"); - assert.ok(!kanban.$('.o_kanban_header:first .o_kanban_config .o_column_edit').length, - "should not be able to edit the column"); - assert.ok(!kanban.$('.o_kanban_header:first .o_kanban_config .o_column_delete').length, - "should not be able to delete the column"); - assert.ok(!kanban.$('.o_kanban_header:first .o_kanban_config .o_column_archive_records').length, "should not be able to archive all the records"); - assert.ok(!kanban.$('.o_kanban_header:first .o_kanban_config .o_column_unarchive_records').length, "should not be able to restore all the records"); + assert.containsOnce(kanban, '.o_kanban_header:first .o_kanban_config .o_kanban_toggle_fold'); + assert.containsNone(kanban, '.o_kanban_header:first .o_kanban_config .o_column_edit'); + assert.containsNone(kanban, '.o_kanban_header:first .o_kanban_config .o_column_delete'); + assert.containsNone(kanban, '.o_kanban_header:first .o_kanban_config .o_column_archive_records'); + assert.containsNone(kanban, '.o_kanban_header:first .o_kanban_config .o_column_unarchive_records'); // the next line makes sure that reload works properly. It looks useless, // but it actually test that a grouped local record can be reloaded without // changing its result. - kanban.reload(); - assert.strictEqual(kanban.$('.o_kanban_group:nth-child(2) .o_kanban_record').length, 3, - "column should contain " + 3 + " record(s)"); + testUtils.kanban.reload(kanban); + assert.containsN(kanban, '.o_kanban_group:nth-child(2) .o_kanban_record', 3); + kanban.destroy(); }); @@ -175,21 +164,23 @@ QUnit.module('Views', { }); // check archive/restore all actions in kanban header's config dropdown - assert.ok(kanban.$('.o_kanban_header:first .o_kanban_config .o_column_archive_records').length, "should be able to archive all the records"); - assert.ok(kanban.$('.o_kanban_header:first .o_kanban_config .o_column_unarchive_records').length, "should be able to restore all the records"); + assert.containsOnce(kanban, '.o_kanban_header:first .o_kanban_config .o_column_archive_records'); + assert.containsOnce(kanban, '.o_kanban_header:first .o_kanban_config .o_column_unarchive_records'); // archive the records of the first column - assert.strictEqual(kanban.$('.o_kanban_group:last .o_kanban_record').length, 3, - "last column should contain 3 records"); + assert.containsN(kanban, '.o_kanban_group:last .o_kanban_record', 3); envIDs = [4]; - kanban.$('.o_kanban_group:last .o_column_archive_records').click(); // Click on 'Archive All' - assert.ok($('.modal').length, 'a confirm modal should be displayed'); - $('.modal-footer .btn-secondary').click(); // Click on 'Cancel' - assert.strictEqual(kanban.$('.o_kanban_group:last .o_kanban_record').length, 3, "still last column should contain 3 records"); - kanban.$('.o_kanban_group:last .o_column_archive_records').click(); + + testUtils.kanban.toggleGroupSettings(kanban.$('.o_kanban_group:last')); + testUtils.dom.click(kanban.$('.o_kanban_group:last .o_column_archive_records')); + assert.containsOnce(document.body, '.modal', "a confirm modal should be displayed"); + testUtils.modal.clickButton('Cancel'); + assert.containsN(kanban, '.o_kanban_group:last .o_kanban_record', 3, "still last column should contain 3 records"); + testUtils.kanban.toggleGroupSettings(kanban.$('.o_kanban_group:last')); + testUtils.dom.click(kanban.$('.o_kanban_group:last .o_column_archive_records')); assert.ok($('.modal').length, 'a confirm modal should be displayed'); - $('.modal-footer .btn-primary').click(); // Click on 'Ok' - assert.strictEqual(kanban.$('.o_kanban_group:last .o_kanban_record').length, 0, "last column should not contain any records"); + testUtils.modal.clickButton('Ok'); + assert.containsNone(kanban, '.o_kanban_group:last .o_kanban_record', "last column should not contain any records"); kanban.destroy(); }); @@ -218,17 +209,19 @@ QUnit.module('Views', { assert.ok(kanban.$('.o_kanban_header:first .o_kanban_config .o_column_unarchive_records').length, "should be able to restore all the records"); // archive the records of the first column - assert.strictEqual(kanban.$('.o_kanban_group:last .o_kanban_record').length, 3, + assert.containsN(kanban, '.o_kanban_group:last .o_kanban_record', 3, "last column should contain 3 records"); envIDs = [4]; - kanban.$('.o_kanban_group:last .o_column_archive_records').click(); // Click on 'Archive All' + testUtils.kanban.toggleGroupSettings(kanban.$('.o_kanban_group:last')); + testUtils.dom.click(kanban.$('.o_kanban_group:last .o_column_archive_records')); assert.ok($('.modal').length, 'a confirm modal should be displayed'); - $('.modal-footer .btn-secondary').click(); // Click on 'Cancel' - assert.strictEqual(kanban.$('.o_kanban_group:last .o_kanban_record').length, 3, "still last column should contain 3 records"); - kanban.$('.o_kanban_group:last .o_column_archive_records').click(); + testUtils.modal.clickButton('Cancel'); // Click on 'Cancel' + assert.containsN(kanban, '.o_kanban_group:last .o_kanban_record', 3, "still last column should contain 3 records"); + testUtils.kanban.toggleGroupSettings(kanban.$('.o_kanban_group:last')); + testUtils.dom.click(kanban.$('.o_kanban_group:last .o_column_archive_records')); assert.ok($('.modal').length, 'a confirm modal should be displayed'); - $('.modal-footer .btn-primary').click(); // Click on 'Ok' - assert.strictEqual(kanban.$('.o_kanban_group:last .o_kanban_record').length, 0, "last column should not contain any records"); + testUtils.modal.clickButton('Ok'); // Click on 'Ok' + assert.containsNone(kanban, '.o_kanban_group:last .o_kanban_record', "last column should not contain any records"); kanban.destroy(); }); @@ -278,7 +271,7 @@ QUnit.module('Views', { }); kanban.renderPager(); - assert.ok(kanban.pager.$el.hasClass('o_hidden'), + assert.isNotVisible(kanban.pager.$el, "pager should be hidden in grouped kanban"); kanban.destroy(); }); @@ -300,7 +293,7 @@ QUnit.module('Views', { }, }); - assert.ok(!kanban.pager.$el.hasClass('o_hidden'), + assert.isVisible(kanban.pager.$el, "pager should be visible in ungrouped kanban"); assert.strictEqual(kanban.pager.state.size, 4, "pager's size should be 4"); kanban.destroy(); @@ -372,17 +365,16 @@ QUnit.module('Views', { '</kanban>', groupBy: ['product_id'], }); - kanban.renderButtons(); - assert.ok(kanban.$('.o_kanban_view').hasClass('ui-sortable'), + assert.hasClass(kanban.$('.o_kanban_view'),'ui-sortable', "columns are sortable when grouped by a m2o field"); - assert.ok(kanban.$buttons.find('.o-kanban-button-new').hasClass('btn-primary'), + assert.hasClass(kanban.$buttons.find('.o-kanban-button-new'),'btn-primary', "'create' button should be btn-primary for grouped kanban with at least one column"); - assert.ok(kanban.$('.o_kanban_view > div:last').hasClass('o_column_quick_create'), + assert.hasClass(kanban.$('.o_kanban_view > div:last'),'o_column_quick_create', "column quick create should be enabled when grouped by a many2one field)"); - kanban.$buttons.find('.o-kanban-button-new').click(); // Click on 'Create' - assert.ok(kanban.$('.o_kanban_group:first() > div:nth(1)').hasClass('o_kanban_quick_create'), + testUtils.kanban.clickCreate(kanban); // Click on 'Create' + assert.hasClass(kanban.$('.o_kanban_group:first() > div:nth(1)'),'o_kanban_quick_create', "clicking on create should open the quick_create in the first column"); assert.ok(kanban.$('span.o_column_title:contains(hello)').length, @@ -405,12 +397,12 @@ QUnit.module('Views', { groupBy: ['foo'], }); - assert.ok(!kanban.$('.o_kanban_view').hasClass('ui-sortable'), + assert.doesNotHaveClass(kanban.$('.o_kanban_view'), 'ui-sortable', "columns aren't sortable when not grouped by a m2o field"); - assert.strictEqual(kanban.$('.o_kanban_group').length, 3, "should have " + 3 + " columns"); + assert.containsN(kanban, '.o_kanban_group', 3, "should have " + 3 + " columns"); assert.strictEqual(kanban.$('.o_kanban_group:first() .o_column_title').text(), "yop", "'yop' column should be the first column"); - assert.ok(!kanban.$('.o_kanban_view > div:last').hasClass('o_column_quick_create'), + assert.doesNotHaveClass(kanban.$('.o_kanban_view > div:last'), 'o_column_quick_create', "column quick create should be disabled when not grouped by a many2one field)"); kanban.destroy(); }); @@ -438,11 +430,11 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 1, + assert.containsOnce(kanban, '.o_kanban_group:first .o_kanban_record', "first column should contain one record"); // click on 'Create' -> should open the quick create in the first column - kanban.$buttons.find('.o-kanban-button-new').click(); + testUtils.kanban.clickCreate(kanban); var $quickCreate = kanban.$('.o_kanban_group:first .o_kanban_quick_create'); assert.strictEqual($quickCreate.length, 1, @@ -451,16 +443,16 @@ QUnit.module('Views', { "should have rendered an XXS form view"); assert.strictEqual($quickCreate.find('input').length, 1, "should have only one input"); - assert.ok($quickCreate.find('input').hasClass('o_required_modifier'), + assert.hasClass($quickCreate.find('input'),'o_required_modifier', "the field should be required"); assert.strictEqual($quickCreate.find('input[placeholder=Title]').length, 1, "input placeholder should be 'Title'"); // fill the quick create and validate - $quickCreate.find('input').val('new partner').trigger('input'); - $quickCreate.find('button.o_kanban_add').click(); + testUtils.fields.editInput($quickCreate.find('input'), 'new partner'); + testUtils.dom.click($quickCreate.find('button.o_kanban_add')); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 2, + assert.containsN(kanban, '.o_kanban_group:first .o_kanban_record', 2, "first column should contain two records"); assert.verifySteps([ @@ -509,11 +501,11 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 1, + assert.containsOnce(kanban, '.o_kanban_group:first .o_kanban_record', "first column should contain one record"); // click on 'Create' -> should open the quick create in the first column - kanban.$buttons.find('.o-kanban-button-new').click(); + testUtils.kanban.clickCreate(kanban); var $quickCreate = kanban.$('.o_kanban_group:first .o_kanban_quick_create'); assert.strictEqual($quickCreate.length, 1, @@ -526,12 +518,12 @@ QUnit.module('Views', { "should have rendered three widgets"); // fill the quick create and validate - $quickCreate.find('.o_field_widget[name=foo]').val('new partner').trigger('input'); - $quickCreate.find('.o_field_widget[name=int_field]').val('4').trigger('input'); - $quickCreate.find('.o_field_widget[name=state] .o_priority_star:first').click(); - $quickCreate.find('button.o_kanban_add').click(); + testUtils.fields.editInput($quickCreate.find('.o_field_widget[name=foo]'), 'new partner'); + testUtils.fields.editInput($quickCreate.find('.o_field_widget[name=int_field]'), '4'); + testUtils.dom.click($quickCreate.find('.o_field_widget[name=state] .o_priority_star:first')); + testUtils.dom.click($quickCreate.find('button.o_kanban_add')); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 2, + assert.containsN(kanban, '.o_kanban_group:first .o_kanban_record', 2, "first column should contain two records"); assert.verifySteps([ @@ -580,16 +572,16 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 2, + assert.containsN(kanban, '.o_kanban_group:first .o_kanban_record', 2, "first column should contain two records"); // click on 'Create', fill the quick create and validate - kanban.$buttons.find('.o-kanban-button-new').click(); + testUtils.kanban.clickCreate(kanban); var $quickCreate = kanban.$('.o_kanban_group:first .o_kanban_quick_create'); - $quickCreate.find('input').val('new partner').trigger('input'); - $quickCreate.find('button.o_kanban_add').click(); + testUtils.fields.editInput($quickCreate.find('input'), 'new partner'); + testUtils.dom.click($quickCreate.find('button.o_kanban_add')); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 3, + assert.containsN(kanban, '.o_kanban_group:first .o_kanban_record', 3, "first column should contain three records"); assert.verifySteps([ @@ -645,18 +637,18 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 2, + assert.containsN(kanban, '.o_kanban_group:first .o_kanban_record', 2, "first column should contain two records"); // click on 'Create', fill the quick create and validate - kanban.$buttons.find('.o-kanban-button-new').click(); + testUtils.kanban.clickCreate(kanban); var $quickCreate = kanban.$('.o_kanban_group:first .o_kanban_quick_create'); - $quickCreate.find('.o_field_widget[name=foo]').val('new partner').trigger('input'); - $quickCreate.find('.o_field_widget[name=int_field]').val('4').trigger('input'); - $quickCreate.find('.o_field_widget[name=state] .o_priority_star:first').click(); - $quickCreate.find('button.o_kanban_add').click(); + testUtils.fields.editInput($quickCreate.find('.o_field_widget[name=foo]'), 'new partner'); + testUtils.fields.editInput($quickCreate.find('.o_field_widget[name=int_field]'), '4'); + testUtils.dom.click($quickCreate.find('.o_field_widget[name=state] .o_priority_star:first')); + testUtils.dom.click($quickCreate.find('button.o_kanban_add')); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 3, + assert.containsN(kanban, '.o_kanban_group:first .o_kanban_record', 3, "first column should contain three records"); assert.verifySteps([ @@ -709,7 +701,7 @@ QUnit.module('Views', { }); // click on 'Create' -> should open the quick create in the first column - kanban.$buttons.find('.o-kanban-button-new').click(); + testUtils.kanban.clickCreate(kanban); var $quickCreate = kanban.$('.o_kanban_group:first .o_kanban_quick_create'); assert.strictEqual($quickCreate.length, 1, @@ -718,7 +710,7 @@ QUnit.module('Views', { "default value should be set"); // fill the 'foo' field -> should trigger the onchange - $quickCreate.find('.o_field_widget[name=foo]').val('new partner').trigger('input'); + testUtils.fields.editInput($quickCreate.find('.o_field_widget[name=foo]'), 'new partner'); assert.strictEqual($quickCreate.find('.o_field_widget[name=int_field]').val(), '8', "onchange should have been triggered"); @@ -758,18 +750,18 @@ QUnit.module('Views', { }); // create a new record - kanban.$('.o_kanban_group:first .o_kanban_quick_add').click(); + testUtils.dom.click(kanban.$('.o_kanban_group:first .o_kanban_quick_add')); var $quickCreate = kanban.$('.o_kanban_group:first .o_kanban_quick_create'); - assert.ok($quickCreate.find('.o_field_widget[name=foo]').hasClass('o_required_modifier'), + assert.hasClass($quickCreate.find('.o_field_widget[name=foo]'),'o_required_modifier', "foo field should be required"); - assert.ok($quickCreate.find('.o_field_widget[name=int_field]').hasClass('o_invisible_modifier'), + assert.hasClass($quickCreate.find('.o_field_widget[name=int_field]'),'o_invisible_modifier', "int_field should be invisible"); // fill 'foo' field - $quickCreate.find('.o_field_widget[name=foo]').val('new partner').trigger('input'); + testUtils.fields.editInput($quickCreate.find('.o_field_widget[name=foo]'), 'new partner'); - assert.notOk($quickCreate.find('.o_field_widget[name=int_field]').hasClass('o_invisible_modifier'), + assert.doesNotHaveClass($quickCreate.find('.o_field_widget[name=int_field]'), 'o_invisible_modifier', "int_field should now be visible"); kanban.destroy(); @@ -800,15 +792,15 @@ QUnit.module('Views', { }); // Quick create kanban record - kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); + testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); var $quickAdd = kanban.$('.o_kanban_quick_create'); $quickAdd.find('.o_input').val('Test'); - $quickAdd.find('.o_kanban_add').click(); + testUtils.dom.click($quickAdd.find('.o_kanban_add')); // Select state in kanban - kanban.$('.o_status').first().click(); - kanban.$('.o_selection .dropdown-item:first').click(); - assert.ok(kanban.$('.o_status').first().hasClass('o_status_green'), + testUtils.dom.click(kanban.$('.o_status').first()); + testUtils.dom.click(kanban.$('.o_selection .dropdown-item:first')); + assert.hasClass(kanban.$('.o_status').first(),'o_status_green', "Kanban state should be done (Green)"); kanban.destroy(); }); @@ -836,7 +828,7 @@ QUnit.module('Views', { }); // click to add an element and cancel the quick creation by pressing ESC - kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); + testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); var $quickCreate = kanban.$('.o_kanban_quick_create'); assert.strictEqual($quickCreate.length, 1, "should have a quick create element"); @@ -845,23 +837,23 @@ QUnit.module('Views', { keyCode: $.ui.keyCode.ESCAPE, which: $.ui.keyCode.ESCAPE, })); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 0, + assert.containsNone(kanban, '.o_kanban_quick_create', "should have destroyed the quick create element"); // click to add and element and click outside, should cancel the quick creation - kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); - kanban.$('.o_kanban_group .o_kanban_record:first').click(); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 0, + testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); + testUtils.dom.click(kanban.$('.o_kanban_group .o_kanban_record:first')); + assert.containsNone(kanban, '.o_kanban_quick_create', "the quick create should be destroyed when the user clicks outside"); // click to really add an element - kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); + testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); $quickCreate = kanban.$('.o_kanban_quick_create'); - $quickCreate.find('input').val('new partner').trigger('input'); + testUtils.fields.editInput($quickCreate.find('input'), 'new partner'); // clicking outside should no longer destroy the quick create as it is dirty - kanban.$('.o_kanban_group .o_kanban_record:first').click(); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 1, + testUtils.dom.click(kanban.$('.o_kanban_group .o_kanban_record:first')); + assert.containsOnce(kanban, '.o_kanban_quick_create', "the quick create should not have been destroyed"); // confirm by pressing ENTER @@ -908,20 +900,15 @@ QUnit.module('Views', { fieldDebounce: 5000, }); - assert.strictEqual(kanban.$('.o_kanban_record').length, 4, + assert.containsN(kanban, '.o_kanban_record', 4, "should have 4 records at the beginning"); // add an element and confirm by pressing ENTER - kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); - kanban.$('.o_kanban_quick_create').find('input[name=foo]') - .val('new partner') - .trigger('input') // changes aren't notified here thanks to the fieldDebounce - .trigger($.Event('keydown', { - keyCode: $.ui.keyCode.ENTER, - which: $.ui.keyCode.ENTER, - })); // triggers a navigation event, leading to the 'commitChanges' and record creation - - assert.strictEqual(kanban.$('.o_kanban_record').length, 5, + testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); + testUtils.kanban.quickCreate(kanban, 'new partner', 'foo'); + // triggers a navigation event, leading to the 'commitChanges' and record creation + + assert.containsN(kanban, '.o_kanban_record', 5, "should have created a new record"); assert.strictEqual(kanban.$('.o_kanban_quick_create input[name=foo]').val(), '', "quick create should now be empty"); @@ -963,36 +950,36 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_record').length, 4, + assert.containsN(kanban, '.o_kanban_record', 4, "should have 4 records at the beginning"); // add an element and press ENTER twice def = $.Deferred(); - kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); + testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); var enterEvent = { keyCode: $.ui.keyCode.ENTER, which: $.ui.keyCode.ENTER, }; - kanban.$('.o_kanban_quick_create').find('input[name=foo]') - .val('new partner') - .trigger('input') - .trigger($.Event('keydown', enterEvent)) - .trigger($.Event('keydown', enterEvent)); + testUtils.fields.editAndTrigger( + kanban.$('.o_kanban_quick_create').find('input[name=foo]'), + 'new partner', + ['input', $.Event('keydown', enterEvent), $.Event('keydown', enterEvent)] + ); - assert.strictEqual(kanban.$('.o_kanban_record').length, 4, + assert.containsN(kanban, '.o_kanban_record', 4, "should not have created the record yet"); assert.strictEqual(kanban.$('.o_kanban_quick_create input[name=foo]').val(), 'new partner', "quick create should not be empty yet"); - assert.ok(kanban.$('.o_kanban_quick_create').hasClass('o_disabled'), + assert.hasClass(kanban.$('.o_kanban_quick_create'),'o_disabled', "quick create should be disabled"); def.resolve(); - assert.strictEqual(kanban.$('.o_kanban_record').length, 5, + assert.containsN(kanban, '.o_kanban_record', 5, "should have created a new record"); assert.strictEqual(kanban.$('.o_kanban_quick_create input[name=foo]').val(), '', "quick create should now be empty"); - assert.notOk(kanban.$('.o_kanban_quick_create').hasClass('o_disabled'), + assert.doesNotHaveClass(kanban.$('.o_kanban_quick_create'), 'o_disabled', "quick create should be enabled"); assert.verifySteps(['create']); @@ -1030,33 +1017,30 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_record').length, 4, + assert.containsN(kanban, '.o_kanban_record', 4, "should have 4 records at the beginning"); // add an element and click 'Add' twice def = $.Deferred(); - kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); - kanban.$('.o_kanban_quick_create').find('input[name=foo]') - .val('new partner') - .trigger('input'); - kanban.$('.o_kanban_quick_create').find('.o_kanban_add') - .click() - .click(); - - assert.strictEqual(kanban.$('.o_kanban_record').length, 4, + testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); + testUtils.fields.editInput(kanban.$('.o_kanban_quick_create').find('input[name=foo]'), 'new partner'); + testUtils.dom.click(kanban.$('.o_kanban_quick_create').find('.o_kanban_add')); + testUtils.dom.click(kanban.$('.o_kanban_quick_create').find('.o_kanban_add')); + + assert.containsN(kanban, '.o_kanban_record', 4, "should not have created the record yet"); assert.strictEqual(kanban.$('.o_kanban_quick_create input[name=foo]').val(), 'new partner', "quick create should not be empty yet"); - assert.ok(kanban.$('.o_kanban_quick_create').hasClass('o_disabled'), + assert.hasClass(kanban.$('.o_kanban_quick_create'),'o_disabled', "quick create should be disabled"); def.resolve(); - assert.strictEqual(kanban.$('.o_kanban_record').length, 5, + assert.containsN(kanban, '.o_kanban_record', 5, "should have created a new record"); assert.strictEqual(kanban.$('.o_kanban_quick_create input[name=foo]').val(), '', "quick create should now be empty"); - assert.notOk(kanban.$('.o_kanban_quick_create').hasClass('o_disabled'), + assert.doesNotHaveClass(kanban.$('.o_kanban_quick_create'), 'o_disabled', "quick create should be enabled"); assert.verifySteps(['create']); @@ -1110,36 +1094,37 @@ QUnit.module('Views', { fieldDebounce: 5000, }); - assert.strictEqual(kanban.$('.o_kanban_record').length, 4, + assert.containsN(kanban, '.o_kanban_record', 4, "should have 4 records at the beginning"); // add an element and press ENTER twice - kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); + testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); def = $.Deferred(); var enterEvent = { keyCode: $.ui.keyCode.ENTER, which: $.ui.keyCode.ENTER, }; - kanban.$('.o_kanban_quick_create').find('input[name=foo]') - .val('new partner') - .trigger('input') - .trigger($.Event('keydown', enterEvent)) - .trigger($.Event('keydown', enterEvent)); - assert.strictEqual(kanban.$('.o_kanban_record').length, 4, + testUtils.fields.editAndTrigger( + kanban.$('.o_kanban_quick_create').find('input[name=foo]'), + 'new partner', + ['input', $.Event('keydown', enterEvent), $.Event('keydown', enterEvent)] + ); + + assert.containsN(kanban, '.o_kanban_record', 4, "should not have created the record yet"); assert.strictEqual(kanban.$('.o_kanban_quick_create input[name=foo]').val(), 'new partner', "quick create should not be empty yet"); - assert.ok(kanban.$('.o_kanban_quick_create').hasClass('o_disabled'), + assert.hasClass(kanban.$('.o_kanban_quick_create'),'o_disabled', "quick create should be disabled"); def.resolve(); - assert.strictEqual(kanban.$('.o_kanban_record').length, 5, + assert.containsN(kanban, '.o_kanban_record', 5, "should have created a new record"); assert.strictEqual(kanban.$('.o_kanban_quick_create input[name=foo]').val(), '', "quick create should now be empty"); - assert.notOk(kanban.$('.o_kanban_quick_create').hasClass('o_disabled'), + assert.doesNotHaveClass(kanban.$('.o_kanban_quick_create'), 'o_disabled', "quick create should be enabled"); assert.verifySteps([ @@ -1194,31 +1179,29 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_record').length, 4, + assert.containsN(kanban, '.o_kanban_record', 4, "should have 4 records at the beginning"); // add an element and click 'add' - kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); + testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); def = $.Deferred(); - kanban.$('.o_kanban_quick_create').find('input[name=foo]') - .val('new partner') - .trigger('input'); - kanban.$('.o_kanban_quick_create').find('.o_kanban_add').click(); + testUtils.fields.editInput(kanban.$('.o_kanban_quick_create').find('input[name=foo]'), 'new partner'); + testUtils.dom.click(kanban.$('.o_kanban_quick_create').find('.o_kanban_add')); - assert.strictEqual(kanban.$('.o_kanban_record').length, 4, + assert.containsN(kanban, '.o_kanban_record', 4, "should not have created the record yet"); assert.strictEqual(kanban.$('.o_kanban_quick_create input[name=foo]').val(), 'new partner', "quick create should not be empty yet"); - assert.ok(kanban.$('.o_kanban_quick_create').hasClass('o_disabled'), + assert.hasClass(kanban.$('.o_kanban_quick_create'),'o_disabled', "quick create should be disabled"); def.resolve(); // the onchange returns - assert.strictEqual(kanban.$('.o_kanban_record').length, 5, + assert.containsN(kanban, '.o_kanban_record', 5, "should have created a new record"); assert.strictEqual(kanban.$('.o_kanban_quick_create input[name=foo]').val(), '', "quick create should now be empty"); - assert.notOk(kanban.$('.o_kanban_quick_create').hasClass('o_disabled'), + assert.doesNotHaveClass(kanban.$('.o_kanban_quick_create'), 'o_disabled', "quick create should be enabled"); assert.verifySteps([ @@ -1246,30 +1229,32 @@ QUnit.module('Views', { groupBy: ['bar'], }); - assert.notOk(kanban.$('.o_kanban_group:first').hasClass('o_column_folded'), + assert.doesNotHaveClass(kanban.$('.o_kanban_group:first'), 'o_column_folded', "first column should not be folded"); // fold the first column - kanban.$('.o_kanban_group:first .o_kanban_toggle_fold').click(); + testUtils.kanban.toggleGroupSettings(kanban.$('.o_kanban_group:first')); + testUtils.dom.click(kanban.$('.o_kanban_group:first .o_kanban_toggle_fold')); - assert.ok(kanban.$('.o_kanban_group:first').hasClass('o_column_folded'), + assert.hasClass(kanban.$('.o_kanban_group:first'),'o_column_folded', "first column should be folded"); // click on 'Create' to open the quick create in the first column - kanban.$buttons.find('.o-kanban-button-new').click(); + testUtils.kanban.clickCreate(kanban); - assert.notOk(kanban.$('.o_kanban_group:first').hasClass('o_column_folded'), + assert.doesNotHaveClass(kanban.$('.o_kanban_group:first'), 'o_column_folded', "first column should no longer be folded"); var $quickCreate = kanban.$('.o_kanban_group:first .o_kanban_quick_create'); assert.strictEqual($quickCreate.length, 1, "should have added a quick create element in first column"); // fold again the first column - kanban.$('.o_kanban_group:first .o_kanban_toggle_fold').click(); + testUtils.kanban.toggleGroupSettings(kanban.$('.o_kanban_group:first')); + testUtils.dom.click(kanban.$('.o_kanban_group:first .o_kanban_toggle_fold')); - assert.ok(kanban.$('.o_kanban_group:first').hasClass('o_column_folded'), + assert.hasClass(kanban.$('.o_kanban_group:first'),'o_column_folded', "first column should be folded"); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 0, + assert.containsNone(kanban, '.o_kanban_quick_create', "there should be no more quick create"); kanban.destroy(); @@ -1290,27 +1275,27 @@ QUnit.module('Views', { groupBy: ['bar'], }); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 1, + assert.containsOnce(kanban, '.o_kanban_group:first .o_kanban_record', "first column should contain one record"); // click to add an element - kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 1, + testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); + assert.containsOnce(kanban, '.o_kanban_quick_create', "should have open the quick create widget"); // click again to add an element -> should have kept the quick create open - kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 1, + testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); + assert.containsOnce(kanban, '.o_kanban_quick_create', "should have kept the quick create open"); // click outside: should remove the quick create - kanban.$('.o_kanban_group .o_kanban_record:first').click(); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 0, + testUtils.dom.click(kanban.$('.o_kanban_group .o_kanban_record:first')); + assert.containsNone(kanban, '.o_kanban_quick_create', "the quick create should not have been destroyed"); // click to reopen the quick create - kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 1, + testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); + assert.containsOnce(kanban, '.o_kanban_quick_create', "should have open the quick create widget"); // press ESC: should remove the quick create @@ -1318,21 +1303,21 @@ QUnit.module('Views', { keyCode: $.ui.keyCode.ESCAPE, which: $.ui.keyCode.ESCAPE, })); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 0, + assert.containsNone(kanban, '.o_kanban_quick_create', "quick create widget should have been removed"); // click to reopen the quick create - kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 1, + testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); + assert.containsOnce(kanban, '.o_kanban_quick_create', "should have open the quick create widget"); // click on 'Discard': should remove the quick create - kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); - kanban.$('.o_kanban_group .o_kanban_record:first').click(); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 0, + testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); + testUtils.dom.click(kanban.$('.o_kanban_group .o_kanban_record:first')); + assert.containsNone(kanban, '.o_kanban_quick_create', "the quick create should be destroyed when the user clicks outside"); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 1, + assert.containsOnce(kanban, '.o_kanban_group:first .o_kanban_record', "first column should still contain one record"); kanban.destroy(); @@ -1353,20 +1338,20 @@ QUnit.module('Views', { groupBy: ['bar'], }); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 1, + assert.containsOnce(kanban, '.o_kanban_group:first .o_kanban_record', "first column should contain one record"); // click to add an element and edit it - kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 1, + testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); + assert.containsOnce(kanban, '.o_kanban_quick_create', "should have open the quick create widget"); var $quickCreate = kanban.$('.o_kanban_quick_create'); - $quickCreate.find('input').val('some value').trigger('input'); + testUtils.fields.editInput($quickCreate.find('input'), 'some value'); // click outside: should not remove the quick create - kanban.$('.o_kanban_group .o_kanban_record:first').click(); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 1, + testUtils.dom.click(kanban.$('.o_kanban_group .o_kanban_record:first')); + assert.containsOnce(kanban, '.o_kanban_quick_create', "the quick create should not have been destroyed"); // press ESC: should remove the quick create @@ -1374,23 +1359,23 @@ QUnit.module('Views', { keyCode: $.ui.keyCode.ESCAPE, which: $.ui.keyCode.ESCAPE, })); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 0, + assert.containsNone(kanban, '.o_kanban_quick_create', "quick create widget should have been removed"); // click to reopen quick create and edit it - kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 1, + testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); + assert.containsOnce(kanban, '.o_kanban_quick_create', "should have open the quick create widget"); $quickCreate = kanban.$('.o_kanban_quick_create'); - $quickCreate.find('input').val('some value').trigger('input'); + testUtils.fields.editInput($quickCreate.find('input'), 'some value'); // click on 'Discard': should remove the quick create - kanban.$('.o_kanban_quick_create .o_kanban_cancel').click(); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 0, + testUtils.dom.click(kanban.$('.o_kanban_quick_create .o_kanban_cancel')); + assert.containsNone(kanban, '.o_kanban_quick_create', "the quick create should be destroyed when the user clicks outside"); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 1, + assert.containsOnce(kanban, '.o_kanban_group:first .o_kanban_record', "first column should still contain one record"); kanban.destroy(); @@ -1429,21 +1414,21 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 1, + assert.containsOnce(kanban, '.o_kanban_group:first .o_kanban_record', "first column should contain one record"); // click to add and edit an element var $quickCreate = kanban.$('.o_kanban_quick_create'); - kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); + testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); $quickCreate = kanban.$('.o_kanban_quick_create'); - $quickCreate.find('input').val('new partner').trigger('input'); - $quickCreate.find('button.o_kanban_edit').click(); + testUtils.fields.editInput($quickCreate.find('input'), 'new partner'); + testUtils.dom.click($quickCreate.find('button.o_kanban_edit')); assert.strictEqual(this.data.partner.records.length, 5, "should have created a partner"); assert.strictEqual(_.last(this.data.partner.records).name, "new partner", "should have correct name"); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 2, + assert.containsN(kanban, '.o_kanban_group:first .o_kanban_record', 2, "first column should now contain two records"); kanban.destroy(); @@ -1464,40 +1449,28 @@ QUnit.module('Views', { groupBy: ['bar'], }); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 1, + assert.containsOnce(kanban, '.o_kanban_group:first .o_kanban_record', "first column should contain one record"); // click to add an element, fill the input and press ENTER - kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); + testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 1, + assert.containsOnce(kanban, '.o_kanban_quick_create', "the quick create should be open"); - kanban.$('.o_kanban_quick_create input') - .val('new partner 1') - .trigger('input') - .trigger($.Event('keydown', { - which: $.ui.keyCode.ENTER, - keyCode: $.ui.keyCode.ENTER, - })); + testUtils.kanban.quickCreate(kanban, 'new partner 1'); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 2, + assert.containsN(kanban, '.o_kanban_group:first .o_kanban_record', 2, "first column should now contain two records"); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 1, + assert.containsOnce(kanban, '.o_kanban_quick_create', "the quick create should still be open"); // create a second element in a row - kanban.$('.o_kanban_quick_create input') - .val('new partner 2') - .trigger('input') - .trigger($.Event('keydown', { - which: $.ui.keyCode.ENTER, - keyCode: $.ui.keyCode.ENTER, - })); - - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 3, + testUtils.kanban.quickCreate(kanban, 'new partner 2'); + + assert.containsN(kanban, '.o_kanban_group:first .o_kanban_record', 3, "first column should now contain three records"); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 1, + assert.containsOnce(kanban, '.o_kanban_quick_create', "the quick create should still be open"); kanban.destroy(); @@ -1526,32 +1499,27 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 1, + assert.containsOnce(kanban, '.o_kanban_group:first .o_kanban_record', "first column should contain one record"); // click to add a record, and add two in a row (first one will be delayed) - kanban.$('.o_kanban_header .o_kanban_quick_add i').first().click(); + testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 1, + assert.containsOnce(kanban, '.o_kanban_quick_create', "the quick create should be open"); def = $.Deferred(); - kanban.$('.o_kanban_quick_create input') - .val('new partner 1') - .trigger('input') - .trigger($.Event('keydown', { - which: $.ui.keyCode.ENTER, - keyCode: $.ui.keyCode.ENTER, - })); - - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 1, + + testUtils.kanban.quickCreate(kanban, 'new partner 1'); + + assert.containsOnce(kanban, '.o_kanban_group:first .o_kanban_record', "first column should still contain one record"); - assert.strictEqual(kanban.$('.o_kanban_quick_create.o_disabled').length, 1, + assert.containsOnce(kanban, '.o_kanban_quick_create.o_disabled', "quick create should be disabled"); def.resolve(); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 2, + assert.containsN(kanban, '.o_kanban_group:first .o_kanban_record', 2, "first column should now contain two records"); assert.strictEqual(kanban.$('.o_kanban_quick_create:not(.o_disabled)').length, 1, "quick create should be enabled"); @@ -1591,20 +1559,14 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 2, + assert.containsN(kanban, '.o_kanban_group:first .o_kanban_record', 2, "there should be 2 records in first column"); - kanban.$buttons.find('.o-kanban-button-new').click(); // Click on 'Create' - assert.ok(kanban.$('.o_kanban_group:first() > div:nth(1)').hasClass('o_kanban_quick_create'), + testUtils.kanban.clickCreate(kanban); // Click on 'Create' + assert.hasClass(kanban.$('.o_kanban_group:first() > div:nth(1)'),'o_kanban_quick_create', "clicking on create should open the quick_create in the first column"); - kanban.$('.o_kanban_quick_create input') - .val('test') - .trigger('input') - .trigger($.Event('keydown', { - keyCode: $.ui.keyCode.ENTER, - which: $.ui.keyCode.ENTER, - })); + testUtils.kanban.quickCreate(kanban, 'test'); assert.strictEqual($('.modal .o_form_view.o_form_editable').length, 1, "a form view dialog should have been opened (in edit)"); @@ -1612,11 +1574,11 @@ QUnit.module('Views', { "the correct product_id should already be set"); // specify a name and save - $('.modal input[name=foo]').val('test').trigger('input'); - $('.modal-footer .btn-primary').click(); + testUtils.fields.editInput($('.modal input[name=foo]'), 'test'); + testUtils.modal.clickButton('Save'); assert.strictEqual($('.modal').length, 0, "the modal should be closed"); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 3, + assert.containsN(kanban, '.o_kanban_group:first .o_kanban_record', 3, "there should be 3 records in first column"); var $firstRecord = kanban.$('.o_kanban_group:first .o_kanban_record:first'); assert.strictEqual($firstRecord.text(), 'test', @@ -1656,26 +1618,19 @@ QUnit.module('Views', { }, $.Event()); } return this._super.apply(this, arguments); - }, + } }); - kanban.$buttons.find('.o-kanban-button-new').click(); // Click on 'Create' - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 1, + testUtils.kanban.clickCreate(kanban); + assert.containsOnce(kanban, '.o_kanban_quick_create', "should have a quick create widget"); - kanban.$('.o_kanban_quick_create input') - .val('test') - .trigger('input') - .trigger($.Event('keydown', { - keyCode: $.ui.keyCode.ENTER, - which: $.ui.keyCode.ENTER, - })); + testUtils.kanban.quickCreate(kanban, 'test'); assert.strictEqual($('.modal .o_form_view.o_form_editable').length, 1, "a form view dialog should have been opened (in edit)"); - // discard - $('.modal-footer .btn-secondary').click(); + testUtils.modal.clickButton('Discard'); assert.strictEqual($('.modal').length, 0, "the modal should be closed"); assert.strictEqual(kanban.$('.o_kanban_quick_create:not(.o_disabled)').length, 1, @@ -1720,22 +1675,21 @@ QUnit.module('Views', { groupBy: ['foo'], }); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 1, + assert.containsOnce(kanban, '.o_kanban_group:first .o_kanban_record', "there should be 1 record in first column"); - kanban.$('.o_kanban_header:first .o_kanban_quick_add i').click(); - kanban.$('.o_kanban_quick_create input').val('test').trigger('input'); - kanban.$('.o_kanban_add').click(); + testUtils.dom.click(kanban.$('.o_kanban_header:first .o_kanban_quick_add i')); + testUtils.fields.editInput(kanban.$('.o_kanban_quick_create input'), 'test'); + testUtils.dom.click(kanban.$('.o_kanban_add')); assert.strictEqual($('.modal .o_form_view.o_form_editable').length, 1, "a form view dialog should have been opened (in edit)"); assert.strictEqual($('.modal .o_field_widget[name=foo]').val(), 'yop', "the correct default value for foo should already be set"); - - $('.modal-footer .btn-primary').click(); + testUtils.modal.clickButton('Save'); assert.strictEqual($('.modal').length, 0, "the modal should be closed"); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 2, + assert.containsN(kanban, '.o_kanban_group:first .o_kanban_record', 2, "there should be 2 records in first column"); kanban.destroy(); @@ -1777,22 +1731,22 @@ QUnit.module('Views', { groupBy: ['state'], }); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 1, + assert.containsOnce(kanban, '.o_kanban_group:first .o_kanban_record', "there should be 1 record in first column"); - kanban.$('.o_kanban_header:first .o_kanban_quick_add i').click(); - kanban.$('.o_kanban_quick_create input').val('test').trigger('input'); - kanban.$('.o_kanban_add').click(); + testUtils.dom.click(kanban.$('.o_kanban_header:first .o_kanban_quick_add i')); + testUtils.fields.editInput(kanban.$('.o_kanban_quick_create input'), 'test'); + testUtils.dom.click(kanban.$('.o_kanban_add')); assert.strictEqual($('.modal .o_form_view.o_form_editable').length, 1, "a form view dialog should have been opened (in edit)"); assert.strictEqual($('.modal .o_field_widget[name=state]').val(), '"abc"', "the correct default value for state should already be set"); - $('.modal-footer .btn-primary').click(); + testUtils.modal.clickButton('Save'); assert.strictEqual($('.modal').length, 0, "the modal should be closed"); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 2, + assert.containsN(kanban, '.o_kanban_group:first .o_kanban_record', 2, "there should be 2 records in first column"); kanban.destroy(); @@ -1827,14 +1781,14 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_group').length, 2, + assert.containsN(kanban, '.o_kanban_group', 2, "there should be 2 columns"); - assert.strictEqual(kanban.$('.o_kanban_record').length, 0, + assert.containsNone(kanban, '.o_kanban_record', "both columns should be empty"); - kanban.$buttons.find('.o-kanban-button-new').click(); + testUtils.kanban.clickCreate(kanban); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_quick_create').length, 1, + assert.containsOnce(kanban, '.o_kanban_group:first .o_kanban_quick_create', "should have opened the quick create in the first column"); kanban.destroy(); @@ -1863,22 +1817,22 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_header .o_kanban_quick_add i').length, 0, + assert.containsNone(kanban, '.o_kanban_header .o_kanban_quick_add i', "quick create should be disabled when grouped on a date field"); // clicking on CREATE in control panel should not open a quick create - kanban.$buttons.find('.o-kanban-button-new').click(); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 0, + testUtils.kanban.clickCreate(kanban); + assert.containsNone(kanban, '.o_kanban_quick_create', "should not have opened the quick create widget"); kanban.reload({groupBy: ['datetime']}); - assert.strictEqual(kanban.$('.o_kanban_header .o_kanban_quick_add i').length, 0, + assert.containsNone(kanban, '.o_kanban_header .o_kanban_quick_add i', "quick create should be disabled when grouped on a datetime field"); // clicking on CREATE in control panel should not open a quick create - kanban.$buttons.find('.o-kanban-button-new').click(); - assert.strictEqual(kanban.$('.o_kanban_quick_create').length, 0, + testUtils.kanban.clickCreate(kanban); + assert.containsNone(kanban, '.o_kanban_quick_create', "should not have opened the quick create widget"); kanban.destroy(); @@ -1899,17 +1853,17 @@ QUnit.module('Views', { groupBy: ['foo'], }); - assert.strictEqual(kanban.$('.o_kanban_header .o_kanban_quick_add i').length, 3, + assert.containsN(kanban, '.o_kanban_header .o_kanban_quick_add i', 3, "quick create should be enabled when grouped on a char field"); kanban.reload({groupBy: ['date']}); - assert.strictEqual(kanban.$('.o_kanban_header .o_kanban_quick_add i').length, 0, + assert.containsNone(kanban, '.o_kanban_header .o_kanban_quick_add i', "quick create should now be disabled (grouped on date field)"); kanban.reload({groupBy: ['bar']}); - assert.strictEqual(kanban.$('.o_kanban_header .o_kanban_quick_add i').length, 2, + assert.containsN(kanban, '.o_kanban_header .o_kanban_quick_add i', 2, "quick create should be enabled again (grouped on boolean field)"); kanban.destroy(); @@ -1937,16 +1891,16 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_header .o_kanban_quick_add i').length, 3, + assert.containsN(kanban, '.o_kanban_header .o_kanban_quick_add i', 3, "quick create should be enabled when grouped on a char field"); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 1, + assert.containsOnce(kanban, '.o_kanban_group:first .o_kanban_record', "first column should contain 1 record"); - kanban.$('.o_kanban_header:first .o_kanban_quick_add i').click(); - kanban.$('.o_kanban_quick_create input').val('new record').trigger('input'); - kanban.$('.o_kanban_add').click(); + testUtils.dom.click(kanban.$('.o_kanban_header:first .o_kanban_quick_add i')); + testUtils.fields.editInput(kanban.$('.o_kanban_quick_create input'), 'new record'); + testUtils.dom.click(kanban.$('.o_kanban_add')); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 2, + assert.containsN(kanban, '.o_kanban_group:first .o_kanban_record', 2, "first column should now contain 2 records"); kanban.destroy(); @@ -1974,14 +1928,14 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_header .o_kanban_quick_add i').length, 2, + assert.containsN(kanban, '.o_kanban_header .o_kanban_quick_add i', 2, "quick create should be enabled when grouped on a boolean field"); assert.strictEqual(kanban.$('.o_kanban_group:nth(1) .o_kanban_record').length, 3, "second column (true) should contain 3 records"); - kanban.$('.o_kanban_header:nth(1) .o_kanban_quick_add i').click(); - kanban.$('.o_kanban_quick_create input').val('new record').trigger('input'); - kanban.$('.o_kanban_add').click(); + testUtils.dom.click(kanban.$('.o_kanban_header:nth(1) .o_kanban_quick_add i')); + testUtils.fields.editInput(kanban.$('.o_kanban_quick_create input'), 'new record'); + testUtils.dom.click(kanban.$('.o_kanban_add')); assert.strictEqual(kanban.$('.o_kanban_group:nth(1) .o_kanban_record').length, 4, "second column (true) should now contain 4 records"); @@ -2011,16 +1965,16 @@ QUnit.module('Views', { groupBy: ['state'], }); - assert.strictEqual(kanban.$('.o_kanban_header .o_kanban_quick_add i').length, 3, + assert.containsN(kanban, '.o_kanban_header .o_kanban_quick_add i', 3, "quick create should be enabled when grouped on a selection field"); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 1, + assert.containsOnce(kanban, '.o_kanban_group:first .o_kanban_record', "first column (abc) should contain 1 record"); - kanban.$('.o_kanban_header:first .o_kanban_quick_add i').click(); - kanban.$('.o_kanban_quick_create input').val('new record').trigger('input'); - kanban.$('.o_kanban_add').click(); + testUtils.dom.click(kanban.$('.o_kanban_header:first .o_kanban_quick_add i')); + testUtils.fields.editInput(kanban.$('.o_kanban_quick_create input'), 'new record'); + testUtils.dom.click(kanban.$('.o_kanban_add')); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 2, + assert.containsN(kanban, '.o_kanban_group:first .o_kanban_record', 2, "first column (abc) should contain 2 records"); kanban.destroy(); @@ -2055,17 +2009,17 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_header .o_kanban_quick_add i').length, 3, + assert.containsN(kanban, '.o_kanban_header .o_kanban_quick_add i', 3, "quick create should be enabled when grouped on a char field"); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 1, + assert.containsOnce(kanban, '.o_kanban_group:first .o_kanban_record', "first column should contain 1 record"); - kanban.$('.o_kanban_header:first .o_kanban_quick_add i').click(); + testUtils.dom.click(kanban.$('.o_kanban_header:first .o_kanban_quick_add i')); assert.strictEqual(kanban.$('.o_kanban_quick_create input').val(), 'yop', "should have set the correct foo value by default"); - kanban.$('.o_kanban_add').click(); + testUtils.dom.click(kanban.$('.o_kanban_add')); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 2, + assert.containsN(kanban, '.o_kanban_group:first .o_kanban_record', 2, "first column should now contain 2 records"); kanban.destroy(); @@ -2100,15 +2054,15 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_header .o_kanban_quick_add i').length, 2, + assert.containsN(kanban, '.o_kanban_header .o_kanban_quick_add i', 2, "quick create should be enabled when grouped on a boolean field"); assert.strictEqual(kanban.$('.o_kanban_group:nth(1) .o_kanban_record').length, 3, "second column (true) should contain 3 records"); - kanban.$('.o_kanban_header:nth(1) .o_kanban_quick_add i').click(); + testUtils.dom.click(kanban.$('.o_kanban_header:nth(1) .o_kanban_quick_add i')); assert.ok(kanban.$('.o_kanban_quick_create .o_field_boolean input').is(':checked'), "should have set the correct bar value by default"); - kanban.$('.o_kanban_add').click(); + testUtils.dom.click(kanban.$('.o_kanban_add')); assert.strictEqual(kanban.$('.o_kanban_group:nth(1) .o_kanban_record').length, 4, "second column (true) should now contain 4 records"); @@ -2145,17 +2099,17 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_header .o_kanban_quick_add i').length, 3, + assert.containsN(kanban, '.o_kanban_header .o_kanban_quick_add i', 3, "quick create should be enabled when grouped on a selection field"); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 1, + assert.containsOnce(kanban, '.o_kanban_group:first .o_kanban_record', "first column (abc) should contain 1 record"); - kanban.$('.o_kanban_header:first .o_kanban_quick_add i').click(); + testUtils.dom.click(kanban.$('.o_kanban_header:first .o_kanban_quick_add i')); assert.strictEqual(kanban.$('.o_kanban_quick_create select').val(), '"abc"', "should have set the correct state value by default"); - kanban.$('.o_kanban_add').click(); + testUtils.dom.click(kanban.$('.o_kanban_add')); - assert.strictEqual(kanban.$('.o_kanban_group:first .o_kanban_record').length, 2, + assert.containsN(kanban, '.o_kanban_group:first .o_kanban_record', 2, "first column (abc) should now contain 2 records"); kanban.destroy(); @@ -2204,7 +2158,7 @@ QUnit.module('Views', { var $first_record = kanban.$('.o_kanban_record:first()'); assert.strictEqual($first_record.find('.o_field_many2manytags .o_tag').length, 2, 'first record should contain 2 tags'); - assert.ok($first_record.find('.o_tag:first()').hasClass('o_tag_color_2'), + assert.hasClass($first_record.find('.o_tag:first()'),'o_tag_color_2', 'first tag should have color 2'); assert.verifySteps(['/web/dataset/search_read', '/web/dataset/call_kw/category/read'], 'two RPC should have been done (one search read and one read for the m2m)'); @@ -2214,7 +2168,7 @@ QUnit.module('Views', { 'there should be only one tag in second record'); // Write on the record using the priority widget to trigger a re-render in readonly - kanban.$('.o_field_widget.o_priority a.o_priority_star.fa-star-o').first().click(); + testUtils.dom.click(kanban.$('.o_field_widget.o_priority a.o_priority_star.fa-star-o').first()); assert.verifySteps([ '/web/dataset/search_read', '/web/dataset/call_kw/category/read', @@ -2226,7 +2180,7 @@ QUnit.module('Views', { 'first record should still contain only 2 tags'); // click on a tag (should trigger switch_view) - kanban.$('.o_tag:contains(gold):first').click(); + testUtils.dom.click(kanban.$('.o_tag:contains(gold):first')); kanban.destroy(); }); @@ -2291,7 +2245,7 @@ QUnit.module('Views', { ev.preventDefault(); }); - $testLink.click(); + testUtils.dom.click($testLink); $(document.body).off('click.o_test'); kanban.destroy(); @@ -2372,7 +2326,7 @@ QUnit.module('Views', { }, }); - kanban.reload(); + testUtils.kanban.reload(kanban); assert.verifySteps([ 'read_group', '/web/dataset/search_read', @@ -2461,22 +2415,18 @@ QUnit.module('Views', { }, }, }); - assert.strictEqual(kanban.$('.o_kanban_group:nth-child(1) .o_kanban_record').length, 2, - "column should contain 2 record(s)"); - assert.strictEqual(kanban.$('.o_kanban_group:nth-child(2) .o_kanban_record').length, 2, - "column should contain 2 record(s)"); + assert.containsN(kanban, '.o_kanban_group:nth-child(1) .o_kanban_record', 2); + assert.containsN(kanban, '.o_kanban_group:nth-child(2) .o_kanban_record', 2); + assert.containsN(kanban, '.thisiseditable', 4); - assert.strictEqual(kanban.$('.thisiseditable').length, 4, "all records should be editable"); var $record = kanban.$('.o_kanban_group:nth-child(1) .o_kanban_record:first'); var $group = kanban.$('.o_kanban_group:nth-child(2)'); envIDs = [3, 2, 4, 1]; // first record of first column moved to the bottom of second column - testUtils.dragAndDrop($record, $group); + testUtils.dom.dragAndDrop($record, $group); - assert.strictEqual(kanban.$('.o_kanban_group:nth-child(1) .o_kanban_record').length, 1, - "column should now contain 1 record(s)"); - assert.strictEqual(kanban.$('.o_kanban_group:nth-child(2) .o_kanban_record').length, 3, - "column should contain 3 record(s)"); - assert.strictEqual(kanban.$('.thisiseditable').length, 4, "all records should be editable"); + assert.containsOnce(kanban, '.o_kanban_group:nth-child(1) .o_kanban_record'); + assert.containsN(kanban, '.o_kanban_group:nth-child(2) .o_kanban_record', 3); + assert.containsN(kanban, '.thisiseditable', 4); kanban.destroy(); }); @@ -2506,19 +2456,15 @@ QUnit.module('Views', { return this._super(route, args); }, }); - assert.strictEqual(kanban.$('.o_kanban_group:nth-child(1) .o_kanban_record').length, 1, - "column should contain 1 record(s)"); - assert.strictEqual(kanban.$('.o_kanban_group:nth-child(2) .o_kanban_record').length, 1, - "column should contain 1 record(s)"); + assert.containsOnce(kanban, '.o_kanban_group:nth-child(1) .o_kanban_record'); + assert.containsOnce(kanban, '.o_kanban_group:nth-child(2) .o_kanban_record'); var $record = kanban.$('.o_kanban_group:nth-child(1) .o_kanban_record:first'); var $group = kanban.$('.o_kanban_group:nth-child(2)'); - testUtils.dragAndDrop($record, $group); + testUtils.dom.dragAndDrop($record, $group); - assert.strictEqual(kanban.$('.o_kanban_group:nth-child(1) .o_kanban_record').length, 0, - "column should now contain 0 record(s)"); - assert.strictEqual(kanban.$('.o_kanban_group:nth-child(2) .o_kanban_record').length, 2, - "column should contain 2 record(s)"); + assert.containsNone(kanban, '.o_kanban_group:nth-child(1) .o_kanban_record'); + assert.containsN(kanban, '.o_kanban_group:nth-child(2) .o_kanban_record', 2); kanban.destroy(); }); @@ -2550,42 +2496,36 @@ QUnit.module('Views', { }); // simulate an update coming from the searchview, with another groupby given kanban.update({groupBy: ['state']}); - assert.strictEqual(kanban.$('.o_kanban_group:nth-child(1) .o_kanban_record').length, 1, - "column should contain 1 record(s)"); - assert.strictEqual(kanban.$('.o_kanban_group:nth-child(2) .o_kanban_record').length, 1, - "column should contain 1 record(s)"); + assert.containsOnce(kanban, '.o_kanban_group:nth-child(1) .o_kanban_record'); + assert.containsOnce(kanban, '.o_kanban_group:nth-child(2) .o_kanban_record'); + // drag&drop a record in another column var $record = kanban.$('.o_kanban_group:nth-child(1) .o_kanban_record:first'); var $group = kanban.$('.o_kanban_group:nth-child(2)'); - testUtils.dragAndDrop($record, $group); + testUtils.dom.dragAndDrop($record, $group); // should not be draggable - assert.strictEqual(kanban.$('.o_kanban_group:nth-child(1) .o_kanban_record').length, 1, - "column should now contain 1 record(s)"); - assert.strictEqual(kanban.$('.o_kanban_group:nth-child(2) .o_kanban_record').length, 1, - "column should contain 1 record(s)"); + assert.containsOnce(kanban, '.o_kanban_group:nth-child(1) .o_kanban_record'); + assert.containsOnce(kanban, '.o_kanban_group:nth-child(2) .o_kanban_record'); // simulate an update coming from the searchview, with another groupby given kanban.update({groupBy: ['foo']}); - assert.strictEqual(kanban.$('.o_kanban_group:nth-child(1) .o_kanban_record').length, 1, - "column should contain 1 record(s)"); - assert.strictEqual(kanban.$('.o_kanban_group:nth-child(2) .o_kanban_record').length, 2, - "column should contain 2 record(s)"); + assert.containsOnce(kanban, '.o_kanban_group:nth-child(1) .o_kanban_record'); + assert.containsN(kanban, '.o_kanban_group:nth-child(2) .o_kanban_record', 2); + // drag&drop a record in another column $record = kanban.$('.o_kanban_group:nth-child(1) .o_kanban_record:first'); $group = kanban.$('.o_kanban_group:nth-child(2)'); - testUtils.dragAndDrop($record, $group); + testUtils.dom.dragAndDrop($record, $group); // should not be draggable - assert.strictEqual(kanban.$('.o_kanban_group:nth-child(1) .o_kanban_record').length, 1, - "column should now contain 1 record(s)"); - assert.strictEqual(kanban.$('.o_kanban_group:nth-child(2) .o_kanban_record').length, 2, - "column should contain 2 record(s)"); + assert.containsOnce(kanban, '.o_kanban_group:nth-child(1) .o_kanban_record'); + assert.containsN(kanban, '.o_kanban_group:nth-child(2) .o_kanban_record', 2); // drag&drop a record in the same column var $record1 = kanban.$('.o_kanban_group:nth-child(2) .o_kanban_record:eq(0)'); var $record2 = kanban.$('.o_kanban_group:nth-child(2) .o_kanban_record:eq(1)'); assert.strictEqual($record1.text(), "blipDEF", "first record should be DEF"); assert.strictEqual($record2.text(), "blipGHI", "second record should be GHI"); - testUtils.dragAndDrop($record2, $record1, {position: 'top'}); + testUtils.dom.dragAndDrop($record2, $record1, {position: 'top'}); // should still be able to resequence assert.strictEqual(kanban.$('.o_kanban_group:nth-child(2) .o_kanban_record:eq(0)').text(), "blipGHI", "records should have been resequenced"); @@ -2627,17 +2567,16 @@ QUnit.module('Views', { }, }); - assert.ok(kanban.$('.o_kanban_view').hasClass('o_kanban_grouped'), - "should have classname 'o_kanban_grouped'"); - assert.strictEqual(kanban.$('.o_kanban_group').length, 2, "should have " + 2 + " columns"); + assert.hasClass(kanban.$('.o_kanban_view'), 'o_kanban_grouped'); + assert.containsN(kanban, '.o_kanban_group', 2, "should have " + 2 + " columns"); // simulate an update coming from the searchview, with another groupby given kanban.update({groupBy: ['product_id']}); - assert.strictEqual(kanban.$('.o_kanban_group').length, 2, "should now have " + 3 + " columns"); + assert.containsN(kanban, '.o_kanban_group', 2, "should now have " + 3 + " columns"); // simulate an update coming from the searchview, removing the previously set groupby kanban.update({groupBy: []}); - assert.strictEqual(kanban.$('.o_kanban_group').length, 2, "should have " + 2 + " columns again"); + assert.containsN(kanban, '.o_kanban_group', 2, "should have " + 2 + " columns again"); kanban.destroy(); }); @@ -2671,7 +2610,7 @@ QUnit.module('Views', { '</t></templates></kanban>', }); - testUtils.intercept(kanban, 'switch_view', function (event) { + testUtils.mock.intercept(kanban, 'switch_view', function (event) { assert.deepEqual(event.data, { view_type: 'form', res_id: 1, @@ -2679,7 +2618,7 @@ QUnit.module('Views', { model: 'partner', }); }); - kanban.$('a').first().click(); + testUtils.dom.click(kanban.$('a').first()); kanban.destroy(); }); @@ -2709,12 +2648,13 @@ QUnit.module('Views', { // fold the second group and check that the res_ids it contains are no // longer in the environment envIDs = [1, 3]; - kanban.$('.o_kanban_group:last .o_kanban_toggle_fold').click(); + testUtils.kanban.toggleGroupSettings(kanban.$('.o_kanban_group:last')); + testUtils.dom.click(kanban.$('.o_kanban_group:last .o_kanban_toggle_fold')); // re-open the second group and check that the res_ids it contains are // back in the environment envIDs = [1, 3, 2, 4]; - kanban.$('.o_kanban_group:last .o_kanban_toggle_fold').click(); + testUtils.dom.click(kanban.$('.o_kanban_group:last')); kanban.destroy(); }); @@ -2747,11 +2687,11 @@ QUnit.module('Views', { return this._super(route, args); }, }); - assert.strictEqual(kanban.$('.o_column_quick_create').length, 1, "should have a quick create column"); + assert.containsOnce(kanban, '.o_column_quick_create', "should have a quick create column"); assert.notOk(kanban.$('.o_column_quick_create input').is(':visible'), "the input should not be visible"); - kanban.$('.o_quick_create_folded').click(); + testUtils.dom.click(kanban.$('.o_quick_create_folded')); assert.ok(kanban.$('.o_column_quick_create input').is(':visible'), "the input should be visible"); @@ -2764,39 +2704,39 @@ QUnit.module('Views', { assert.notOk(kanban.$('.o_column_quick_create input').is(':visible'), "the input should not be visible after discard"); - kanban.$('.o_quick_create_folded').click(); + testUtils.dom.click(kanban.$('.o_quick_create_folded')); assert.ok(kanban.$('.o_column_quick_create input').is(':visible'), "the input should be visible"); kanban.$('.o_column_quick_create input').val('new value'); - kanban.$('.o_column_quick_create button.o_kanban_add').click(); + testUtils.dom.click(kanban.$('.o_column_quick_create button.o_kanban_add')); assert.strictEqual(kanban.$('.o_kanban_group:last span:contains(new value)').length, 1, "the last column should be the newly created one"); assert.ok(_.isNumber(kanban.$('.o_kanban_group:last').data('id')), 'the created column should have the correct id'); - assert.ok(!kanban.$('.o_kanban_group:last').hasClass('o_column_folded'), + assert.doesNotHaveClass(kanban.$('.o_kanban_group:last'), 'o_column_folded', 'the created column should not be folded'); // fold and unfold the created column, and check that no RPC is done (as there is no record) nbRPCs = 0; - kanban.$('.o_kanban_group:last .o_kanban_toggle_fold').click(); // fold the group - assert.ok(kanban.$('.o_kanban_group:last').hasClass('o_column_folded'), + testUtils.kanban.toggleGroupSettings(kanban.$('.o_kanban_group:last')); + testUtils.dom.click(kanban.$('.o_kanban_group:last .o_kanban_toggle_fold')); + assert.hasClass(kanban.$('.o_kanban_group:last'),'o_column_folded', 'the created column should now be folded'); - kanban.$('.o_kanban_group:last').click(); - assert.ok(!kanban.$('.o_kanban_group:last').hasClass('o_column_folded'), - 'the created column should not be folded'); + testUtils.dom.click(kanban.$('.o_kanban_group:last')); + assert.doesNotHaveClass(kanban.$('.o_kanban_group:last'), 'o_column_folded'); assert.strictEqual(nbRPCs, 0, 'no rpc should have been done when folding/unfolding'); // quick create a record - kanban.$buttons.find('.o-kanban-button-new').click(); // Click on 'Create' - assert.ok(kanban.$('.o_kanban_group:first() > div:nth(1)').hasClass('o_kanban_quick_create'), + testUtils.kanban.clickCreate(kanban); + assert.hasClass(kanban.$('.o_kanban_group:first() > div:nth(1)'),'o_kanban_quick_create', "clicking on create should open the quick_create in the first column"); kanban.destroy(); }); QUnit.test('auto fold group when reach the limit', function (assert) { - assert.expect(7); + assert.expect(9); var data = this.data; for (var i = 0; i < 12; i++) { @@ -2835,28 +2775,19 @@ QUnit.module('Views', { }); // we look if column are fold/unfold according what is expected - assert.notOk(kanban.$('.o_kanban_group:nth-child(2)').hasClass('o_column_folded'), - 'second column must be unfolded by default'); - assert.notOk(kanban.$('.o_kanban_group:nth-child(4)').hasClass('o_column_folded'), - 'fourth column must be unfolded by default'); - assert.notOk(kanban.$('.o_kanban_group:nth-child(10)').hasClass('o_column_folded'), - 'tenth column must be unfolded by default'); - assert.ok( - kanban.$('.o_kanban_group:nth-child(3)').hasClass('o_column_folded') - && kanban.$('.o_kanban_group:nth-child(9)').hasClass('o_column_folded'), - 'third and ninth columns must be folded by default'); + assert.doesNotHaveClass(kanban.$('.o_kanban_group:nth-child(2)'), 'o_column_folded'); + assert.doesNotHaveClass(kanban.$('.o_kanban_group:nth-child(4)'), 'o_column_folded'); + assert.doesNotHaveClass(kanban.$('.o_kanban_group:nth-child(10)'), 'o_column_folded'); + assert.hasClass(kanban.$('.o_kanban_group:nth-child(3)'), 'o_column_folded'); + assert.hasClass(kanban.$('.o_kanban_group:nth-child(9)'), 'o_column_folded'); + // we look if columns are actually fold after we reached the limit - assert.ok( - kanban.$('.o_kanban_group:nth-child(13)').hasClass('o_column_folded') - && kanban.$('.o_kanban_group:nth-child(14)').hasClass('o_column_folded'), - 'thirteenth and fourtheenth columns must be folded because we reached the limit'); + assert.hasClass(kanban.$('.o_kanban_group:nth-child(13)'), 'o_column_folded'); + assert.hasClass(kanban.$('.o_kanban_group:nth-child(14)'), 'o_column_folded'); + // we look if we have the right count of folded/unfolded column - assert.strictEqual( - kanban.$('.o_kanban_group:not(.o_column_folded)').length, - 10, 'must have ten opened columns'); - assert.strictEqual( - kanban.$('.o_kanban_group.o_column_folded').length, - 4, 'must have four folded columns'); + assert.containsN(kanban, '.o_kanban_group:not(.o_column_folded)', 10); + assert.containsN(kanban, '.o_kanban_group.o_column_folded', 4); kanban.destroy(); }); @@ -2877,13 +2808,12 @@ QUnit.module('Views', { groupBy: ['product_id'], }); - kanban.$('.o_quick_create_folded').click(); - + testUtils.dom.click(kanban.$('.o_quick_create_folded')); assert.ok(kanban.$('.o_discard_msg').is(':visible'), 'the ESC to discard message is visible'); - // click in the column, but outside the input (to lose focus) - kanban.$('.o_kanban_header').click(); + // click outside the column (to lose focus) + testUtils.dom.clickFirst(kanban.$('.o_kanban_header')); assert.notOk(kanban.$('.o_discard_msg').is(':visible'), 'the ESC to discard message is no longer visible'); @@ -2893,7 +2823,7 @@ QUnit.module('Views', { QUnit.test('delete a column in grouped on m2o', function (assert) { assert.expect(36); - testUtils.patch(KanbanRenderer, { + testUtils.mock.patch(KanbanRenderer, { _renderGrouped: function () { this._super.apply(this, arguments); // set delay and revert animation time to 0 so dummy drag and drop works @@ -2931,14 +2861,14 @@ QUnit.module('Views', { }); // check the initial rendering - assert.strictEqual(kanban.$('.o_kanban_group').length, 2, "should have two columns"); + assert.containsN(kanban, '.o_kanban_group', 2, "should have two columns"); assert.strictEqual(kanban.$('.o_kanban_group:first').data('id'), 3, 'first column should be [3, "hello"]'); assert.strictEqual(kanban.$('.o_kanban_group:last').data('id'), 5, 'second column should be [5, "xmo"]'); assert.strictEqual(kanban.$('.o_kanban_group:last .o_column_title').text(), 'xmo', 'second column should have correct title'); - assert.strictEqual(kanban.$('.o_kanban_group:last .o_kanban_record').length, 2, + assert.containsN(kanban, '.o_kanban_group:last .o_kanban_record', 2, "second column should have two records"); // check available actions in kanban header's config dropdown @@ -2952,17 +2882,19 @@ QUnit.module('Views', { assert.ok(!kanban.$('.o_kanban_group:first .o_column_unarchive_records').length, "should not be able to restore all the records"); // delete second column (first cancel the confirm request, then confirm) - kanban.$('.o_kanban_group:last .o_column_delete').click(); // click on delete + testUtils.kanban.toggleGroupSettings(kanban.$('.o_kanban_group:last')); + testUtils.dom.click(kanban.$('.o_kanban_group:last .o_column_delete')); assert.ok($('.modal').length, 'a confirm modal should be displayed'); - $('.modal-footer .btn-secondary').click(); // click on cancel + testUtils.modal.clickButton('Cancel'); // click on cancel assert.strictEqual(kanban.$('.o_kanban_group:last').data('id'), 5, 'column [5, "xmo"] should still be there'); - kanban.$('.o_kanban_group:last .o_column_delete').click(); // click on delete + testUtils.kanban.toggleGroupSettings(kanban.$('.o_kanban_group:last')); + testUtils.dom.click(kanban.$('.o_kanban_group:last .o_column_delete')); assert.ok($('.modal').length, 'a confirm modal should be displayed'); - $('.modal-footer .btn-primary').click(); // click on confirm + testUtils.modal.clickButton('Ok'); // click on confirm assert.strictEqual(kanban.$('.o_kanban_group:last').data('id'), 3, 'last column should now be [3, "hello"]'); - assert.strictEqual(kanban.$('.o_kanban_group').length, 2, "should still have two columns"); + assert.containsN(kanban, '.o_kanban_group', 2, "should still have two columns"); assert.ok(!_.isNumber(kanban.$('.o_kanban_group:first').data('id')), 'first column should have no id (Undefined column)'); // check available actions on 'Undefined' column @@ -2979,22 +2911,23 @@ QUnit.module('Views', { "the old widgets should have been correctly deleted"); // test column drag and drop having an 'Undefined' column - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( kanban.$('.o_kanban_header_title:first'), kanban.$('.o_kanban_header_title:last'), {position: 'right'} ); assert.strictEqual(resequencedIDs, undefined, "resequencing require at least 2 not Undefined columns"); + testUtils.dom.click(kanban.$('.o_column_quick_create .o_quick_create_folded')); kanban.$('.o_column_quick_create input').val('once third column'); - kanban.$('.o_column_quick_create button.o_kanban_add').click(); + testUtils.dom.click(kanban.$('.o_column_quick_create button.o_kanban_add')); var newColumnID = kanban.$('.o_kanban_group:last').data('id'); - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( kanban.$('.o_kanban_header_title:first'), kanban.$('.o_kanban_header_title:last'), {position: 'right'} ); assert.deepEqual([3, newColumnID], resequencedIDs, "moving the Undefined column should not affect order of other columns") - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( kanban.$('.o_kanban_header_title:first'), kanban.$('.o_kanban_header_title:nth(1)'), {position: 'right'} ); @@ -3002,7 +2935,7 @@ QUnit.module('Views', { "moved column should be resequenced accordingly") kanban.destroy(); - testUtils.unpatch(KanbanRenderer); + testUtils.mock.unpatch(KanbanRenderer); }); QUnit.test('create a column, delete it and create another one', function (assert) { @@ -3021,24 +2954,25 @@ QUnit.module('Views', { groupBy: ['product_id'], }); - assert.strictEqual(kanban.$('.o_kanban_group').length, 2, "should have two columns"); + assert.containsN(kanban, '.o_kanban_group', 2, "should have two columns"); - kanban.$('.o_column_quick_create').click(); + testUtils.dom.click(kanban.$('.o_column_quick_create .o_quick_create_folded')); kanban.$('.o_column_quick_create input').val('new column 1'); - kanban.$('.o_column_quick_create button.o_kanban_add').click(); + testUtils.dom.click(kanban.$('.o_column_quick_create button.o_kanban_add')); - assert.strictEqual(kanban.$('.o_kanban_group').length, 3, "should have two columns"); + assert.containsN(kanban, '.o_kanban_group', 3, "should have two columns"); - kanban.$('.o_kanban_group:last .o_column_delete').click(); - $('.modal-footer .btn-primary').click(); + testUtils.kanban.toggleGroupSettings(kanban.$('.o_kanban_group:last')); + testUtils.dom.click(kanban.$('.o_kanban_group:last .o_column_delete')); + testUtils.modal.clickButton('Ok'); - assert.strictEqual(kanban.$('.o_kanban_group').length, 2, "should have twos columns"); + assert.containsN(kanban, '.o_kanban_group', 2, "should have twos columns"); - kanban.$('.o_column_quick_create').click(); + testUtils.dom.click(kanban.$('.o_column_quick_create .o_quick_create_folded')); kanban.$('.o_column_quick_create input').val('new column 2'); - kanban.$('.o_column_quick_create button.o_kanban_add').click(); + testUtils.dom.click(kanban.$('.o_column_quick_create button.o_kanban_add')); - assert.strictEqual(kanban.$('.o_kanban_group').length, 3, "should have three columns"); + assert.containsN(kanban, '.o_kanban_group', 3, "should have three columns"); assert.strictEqual(kanban.$('.o_kanban_group:last span:contains(new column 2)').length, 1, "the last column should be the newly created one"); kanban.destroy(); @@ -3071,33 +3005,37 @@ QUnit.module('Views', { 'title of the column should be "xmo"'); // edit the title of column [5, 'xmo'] and close without saving - kanban.$('.o_kanban_group[data-id=5] .o_column_edit').click(); // click on 'Edit' - assert.ok($('.modal .o_form_editable').length, 'a form view should be open in a modal'); + testUtils.kanban.toggleGroupSettings(kanban.$('.o_kanban_group[data-id=5]')); + testUtils.dom.click(kanban.$('.o_kanban_group[data-id=5] .o_column_edit')); + assert.containsOnce(document.body, '.modal .o_form_editable', + "a form view should be open in a modal"); assert.strictEqual($('.modal .o_form_editable input').val(), 'xmo', 'the name should be "xmo"'); - $('.modal .o_form_editable input').val('ged').trigger('input'); // change the value + testUtils.fields.editInput($('.modal .o_form_editable input'), 'ged'); // change the value nbRPCs = 0; - $('.modal-header .close').click(); // click on the cross to close the modal - assert.ok(!$('.modal').length, 'the modal should be closed'); + testUtils.dom.click($('.modal-header .close')); + assert.containsNone(document.body, '.modal'); assert.strictEqual(kanban.$('.o_kanban_group[data-id=5] .o_column_title').text(), 'xmo', 'title of the column should still be "xmo"'); assert.strictEqual(nbRPCs, 0, 'no RPC should have been done'); // edit the title of column [5, 'xmo'] and discard - kanban.$('.o_kanban_group[data-id=5] .o_column_edit').click(); // click on 'Edit' - $('.modal .o_form_editable input').val('ged').trigger('input'); // change the value + testUtils.kanban.toggleGroupSettings(kanban.$('.o_kanban_group[data-id=5]')); + testUtils.dom.click(kanban.$('.o_kanban_group[data-id=5] .o_column_edit')); + testUtils.fields.editInput($('.modal .o_form_editable input'), 'ged'); // change the value nbRPCs = 0; - $('.modal-footer .btn-secondary').click(); // click on discard - assert.ok(!$('.modal').length, 'the modal should be closed'); + testUtils.modal.clickButton('Discard'); + assert.containsNone(document.body, '.modal'); assert.strictEqual(kanban.$('.o_kanban_group[data-id=5] .o_column_title').text(), 'xmo', 'title of the column should still be "xmo"'); assert.strictEqual(nbRPCs, 0, 'no RPC should have been done'); // edit the title of column [5, 'xmo'] and save - kanban.$('.o_kanban_group[data-id=5] .o_column_edit').click(); // click on 'Edit' - $('.modal .o_form_editable input').val('ged').trigger('input'); // change the value + testUtils.kanban.toggleGroupSettings(kanban.$('.o_kanban_group[data-id=5]')); + testUtils.dom.click(kanban.$('.o_kanban_group[data-id=5] .o_column_edit')); + testUtils.fields.editInput($('.modal .o_form_editable input'), 'ged'); // change the value nbRPCs = 0; - $('.modal-footer .btn-primary').click(); // click on save + testUtils.modal.clickButton('Save'); // click on save assert.ok(!$('.modal').length, 'the modal should be closed'); assert.strictEqual(kanban.$('.o_kanban_group[data-id=5] .o_column_title').text(), 'ged', 'title of the column should be "ged"'); @@ -3122,10 +3060,8 @@ QUnit.module('Views', { domain: [['foo', '=', 'norecord']], }); - assert.strictEqual(kanban.$('.o_kanban_group').length, 0, - "there should be no column"); - assert.strictEqual(kanban.$('.o_column_quick_create').length, 1, - "should have a quick create column"); + assert.containsNone(kanban, '.o_kanban_group'); + assert.containsOnce(kanban, '.o_column_quick_create'); assert.ok(kanban.$('.o_column_quick_create input').is(':visible'), "the quick create should be opened"); @@ -3148,34 +3084,34 @@ QUnit.module('Views', { groupBy: ['product_id'], }); - assert.strictEqual(kanban.$('.o_kanban_group').length, 2, + assert.containsN(kanban, '.o_kanban_group', 2, "should have two columns"); - assert.strictEqual(kanban.$('.o_column_quick_create').length, 1, + assert.containsOnce(kanban, '.o_column_quick_create', "should have a ColumnQuickCreate widget"); - assert.strictEqual(kanban.$('.o_column_quick_create .o_quick_create_folded:visible').length, 1, + assert.containsOnce(kanban, '.o_column_quick_create .o_quick_create_folded:visible', "the ColumnQuickCreate should be folded"); - assert.strictEqual(kanban.$('.o_column_quick_create .o_quick_create_unfolded:visible').length, 0, + assert.containsNone(kanban, '.o_column_quick_create .o_quick_create_unfolded:visible', "the ColumnQuickCreate should be folded"); // add a new column - kanban.$('.o_column_quick_create .o_quick_create_folded').click(); - assert.strictEqual(kanban.$('.o_column_quick_create .o_quick_create_folded:visible').length, 0, + testUtils.dom.click(kanban.$('.o_column_quick_create .o_quick_create_folded')); + assert.containsNone(kanban, '.o_column_quick_create .o_quick_create_folded:visible', "the ColumnQuickCreate should be unfolded"); - assert.strictEqual(kanban.$('.o_column_quick_create .o_quick_create_unfolded:visible').length, 1, + assert.containsOnce(kanban, '.o_column_quick_create .o_quick_create_unfolded:visible', "the ColumnQuickCreate should be unfolded"); kanban.$('.o_column_quick_create input').val('New Column 1'); - kanban.$('.o_column_quick_create .btn-primary').click(); - assert.strictEqual(kanban.$('.o_kanban_group').length, 3, + testUtils.dom.click(kanban.$('.o_column_quick_create .btn-primary')); + assert.containsN(kanban, '.o_kanban_group', 3, "should now have three columns"); // add another column - assert.strictEqual(kanban.$('.o_column_quick_create .o_quick_create_folded:visible').length, 0, + assert.containsNone(kanban, '.o_column_quick_create .o_quick_create_folded:visible', "the ColumnQuickCreate should still be unfolded"); - assert.strictEqual(kanban.$('.o_column_quick_create .o_quick_create_unfolded:visible').length, 1, + assert.containsOnce(kanban, '.o_column_quick_create .o_quick_create_unfolded:visible', "the ColumnQuickCreate should still be unfolded"); kanban.$('.o_column_quick_create input').val('New Column 2'); - kanban.$('.o_column_quick_create .btn-primary').click(); - assert.strictEqual(kanban.$('.o_kanban_group').length, 4, + testUtils.dom.click(kanban.$('.o_column_quick_create .btn-primary')); + assert.containsN(kanban, '.o_kanban_group', 4, "should now have four columns"); kanban.destroy(); @@ -3206,17 +3142,17 @@ QUnit.module('Views', { groupBy: ['product_id'], }); - assert.strictEqual(kanban.$('.o_column_quick_create').length, 1, + assert.containsOnce(kanban, '.o_column_quick_create', "should have a ColumnQuickCreate widget"); // open the quick create - kanban.$('.o_column_quick_create .o_quick_create_folded').click(); + testUtils.dom.click(kanban.$('.o_column_quick_create .o_quick_create_folded')); - assert.strictEqual(kanban.$('.o_column_quick_create .o_kanban_examples:visible').length, 1, + assert.containsOnce(kanban, '.o_column_quick_create .o_kanban_examples:visible', "should have a link to see examples"); // click to see the examples - kanban.$('.o_column_quick_create .o_kanban_examples').click(); + testUtils.dom.click(kanban.$('.o_column_quick_create .o_kanban_examples')); assert.strictEqual($('.modal .o_kanban_examples_dialog').length, 1, "should have open the examples dialog"); @@ -3263,7 +3199,7 @@ QUnit.module('Views', { }); kanban.update({groupBy: []}); - assert.ok(kanban.$('.o_kanban_view').hasClass('o_kanban_grouped')); + assert.hasClass(kanban.$('.o_kanban_view'), 'o_kanban_grouped'); kanban.destroy(); }); @@ -3281,11 +3217,11 @@ QUnit.module('Views', { '</t></templates>' + '</kanban>', }); - assert.notOk(kanban.$('.o_kanban_view').hasClass('o_kanban_grouped'), "should not be grouped"); + assert.doesNotHaveClass(kanban.$('.o_kanban_view'), 'o_kanban_grouped', "should not be grouped"); kanban.update({groupBy: ['product_id']}); - assert.ok(kanban.$('.o_kanban_view').hasClass('o_kanban_grouped'), "should be grouped"); + assert.hasClass(kanban.$('.o_kanban_view'),'o_kanban_grouped', "should be grouped"); kanban.update({groupBy: []}); - assert.notOk(kanban.$('.o_kanban_view').hasClass('o_kanban_grouped'), "should not be grouped"); + assert.doesNotHaveClass(kanban.$('.o_kanban_view'), 'o_kanban_grouped', "should not be grouped"); kanban.destroy(); }); @@ -3313,7 +3249,7 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_view_nocontent').length, 1, + assert.containsOnce(kanban, '.o_view_nocontent', "should display the no content helper"); assert.strictEqual(kanban.$('.o_view_nocontent p.hello:contains(add a partner)').length, 1, @@ -3322,7 +3258,7 @@ QUnit.module('Views', { this.data.partner.records = records; kanban.reload(); - assert.strictEqual(kanban.$('.o_view_nocontent').length, 0, + assert.containsNone(kanban, '.o_view_nocontent', "should not display the no content helper"); kanban.destroy(); }); @@ -3362,9 +3298,9 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_group').length, 2, + assert.containsN(kanban, '.o_kanban_group', 2, "there should be two columns"); - assert.strictEqual(kanban.$('.o_kanban_record').length, 0, + assert.containsNone(kanban, '.o_kanban_record', "there should be no records"); kanban.destroy(); @@ -3392,13 +3328,13 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_group').length, 0, + assert.containsNone(kanban, '.o_kanban_group', "there should be no columns"); - assert.strictEqual(kanban.$('.o_kanban_record').length, 0, + assert.containsNone(kanban, '.o_kanban_record', "there should be no records"); - assert.strictEqual(kanban.$('.o_view_nocontent').length, 0, + assert.containsNone(kanban, '.o_view_nocontent', "there should be no nocontent helper (we are in 'column creation mode')"); - assert.strictEqual(kanban.$('.o_column_quick_create').length, 1, + assert.containsOnce(kanban, '.o_column_quick_create', "there should be a column quick create"); kanban.destroy(); }); @@ -3425,14 +3361,14 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_view_nocontent').length, 0, + assert.containsNone(kanban, '.o_view_nocontent', "there should be no nocontent helper (we are in 'column creation mode')"); // creating a new column kanban.$('.o_column_quick_create .o_input').val('applejack'); - kanban.$('.o_column_quick_create .o_kanban_add').click(); + testUtils.dom.click(kanban.$('.o_column_quick_create .o_kanban_add')); - assert.strictEqual(kanban.$('.o_view_nocontent').length, 0, + assert.containsNone(kanban, '.o_view_nocontent', "there should be no nocontent helper (still in 'column creation mode')"); // leaving column creation mode @@ -3441,7 +3377,7 @@ QUnit.module('Views', { which: $.ui.keyCode.ESCAPE, })); - assert.strictEqual(kanban.$('.o_view_nocontent').length, 1, + assert.containsOnce(kanban, '.o_view_nocontent', "there should be a nocontent helper"); kanban.destroy(); @@ -3478,12 +3414,12 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_view_nocontent').length, 1, + assert.containsOnce(kanban, '.o_view_nocontent', "there should be a nocontent helper"); - kanban.$('.o_kanban_add_column').click(); + testUtils.dom.click(kanban.$('.o_kanban_add_column')); - assert.strictEqual(kanban.$('.o_view_nocontent').length, 0, + assert.containsNone(kanban, '.o_view_nocontent', "there should be no nocontent helper (we are in 'column creation mode')"); kanban.destroy(); @@ -3520,15 +3456,15 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_view_nocontent').length, 1, + assert.containsOnce(kanban, '.o_view_nocontent', "there should be a nocontent helper"); // add a record - kanban.$('.o_kanban_quick_add').click(); - kanban.$('.o_kanban_quick_create .o_input').val('twilight sparkle').trigger('input'); - kanban.$('button.o_kanban_add').click(); + testUtils.dom.click(kanban.$('.o_kanban_quick_add')); + testUtils.fields.editInput(kanban.$('.o_kanban_quick_create .o_input'), 'twilight sparkle'); + testUtils.dom.click(kanban.$('.o_kanban_quick_create button.o_kanban_add')); - assert.strictEqual(kanban.$('.o_view_nocontent').length, 0, + assert.containsNone(kanban, '.o_view_nocontent', "there should be no nocontent helper (there is now one record)"); kanban.destroy(); @@ -3565,14 +3501,14 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_view_nocontent').length, 1, + assert.containsOnce(kanban, '.o_view_nocontent', "there should be a nocontent helper"); // add a record - kanban.$('.o_kanban_quick_add').click(); - kanban.$('.o_kanban_quick_create .o_input').val('twilight sparkle').trigger('input'); + testUtils.dom.click(kanban.$('.o_kanban_quick_add')); + testUtils.fields.editInput(kanban.$('.o_kanban_quick_create .o_input'), 'twilight sparkle'); - assert.strictEqual(kanban.$('.o_view_nocontent').length, 0, + assert.containsNone(kanban, '.o_view_nocontent', "there should be no nocontent helper (there is now one record)"); kanban.destroy(); @@ -3610,11 +3546,11 @@ QUnit.module('Views', { }); // add a record - kanban.$('.o_kanban_quick_add').click(); + testUtils.dom.click(kanban.$('.o_kanban_quick_add')); - kanban.$('.o_kanban_view').click(); + testUtils.dom.click(kanban.$('.o_kanban_view')); - assert.strictEqual(kanban.$('.o_view_nocontent').length, 1, + assert.containsOnce(kanban, '.o_view_nocontent', "there should be again a nocontent helper"); kanban.destroy(); @@ -3643,13 +3579,13 @@ QUnit.module('Views', { }, }); - assert.strictEqual(kanban.$('.o_kanban_group').length, 0, + assert.containsNone(kanban, '.o_kanban_group', "there should be no columns"); - assert.strictEqual(kanban.$('.o_kanban_record').length, 0, + assert.containsNone(kanban, '.o_kanban_record', "there should be no records"); - assert.strictEqual(kanban.$('.o_view_nocontent').length, 0, + assert.containsNone(kanban, '.o_view_nocontent', "there should not be a nocontent helper"); - assert.strictEqual(kanban.$('.o_column_quick_create').length, 0, + assert.containsNone(kanban, '.o_column_quick_create', "there should not be a column quick create"); kanban.destroy(); }); @@ -3678,9 +3614,9 @@ QUnit.module('Views', { '</kanban>', }); - assert.strictEqual(kanban.$(".o_btn_test_1").length, 1, + assert.containsOnce(kanban, ".o_btn_test_1", "kanban should have one buttons of type 1"); - assert.strictEqual(kanban.$(".o_btn_test_2").length, 3, + assert.containsN(kanban, ".o_btn_test_2", 3, "kanban should have three buttons of type 2"); kanban.destroy(); }); @@ -3709,14 +3645,14 @@ QUnit.module('Views', { "kanban should have at least one button a1"); var count = 0; - testUtils.intercept(kanban, 'execute_action', function (event) { + testUtils.mock.intercept(kanban, 'execute_action', function (event) { count++; event.data.on_closed(); }); - $('button[data-name="a1"]').first().click(); + testUtils.dom.click($('button[data-name="a1"]').first()); assert.strictEqual(count, 1, "should have triggered a execute action"); - $('button[data-name="a1"]').first().click(); + testUtils.dom.click($('button[data-name="a1"]').first()); assert.strictEqual(count, 1, "double-click on kanban actions should be debounced"); assert.verifySteps([ @@ -3751,13 +3687,13 @@ QUnit.module('Views', { '</kanban>', }); - testUtils.intercept(kanban, 'execute_action', function (event) { + testUtils.mock.intercept(kanban, 'execute_action', function (event) { data.partner.records[0].active = false; event.data.on_closed(); }); assert.strictEqual(kanban.$('.o_kanban_record:contains(yop)').length, 1, "should display 'yop' record"); - kanban.$('.o_kanban_record:contains(yop) button[data-name="toggle_active"]').click(); + testUtils.dom.click(kanban.$('.o_kanban_record:contains(yop) button[data-name="toggle_active"]')); assert.strictEqual(kanban.$('.o_kanban_record:contains(yop)').length, 0, "should remove 'yop' record from the view"); kanban.destroy(); @@ -3781,12 +3717,12 @@ QUnit.module('Views', { '</kanban>', }); - testUtils.intercept(kanban, 'execute_action', function (event) { + testUtils.mock.intercept(kanban, 'execute_action', function (event) { event.data.on_closed(); }); try { - kanban.$('.o_kanban_record:contains(yop) button[data-name="toggle_action"]').click(); + testUtils.dom.click(kanban.$('.o_kanban_record:contains(yop) button[data-name="toggle_action"]')); assert.strictEqual(true, true, 'Everything went fine'); } catch (e) { assert.strictEqual(true, false, 'Error triggered at action execution'); @@ -3879,9 +3815,9 @@ QUnit.module('Views', { }, }); - assert.ok(kanban.$('.o_kanban_view').hasClass('ui-sortable'), + assert.hasClass(kanban.$('.o_kanban_view'),'ui-sortable', "columns should be sortable"); - assert.strictEqual(kanban.$('.o_kanban_group').length, 2, + assert.containsN(kanban, '.o_kanban_group', 2, "should have two columns"); assert.strictEqual(kanban.$('.o_kanban_group:first').data('id'), 3, "first column should be id 3 before resequencing"); @@ -3921,7 +3857,7 @@ QUnit.module('Views', { '</kanban>', }); - assert.strictEqual(kanban.$('button.oe_kanban_action_button').length, 1, + assert.containsOnce(kanban, 'button.oe_kanban_action_button', "only one button should be visible"); kanban.destroy(); }); @@ -3967,7 +3903,7 @@ QUnit.module('Views', { var $firstRecord = kanban.$('.o_kanban_record:first()'); - assert.strictEqual(kanban.$('.o_kanban_record.oe_kanban_color_12').length, 0, + assert.containsNone(kanban, '.o_kanban_record.oe_kanban_color_12', "no record should have the color 12"); assert.strictEqual($firstRecord.find('.oe_kanban_colorpicker').length, 1, "there should be a color picker"); @@ -3975,7 +3911,8 @@ QUnit.module('Views', { "the color picker should have 12 children (the colors)"); // Set a color - $firstRecord.find('.oe_kanban_colorpicker a.oe_kanban_color_9').click(); + testUtils.kanban.toggleRecordDropdown($firstRecord); + testUtils.dom.click($firstRecord.find('.oe_kanban_colorpicker a.oe_kanban_color_9')); assert.ok(writeOnColor, "should write on the color field"); $firstRecord = kanban.$('.o_kanban_record:first()'); // First record is reloaded here assert.ok($firstRecord.is('.oe_kanban_color_9'), @@ -4020,7 +3957,7 @@ QUnit.module('Views', { // load more envIDs = [1, 2, 3, 4]; // id 3 will be loaded - kanban.$('.o_kanban_group:eq(1)').find('.o_kanban_load_more').click(); + testUtils.dom.click(kanban.$('.o_kanban_group:eq(1)').find('.o_kanban_load_more')); assert.strictEqual(kanban.$('.o_kanban_group:eq(1) .o_kanban_record').length, 3, "there should now be 3 records in the column"); @@ -4086,7 +4023,7 @@ QUnit.module('Views', { assert.verifySteps([[7]], "only the appearing category should be fetched"); // load more - kanban.$('.o_kanban_group:eq(1)').find('.o_kanban_load_more').click(); + testUtils.dom.click(kanban.$('.o_kanban_group:eq(1)').find('.o_kanban_load_more')); assert.strictEqual(kanban.$('.o_kanban_group:eq(1) .o_kanban_record').length, 3, "there should now be 3 records in the column"); @@ -4112,14 +4049,14 @@ QUnit.module('Views', { groupBy: ['product_id'], }); - assert.ok(kanban.$buttons.find('.o-kanban-button-new').hasClass('o_hidden'), + assert.isNotVisible(kanban.$buttons.find('.o-kanban-button-new'), "Create button should be hidden"); - kanban.$('.o_column_quick_create').click(); + testUtils.dom.click(kanban.$('.o_column_quick_create')); kanban.$('.o_column_quick_create input').val('new column'); - kanban.$('.o_column_quick_create button.o_kanban_add').click(); + testUtils.dom.click(kanban.$('.o_column_quick_create button.o_kanban_add')); - assert.notOk(kanban.$buttons.find('.o-kanban-button-new').hasClass('o_hidden'), + assert.isVisible(kanban.$buttons.find('.o-kanban-button-new'), "Create button should now be visible"); kanban.destroy(); }); @@ -4149,13 +4086,13 @@ QUnit.module('Views', { }, }); - assert.ok(kanban.$('.o_kanban_view').hasClass('o_kanban_grouped'), + assert.hasClass(kanban.$('.o_kanban_view'),'o_kanban_grouped', "should have classname 'o_kanban_grouped'"); - assert.strictEqual(kanban.$('.o_kanban_group').length, 2, "should have " + 2 + " columns"); + assert.containsN(kanban, '.o_kanban_group', 2, "should have " + 2 + " columns"); // simulate an update coming from the searchview, with another groupby given kanban.update({groupBy: ['product_id']}); - assert.strictEqual(kanban.$('.o_kanban_group').length, 3, "should have " + 3 + " columns"); + assert.containsN(kanban, '.o_kanban_group', 3, "should have " + 3 + " columns"); assert.strictEqual(kanban.$('.o_kanban_group:nth-child(1) .o_kanban_record').length, 1, "column should contain 1 record(s)"); assert.strictEqual(kanban.$('.o_kanban_group:nth-child(2) .o_kanban_record').length, 2, @@ -4194,18 +4131,18 @@ QUnit.module('Views', { groupBy: ['product_id'], }); - kanban.$('.o_column_quick_create').click(); + testUtils.dom.click(kanban.$('.o_column_quick_create')); kanban.$('.o_column_quick_create input').val('column1'); - kanban.$('.o_column_quick_create button.o_kanban_add').click(); + testUtils.dom.click(kanban.$('.o_column_quick_create button.o_kanban_add')); - kanban.$('.o_column_quick_create').click(); + testUtils.dom.click(kanban.$('.o_column_quick_create')); kanban.$('.o_column_quick_create input').val('column2'); - kanban.$('.o_column_quick_create button.o_kanban_add').click(); + testUtils.dom.click(kanban.$('.o_column_quick_create button.o_kanban_add')); - kanban.$('.o_kanban_group:eq(1) .o_kanban_quick_add i').click(); + testUtils.dom.click(kanban.$('.o_kanban_group:eq(1) .o_kanban_quick_add i')); var $quickCreate = kanban.$('.o_kanban_group:eq(1) .o_kanban_quick_create'); - $quickCreate.find('input').val('new partner').trigger('input'); - $quickCreate.find('button.o_kanban_add').click(); + testUtils.fields.editInput($quickCreate.find('input'), 'new partner'); + testUtils.dom.click($quickCreate.find('button.o_kanban_add')); assert.strictEqual(kanban.$('.o_kanban_group:eq(0) .o_kanban_record').length, 0, "column should contain 0 record"); @@ -4214,7 +4151,7 @@ QUnit.module('Views', { var $record = kanban.$('.o_kanban_group:eq(1) .o_kanban_record:eq(0)'); var $group = kanban.$('.o_kanban_group:eq(0)'); - testUtils.dragAndDrop($record, $group); + testUtils.dom.dragAndDrop($record, $group); assert.strictEqual(kanban.$('.o_kanban_group:eq(0) .o_kanban_record').length, 1, "column should contain 1 records"); @@ -4224,7 +4161,7 @@ QUnit.module('Views', { $record = kanban.$('.o_kanban_group:eq(0) .o_kanban_record:eq(0)'); $group = kanban.$('.o_kanban_group:eq(1)'); - testUtils.dragAndDrop($record, $group); + testUtils.dom.dragAndDrop($record, $group); assert.strictEqual(kanban.$('.o_kanban_group:eq(0) .o_kanban_record').length, 0, "column should contain 0 records"); @@ -4258,19 +4195,19 @@ QUnit.module('Views', { }, }); - kanban.$('.o_column_quick_create').click(); + testUtils.dom.click(kanban.$('.o_column_quick_create')); kanban.$('.o_column_quick_create input').val('column1'); - kanban.$('.o_column_quick_create button.o_kanban_add').click(); + testUtils.dom.click(kanban.$('.o_column_quick_create button.o_kanban_add')); - kanban.$('.o_kanban_group:eq(0) .o_kanban_quick_add i').click(); + testUtils.dom.click(kanban.$('.o_kanban_group:eq(0) .o_kanban_quick_add i')); var $quickCreate = kanban.$('.o_kanban_group:eq(0) .o_kanban_quick_create'); - $quickCreate.find('input').val('record1').trigger('input'); - $quickCreate.find('button.o_kanban_add').click(); + testUtils.fields.editInput($quickCreate.find('input'), 'record1'); + testUtils.dom.click($quickCreate.find('button.o_kanban_add')); - kanban.$('.o_kanban_group:eq(0) .o_kanban_quick_add i').click(); + testUtils.dom.click(kanban.$('.o_kanban_group:eq(0) .o_kanban_quick_add i')); $quickCreate = kanban.$('.o_kanban_group:eq(0) .o_kanban_quick_create'); - $quickCreate.find('input').val('record2').trigger('input'); - $quickCreate.find('button.o_kanban_add').click(); + testUtils.fields.editInput($quickCreate.find('input'), 'record2'); + testUtils.dom.click($quickCreate.find('button.o_kanban_add')); assert.strictEqual(kanban.$('.o_kanban_group:eq(0) .o_kanban_record').length, 2, "column should contain 2 records"); @@ -4281,7 +4218,7 @@ QUnit.module('Views', { var $record1 = kanban.$('.o_kanban_group:eq(0) .o_kanban_record:eq(1)'); var $record2 = kanban.$('.o_kanban_group:eq(0) .o_kanban_record:eq(0)'); - testUtils.dragAndDrop($record1, $record2, {position: 'top'}); + testUtils.dom.dragAndDrop($record1, $record2, {position: 'top'}); assert.strictEqual(kanban.$('.o_kanban_group:eq(0) .o_kanban_record').length, 2, "column should contain 2 records"); @@ -4290,7 +4227,7 @@ QUnit.module('Views', { assert.strictEqual(kanban.$('.o_kanban_group:eq(0) .o_kanban_record:eq(1)').text(), "record2", "records should be correctly ordered"); - testUtils.dragAndDrop($record2, $record1, {position: 'top'}); + testUtils.dom.dragAndDrop($record2, $record1, {position: 'top'}); assert.strictEqual(kanban.$('.o_kanban_group:eq(0) .o_kanban_record').length, 2, "column should contain 2 records"); @@ -4356,7 +4293,7 @@ QUnit.module('Views', { groupBy: ['bar'], }); - assert.strictEqual(kanban.$('.o_kanban_counter').length, this.data.product.records.length, + assert.containsN(kanban, '.o_kanban_counter', this.data.product.records.length, "kanban counters should have been created"); assert.strictEqual(parseInt(kanban.$('.o_kanban_counter_side').last().text()), 36, @@ -4419,11 +4356,11 @@ QUnit.module('Views', { // Create a new column: this should create an empty progressbar var $columnQuickCreate = kanban.$('.o_column_quick_create'); - $columnQuickCreate.click(); + testUtils.dom.click($columnQuickCreate.find('.o_quick_create_folded')); $columnQuickCreate.find('input').val('test'); - $columnQuickCreate.find('.btn-primary').click(); + testUtils.dom.click($columnQuickCreate.find('.btn-primary')); - assert.strictEqual(kanban.$('.o_kanban_counter').length, nbProgressBars + 1, + assert.containsN(kanban, '.o_kanban_counter', nbProgressBars + 1, "a new column with a new column progressbar should have been created"); kanban.destroy(); @@ -4449,9 +4386,9 @@ QUnit.module('Views', { }); var initialCount = parseInt(kanban.$('.o_kanban_counter_side:first').text()); - kanban.$('.o_kanban_quick_add:first').click(); - kanban.$('.o_kanban_quick_create input').val('Test').trigger('input'); - kanban.$('.o_kanban_add').click(); + testUtils.dom.click(kanban.$('.o_kanban_quick_add:first')); + testUtils.fields.editInput(kanban.$('.o_kanban_quick_create input'), 'Test'); + testUtils.dom.click(kanban.$('.o_kanban_add')); var lastCount = parseInt(kanban.$('.o_kanban_counter_side:first').text()); assert.strictEqual(lastCount, initialCount + 1, "kanban counters should have updated on quick create"); @@ -4480,8 +4417,8 @@ QUnit.module('Views', { }); // we have 1 record shown, load 2 more and check it worked - kanban.$('.o_kanban_group').find('.o_kanban_load_more').click(); - kanban.$('.o_kanban_group').find('.o_kanban_load_more').click(); + testUtils.dom.click(kanban.$('.o_kanban_group').find('.o_kanban_load_more')); + testUtils.dom.click(kanban.$('.o_kanban_group').find('.o_kanban_load_more')); var shownIDs = _.map(kanban.$('.o_kanban_record'), function(record) { return parseInt(record.innerText); }); @@ -4521,9 +4458,9 @@ QUnit.module('Views', { "the counter progressbars should be correctly displayed"); // archive all records of the second columns - kanban.$('.o_kanban_group:eq(1) .o_kanban_config a.o-no-caret').click(); - kanban.$('.o_column_archive_records:visible').click(); - $('.modal-footer button:first').click(); + testUtils.kanban.toggleGroupSettings(kanban.$('.o_kanban_group:eq(1)')); + testUtils.dom.click(kanban.$('.o_column_archive_records:visible')); + testUtils.dom.click($('.modal-footer button:first')); assert.strictEqual(kanban.$('.o_kanban_group:eq(1) .o_kanban_counter_side').text(), "0", "counter should contain the correct value"); @@ -4564,9 +4501,9 @@ QUnit.module('Views', { }); // archive all records of the first column - kanban.$('.o_kanban_group:first .o_kanban_config a.o-no-caret').click(); - kanban.$('.o_column_archive_records:visible').click(); - $('.modal-footer button:first').click(); + testUtils.kanban.toggleGroupSettings(kanban.$('.o_kanban_group:first')); + testUtils.dom.click(kanban.$('.o_column_archive_records:visible')); + testUtils.dom.click($('.modal-footer button:first')); assert.verifySteps([ [1, 2, 3, 4], @@ -4649,15 +4586,15 @@ QUnit.module('Views', { assert.strictEqual(kanban.$('.o_kanban_group:eq(0) .o_kanban_counter_side').text(), "1", "counter should contain the correct value"); - testUtils.dragAndDrop(kanban.$('.o_kanban_group:eq(0) .o_kanban_record:eq(0)'), kanban.$('.o_kanban_group:eq(1)')); + testUtils.dom.dragAndDrop(kanban.$('.o_kanban_group:eq(0) .o_kanban_record:eq(0)'), kanban.$('.o_kanban_group:eq(1)')); assert.strictEqual(kanban.$('.o_kanban_group:eq(0) .o_kanban_counter_side').text(), "0", "counter should contain the correct value"); - testUtils.dragAndDrop(kanban.$('.o_kanban_group:eq(1) .o_kanban_record:eq(2)'), kanban.$('.o_kanban_group:eq(0)')); + testUtils.dom.dragAndDrop(kanban.$('.o_kanban_group:eq(1) .o_kanban_record:eq(2)'), kanban.$('.o_kanban_group:eq(0)')); assert.strictEqual(kanban.$('.o_kanban_group:eq(0) .o_kanban_counter_side').text(), "1", "counter should contain the correct value"); - testUtils.dragAndDrop(kanban.$('.o_kanban_group:eq(0) .o_kanban_record:eq(0)'), kanban.$('.o_kanban_group:eq(1)')); + testUtils.dom.dragAndDrop(kanban.$('.o_kanban_group:eq(0) .o_kanban_record:eq(0)'), kanban.$('.o_kanban_group:eq(1)')); assert.strictEqual(kanban.$('.o_kanban_group:eq(0) .o_kanban_counter_side').text(), "0", "counter should contain the correct value"); @@ -4683,11 +4620,12 @@ QUnit.module('Views', { groupBy: ['bar'], }); - var initialCount = parseInt(kanban.$('.o_kanban_counter_side').eq(1).text()); + var $secondGroup = kanban.$('.o_kanban_group:eq(1)'); + var initialCount = parseInt($secondGroup.find('.o_kanban_counter_side').text()); assert.strictEqual(initialCount, 3, "Initial count should be Three"); - kanban.$('.bg-success-full').click(); - var lastCount = parseInt(kanban.$('.o_kanban_counter_side').eq(1).text()); + testUtils.dom.click($secondGroup.find('.bg-success-full')); + var lastCount = parseInt($secondGroup.find('.o_kanban_counter_side').text()); assert.strictEqual(lastCount, 1, "kanban counters should vary according to what subgroup is selected"); @@ -4720,11 +4658,11 @@ QUnit.module('Views', { var initialCount = parseInt(kanban.$('.o_kanban_counter_side:first').text()); - // click on 'Create', fill the quick create and validate - kanban.$buttons.find('.o-kanban-button-new').click(); + testUtils.kanban.clickCreate(kanban); + // fill the quick create and validate var $quickCreate = kanban.$('.o_kanban_group:first .o_kanban_quick_create'); - $quickCreate.find('.o_field_widget[name=int_field]').val('44').trigger('input'); - $quickCreate.find('button.o_kanban_add').click(); + testUtils.fields.editInput($quickCreate.find('.o_field_widget[name=int_field]'), '44'); + testUtils.dom.click($quickCreate.find('button.o_kanban_add')); var lastCount = parseInt(kanban.$('.o_kanban_counter_side:first').text()); assert.strictEqual(lastCount, initialCount + 44, @@ -4759,12 +4697,12 @@ QUnit.module('Views', { var $quickCreateGroup; var $groups; _quickCreateAndTest(); - testUtils.dragAndDrop($groups.first().find('.o_kanban_record:first'), $groups.eq(1)); + testUtils.dom.dragAndDrop($groups.first().find('.o_kanban_record:first'), $groups.eq(1)); _quickCreateAndTest(); kanban.destroy(); function _quickCreateAndTest() { - kanban.$buttons.find('.o-kanban-button-new').click(); + testUtils.kanban.clickCreate(kanban); $quickCreateGroup = kanban.$('.o_kanban_quick_create').closest('.o_kanban_group'); $groups = kanban.$('.o_kanban_group'); assert.strictEqual($quickCreateGroup[0], $groups[0], @@ -4802,7 +4740,7 @@ QUnit.module('Views', { assert.expect(1); var instanceNumber = 0; - testUtils.patch(mixins.ParentedMixin, { + testUtils.mock.patch(mixins.ParentedMixin, { init: function () { instanceNumber++; return this._super.apply(this, arguments); @@ -4850,7 +4788,7 @@ QUnit.module('Views', { kanban.destroy(); - testUtils.unpatch(mixins.ParentedMixin); + testUtils.mock.unpatch(mixins.ParentedMixin); }); QUnit.test('grouped kanban becomes ungrouped when clearing domain then clearing groupby', function (assert) { @@ -4886,18 +4824,18 @@ QUnit.module('Views', { }, }); - assert.ok(kanban.$('.o_kanban_view').hasClass('o_kanban_grouped'), + assert.hasClass(kanban.$('.o_kanban_view'),'o_kanban_grouped', "the kanban view should be grouped"); - assert.notOk(kanban.$('.o_kanban_view').hasClass('o_kanban_ungrouped'), + assert.doesNotHaveClass(kanban.$('.o_kanban_view'), 'o_kanban_ungrouped', "the kanban view should not be ungrouped"); kanban.update({domain: []}); // 1st update on kanban view kanban.update({groupBy: false}); // 2n update on kanban view def.resolve(); // simulate slow 1st update of kanban view - assert.notOk(kanban.$('.o_kanban_view').hasClass('o_kanban_grouped'), + assert.doesNotHaveClass(kanban.$('.o_kanban_view'), 'o_kanban_grouped', "the kanban view should not longer be grouped"); - assert.ok(kanban.$('.o_kanban_view').hasClass('o_kanban_ungrouped'), + assert.hasClass(kanban.$('.o_kanban_view'),'o_kanban_ungrouped', "the kanban view should have become ungrouped"); kanban.destroy(); @@ -4910,7 +4848,8 @@ QUnit.module('Views', { View: KanbanView, model: 'partner', data: this.data, - arch: '<kanban class="o_kanban_test" on_create="quick_create"><templates><t t-name="kanban-box">' + + // force group_create to false, otherwise the CREATE button in control panel is hidden + arch: '<kanban class="o_kanban_test" group_create="0" on_create="quick_create"><templates><t t-name="kanban-box">' + '<div>' + '<field name="name"/>' + '</div>' + @@ -4923,7 +4862,7 @@ QUnit.module('Views', { }, }, }); - kanban.$buttons.find('.o-kanban-button-new').click(); + testUtils.kanban.clickCreate(kanban); kanban.destroy(); }); @@ -5071,7 +5010,7 @@ QUnit.module('Views', { '</t></templates></kanban>', }); - testUtils.intercept(kanban, 'switch_view', function (event) { + testUtils.mock.intercept(kanban, 'switch_view', function (event) { assert.deepEqual(event.data, { view_type: 'form', res_id: 1, diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index 030a676f4eb..51a4d424d10 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -105,15 +105,15 @@ QUnit.module('Views', { arch: '<tree><field name="foo"/><field name="int_field"/></tree>', }); - assert.notOk(list.$el.hasClass('o_cannot_create'), + assert.doesNotHaveClass(list.$el, 'o_cannot_create', "should not have className 'o_cannot_create'"); // 3 th (1 for checkbox, 2 for columns) - assert.strictEqual(list.$('th').length, 3, "should have 3 columns"); + assert.containsN(list, 'th', 3, "should have 3 columns"); assert.strictEqual(list.$('td:contains(gnap)').length, 1, "should contain gnap"); - assert.strictEqual(list.$('tbody tr').length, 4, "should have 4 rows"); - assert.strictEqual(list.$('th.o_column_sortable').length, 1, "should have 1 sortable column"); + assert.containsN(list, 'tbody tr', 4, "should have 4 rows"); + assert.containsOnce(list, 'th.o_column_sortable', "should have 1 sortable column"); assert.strictEqual(list.$('thead th:nth(2)').css('text-align'), 'right', "header cells of integer fields should be right aligned"); @@ -139,7 +139,7 @@ QUnit.module('Views', { arch: '<tree create="0"><field name="foo"/></tree>', }); - assert.ok(list.$el.hasClass('o_cannot_create'), + assert.hasClass(list.$el,'o_cannot_create', "should have className 'o_cannot_create'"); assert.strictEqual(list.$buttons.find('.o_list_button_add').length, 0, "should not have the 'Create' button"); @@ -158,11 +158,11 @@ QUnit.module('Views', { arch: '<tree delete="0"><field name="foo"/></tree>', }); - assert.ok(list.sidebar.$el.hasClass('o_hidden'), 'sidebar should be invisible'); + assert.isNotVisible(list.sidebar.$el, 'sidebar should be invisible'); assert.ok(list.$('tbody td.o_list_record_selector').length, 'should have at least one record'); - list.$('tbody td.o_list_record_selector:first input').click(); - assert.ok(!list.sidebar.$el.hasClass('o_hidden'), 'sidebar should be visible'); + testUtils.dom.click(list.$('tbody td.o_list_record_selector:first input')); + assert.isVisible(list.sidebar.$el, 'sidebar should be visible'); assert.notOk(list.sidebar.$('a:contains(Delete)').length, 'sidebar should not have Delete button'); list.destroy(); @@ -178,8 +178,8 @@ QUnit.module('Views', { arch: '<tree editable="bottom"><field name="foo"/><field name="bar"/></tree>', }); - assert.strictEqual(list.$('th').length, 3, "should have 2 th"); - assert.strictEqual(list.$('th').length, 3, "should have 3 th"); + assert.containsN(list, 'th', 3, "should have 2 th"); + assert.containsN(list, 'th', 3, "should have 3 th"); assert.strictEqual(list.$('td:contains(yop)').length, 1, "should contain yop"); assert.ok(list.$buttons.find('.o_list_button_add').is(':visible'), @@ -189,7 +189,7 @@ QUnit.module('Views', { assert.ok(!list.$buttons.find('.o_list_button_discard').is(':visible'), "should not have a visible discard button"); - list.$('td:not(.o_list_record_selector)').first().click(); + testUtils.dom.click(list.$('td:not(.o_list_record_selector)').first()); assert.ok(!list.$buttons.find('.o_list_button_add').is(':visible'), "should not have a visible Create button"); @@ -198,7 +198,7 @@ QUnit.module('Views', { assert.ok(list.$buttons.find('.o_list_button_discard').is(':visible'), "should have a visible discard button"); - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); assert.ok(list.$buttons.find('.o_list_button_add').is(':visible'), "should have a visible Create button"); @@ -223,7 +223,7 @@ QUnit.module('Views', { }); // 1 th for checkbox, 1 for 1 visible column - assert.strictEqual(list.$('th').length, 2, "should have 2 th"); + assert.containsN(list, 'th', 2, "should have 2 th"); list.destroy(); }); @@ -241,11 +241,11 @@ QUnit.module('Views', { '</tree>', }); - assert.strictEqual(list.$('tbody tr:first td').length, 4, + assert.containsN(list, 'tbody tr:first td', 4, "there should be 4 cells in the first row"); - assert.strictEqual(list.$('tbody td.o_invisible_modifier').length, 1, + assert.containsOnce(list, 'tbody td.o_invisible_modifier', "there should be 1 invisible bar cell"); - assert.ok(list.$('tbody tr:first td:eq(2)').hasClass('o_invisible_modifier'), + assert.hasClass(list.$('tbody tr:first td:eq(2)'),'o_invisible_modifier', "the 3rd cell should be invisible"); assert.strictEqual(list.$('tbody tr:eq(0) td:visible').length, list.$('tbody tr:eq(1) td:visible').length, "there should be the same number of visible cells in different rows"); @@ -271,7 +271,7 @@ QUnit.module('Views', { }, }); - list.$buttons.find('.o_list_button_add').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); assert.verifySteps(['search_read', 'default_get'], "no nameget should be done"); list.destroy(); @@ -288,7 +288,7 @@ QUnit.module('Views', { domain: [['bar', '=', true]], }); - assert.strictEqual(list.$('tbody tr').length, 4, "should have 4 rows"); + assert.containsN(list, 'tbody tr', 4, "should have 4 rows"); list.destroy(); }); @@ -305,8 +305,8 @@ QUnit.module('Views', { assert.strictEqual(list.$('th:contains(Foo)').length, 1, "should contain Foo"); assert.strictEqual(list.$('th:contains(Bar)').length, 1, "should contain Bar"); - assert.strictEqual(list.$('tr.o_group_header').length, 2, "should have 2 .o_group_header"); - assert.strictEqual(list.$('th.o_group_name').length, 2, "should have 2 .o_group_name"); + assert.containsN(list, 'tr.o_group_header', 2, "should have 2 .o_group_header"); + assert.containsN(list, 'th.o_group_name', 2, "should have 2 .o_group_name"); list.destroy(); }); @@ -404,9 +404,9 @@ QUnit.module('Views', { groupBy: ['foo'], }); - list.$('th.o_group_name').get(1).click(); + testUtils.dom.click(list.$('th.o_group_name:nth(1)')); assert.strictEqual(list.$('tbody:eq(1) tr').length, 2, "open group should contain 2 records"); - assert.strictEqual(list.$('tbody').length, 3, "should contain 3 tbody"); + assert.containsN(list, 'tbody', 3, "should contain 3 tbody"); assert.strictEqual(list.$('td:contains(9)').length, 1, "should contain 9"); assert.strictEqual(list.$('td:contains(-4)').length, 1, "should contain -4"); assert.strictEqual(list.$('td:contains(10)').length, 1, "should contain 10"); @@ -424,16 +424,16 @@ QUnit.module('Views', { arch: '<tree><field name="foo"/></tree>', }); - testUtils.intercept(list, "open_record", function () { + testUtils.mock.intercept(list, "open_record", function () { assert.ok("list view should trigger 'open_record' event"); }); - list.$('tr td:not(.o_list_record_selector)').first().click(); + testUtils.dom.click(list.$('tr td:not(.o_list_record_selector)').first()); list.update({groupBy: ['foo']}); - assert.strictEqual(list.$('tr.o_group_header').length, 3, "list should be grouped"); - list.$('th.o_group_name').first().click(); + assert.containsN(list, 'tr.o_group_header', 3, "list should be grouped"); + testUtils.dom.click(list.$('th.o_group_name').first()); - list.$('tr:not(.o_group_header) td:not(.o_list_record_selector)').first().click(); + testUtils.dom.click(list.$('tr:not(.o_group_header) td:not(.o_list_record_selector)').first()); list.destroy(); }); @@ -455,31 +455,33 @@ QUnit.module('Views', { var $td = list.$('td:not(.o_list_record_selector)').first(); var $second_td = list.$('td:not(.o_list_record_selector)').eq(1); var $third_td = list.$('td:not(.o_list_record_selector)').eq(2); - $td.click(); - assert.ok($td.parent().hasClass('o_selected_row'), + testUtils.dom.click($td); + assert.hasClass($td.parent(),'o_selected_row', "row should be in edit mode"); - assert.ok($td.hasClass('o_readonly_modifier'), + assert.hasClass($td,'o_readonly_modifier', "foo cell should be readonly in edit mode"); - assert.ok(!$second_td.hasClass('o_readonly_modifier'), + assert.doesNotHaveClass($second_td, 'o_readonly_modifier', "bar cell should be editable"); - assert.ok($third_td.hasClass('o_readonly_modifier'), + assert.hasClass($third_td,'o_readonly_modifier', "int_field cell should be readonly in edit mode"); list.destroy(); }); - QUnit.test('editable list view: no active element', function (assert) { + QUnit.test('editable list view: line with no active element', function (assert) { assert.expect(3); - this.data.bar= { + + this.data.bar = { fields: { titi: {string: "Char", type: "char"}, grosminet: {string: "Bool", type: "boolean"}, }, records: [ - {titi: 'cui', grosminet: true}, - {titi: 'cuicui', grosminet: false}, - ] + {id: 1, titi: 'cui', grosminet: true}, + {id: 2, titi: 'cuicui', grosminet: false}, + ], }; this.data.foo.records[0].o2m = [1, 2]; + var form = createView({ View: FormView, model: 'foo', @@ -494,20 +496,25 @@ QUnit.module('Views', { '</tree>'+ '</field>'+ '</form>', + mockRPC: function (route, args) { + if (args.method === 'write') { + assert.deepEqual(args.args[1], { + o2m: [[1, 1, {grosminet: false}], [4, 2, false]], + }); + } + return this._super.apply(this, arguments); + }, }); + var $td = form.$('.o_data_cell').first(); var $td2 = form.$('.o_data_cell').eq(1); - assert.ok($td.hasClass("o_readonly_modifier"), "first field must be readonly"); - assert.ok($td2.hasClass("o_boolean_toggle_cell"), "second field must be not activable but updatable on click (boolean toggle in this case)"); - $td.click(); //select row first - var $slider = $td2.find('.slider').first(); - try { - $slider.click(); //toggle boolean - assert.ok(true); - } - catch(e) { - assert.ok(false, "should not crash when clicking on the slider"); - } + assert.hasClass($td, 'o_readonly_modifier'); + assert.hasClass($td2, 'o_boolean_toggle_cell'); + testUtils.dom.click($td); + testUtils.dom.click($td2.find('.o_boolean_toggle input')); + + testUtils.form.clickSave(form); + form.destroy(); }); @@ -522,16 +529,16 @@ QUnit.module('Views', { }); var $td = list.$('td:not(.o_list_record_selector)').first(); - assert.ok(!$td.parent().hasClass('o_selected_row'), "td should not be in edit mode"); - $td.click(); - assert.ok($td.parent().hasClass('o_selected_row'), "td should be in edit mode"); + assert.doesNotHaveClass($td.parent(), 'o_selected_row', "td should not be in edit mode"); + testUtils.dom.click($td); + assert.hasClass($td.parent(),'o_selected_row', "td should be in edit mode"); list.destroy(); }); QUnit.test('editable list: add a line and discard', function (assert) { assert.expect(11); - testUtils.patch(basicFields.FieldChar, { + testUtils.mock.patch(basicFields.FieldChar, { destroy: function () { assert.step('destroy'); this._super.apply(this, arguments); @@ -546,34 +553,34 @@ QUnit.module('Views', { domain: [['foo', '=', 'yop']], }); - assert.strictEqual(list.$('tbody tr').length, 4, + assert.containsN(list, 'tbody tr', 4, "list should contain 4 rows"); - assert.strictEqual(list.$('.o_data_row').length, 1, + assert.containsOnce(list, '.o_data_row', "list should contain one record (and thus 3 empty rows)"); assert.strictEqual(list.pager.$('.o_pager_value').text(), '1-1', "pager should be correct"); - list.$buttons.find('.o_list_button_add').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); - assert.strictEqual(list.$('tbody tr').length, 4, + assert.containsN(list, 'tbody tr', 4, "list should still contain 4 rows"); - assert.strictEqual(list.$('.o_data_row').length, 2, + assert.containsN(list, '.o_data_row', 2, "list should contain two record (and thus 2 empty rows)"); assert.strictEqual(list.pager.$('.o_pager_value').text(), '1-2', "pager should be correct"); - list.$buttons.find('.o_list_button_discard').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_discard')); - assert.strictEqual(list.$('tbody tr').length, 4, + assert.containsN(list, 'tbody tr', 4, "list should still contain 4 rows"); - assert.strictEqual(list.$('.o_data_row').length, 1, + assert.containsOnce(list, '.o_data_row', "list should contain one record (and thus 3 empty rows)"); assert.strictEqual(list.pager.$('.o_pager_value').text(), '1-1', "pager should be correct"); assert.verifySteps(['destroy'], "should have destroyed the widget of the removed line"); - testUtils.unpatch(basicFields.FieldChar); + testUtils.mock.unpatch(basicFields.FieldChar); list.destroy(); }); @@ -589,13 +596,13 @@ QUnit.module('Views', { var $td = list.$('td:not(.o_list_record_selector)').first(); var n = 0; - testUtils.intercept(list, "field_changed", function () { + testUtils.mock.intercept(list, "field_changed", function () { n += 1; }); - $td.click(); - $td.find('input').val('abc').trigger('input'); + testUtils.dom.click($td); + testUtils.fields.editInput($td.find('input'), 'abc'); assert.strictEqual(n, 1, "field_changed should have been triggered"); - list.$('td:not(.o_list_record_selector)').eq(2).click(); + testUtils.dom.click(list.$('td:not(.o_list_record_selector)').eq(2)); assert.strictEqual(n, 1, "field_changed should not have been triggered"); list.destroy(); }); @@ -610,15 +617,15 @@ QUnit.module('Views', { arch: '<tree editable="bottom"><field name="foo"/><field name="bar"/></tree>', }); var $td = list.$('td:not(.o_list_record_selector)').first(); - $td.click(); - $td.find('input').val('abc').trigger('input'); + testUtils.dom.click($td); + testUtils.fields.editInput($td.find('input'), 'abc'); assert.strictEqual($td.find('input').val(), 'abc', "char field has been edited correctly"); var $next_row_td = list.$('tbody tr:eq(1) td:not(.o_list_record_selector)').first(); - $next_row_td.click(); // should trigger the save of the previous row + testUtils.dom.click($next_row_td); assert.strictEqual(list.$('td:not(.o_list_record_selector)').first().text(), 'abc', 'changes should be saved correctly'); - assert.ok(!list.$('tbody tr').first().hasClass('o_selected_row'), + assert.doesNotHaveClass(list.$('tbody tr').first(), 'o_selected_row', 'saved row should be in readonly mode'); assert.strictEqual(this.data.foo.records[0].foo, 'abc', "the edition should have been properly saved"); @@ -644,15 +651,15 @@ QUnit.module('Views', { } }); - list.$('.o_data_cell:first').click(); - list.$('input[name="foo"]').val('xyz').trigger('input'); - list.$('.o_column_sortable').click(); + testUtils.dom.click(list.$('.o_data_cell:first')); + testUtils.fields.editInput(list.$('input[name="foo"]'), 'xyz'); + testUtils.dom.click(list.$('.o_column_sortable')); - assert.ok(list.$('.o_data_row:first').hasClass('o_selected_row'), + assert.hasClass(list.$('.o_data_row:first'),'o_selected_row', "first row should still be in edition"); - list.$buttons.find('.o_list_button_save').click(); - assert.ok(!list.$buttons.hasClass('o-editing'), + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); + assert.doesNotHaveClass(list.$buttons, 'o-editing', "list buttons should be back to their readonly mode"); list.destroy(); @@ -671,28 +678,28 @@ QUnit.module('Views', { var $thead_selector = list.$('thead .o_list_record_selector input'); var n = 0; - testUtils.intercept(list, "selection_changed", function () { + testUtils.mock.intercept(list, "selection_changed", function () { n += 1; }); // tbody checkbox click - $tbody_selector.click(); + testUtils.dom.click($tbody_selector); assert.strictEqual(n, 1, "selection_changed should have been triggered"); assert.ok($tbody_selector.is(':checked'), "selection checkbox should be checked"); - $tbody_selector.click(); + testUtils.dom.click($tbody_selector); assert.strictEqual(n, 2, "selection_changed should have been triggered"); assert.ok(!$tbody_selector.is(':checked'), "selection checkbox shouldn't be checked"); // head checkbox click - $thead_selector.click(); + testUtils.dom.click($thead_selector); assert.strictEqual(n, 3, "selection_changed should have been triggered"); - assert.strictEqual(list.$('tbody .o_list_record_selector input:checked').length, + assert.containsN(list, 'tbody .o_list_record_selector input:checked', list.$('tbody tr').length, "all selection checkboxes should be checked"); - $thead_selector.click(); + testUtils.dom.click($thead_selector); assert.strictEqual(n, 4, "selection_changed should have been triggered"); - assert.strictEqual(list.$('tbody .o_list_record_selector input:checked').length, 0, + assert.containsNone(list, 'tbody .o_list_record_selector input:checked', "no selection checkbox should be checked"); list.destroy(); }); @@ -715,7 +722,7 @@ QUnit.module('Views', { // select first record var $firstRowSelector = list.$('tbody .o_list_record_selector input').first(); - $firstRowSelector.click(); + testUtils.dom.click($firstRowSelector); assert.ok($firstRowSelector.is(':checked'), "first row should be selected"); assert.strictEqual(list.$('tfoot td:nth(2)').text(), '10', "total should be 10 (first record selected)"); @@ -732,7 +739,7 @@ QUnit.module('Views', { }); QUnit.test('selection is kept on render without reload', function (assert) { - assert.expect(5); + assert.expect(6); var list = createView({ View: ListView, @@ -746,26 +753,25 @@ QUnit.module('Views', { '</tree>', }); + assert.isNotVisible(list.sidebar); + // open blip grouping and check all lines - list.$('.o_group_header:contains("blip (2)")').click(); - list.$('.o_data_row input').click(); - assert.strictEqual(true, list.sidebar.$el.is(':visible'), - "element checked so sidebar") + testUtils.dom.click(list.$('.o_group_header:contains("blip (2)")')); + testUtils.dom.click(list.$('.o_data_row:first input')); + assert.isVisible(list.sidebar); // open yop grouping and verify blip are still checked - list.$('.o_group_header:contains("yop (1)")').click() - assert.strictEqual(2, list.$('.o_data_row input:checked').length, + testUtils.dom.click(list.$('.o_group_header:contains("yop (1)")')); + assert.containsOnce(list, '.o_data_row input:checked', "opening a grouping does not uncheck others"); - assert.strictEqual(true, list.sidebar.$el.is(':visible'), - "element checked so sidebar") + assert.isVisible(list.sidebar); // close and open blip grouping and verify blip are unchecked - list.$('.o_group_header:contains("blip (2)")').click(); - list.$('.o_group_header:contains("blip (2)")').click(); - assert.strictEqual(0, list.$('.o_data_row input:checked').length, + testUtils.dom.click(list.$('.o_group_header:contains("blip (2)")')); + testUtils.dom.click(list.$('.o_group_header:contains("blip (2)")')); + assert.containsNone(list, '.o_data_row input:checked', "opening and closing a grouping uncheck its elements"); - assert.strictEqual(false, list.sidebar.$el.is(':visible'), - "no element checked so no sidebar") + assert.isNotVisible(list.sidebar); list.destroy(); }); @@ -784,12 +790,12 @@ QUnit.module('Views', { assert.strictEqual(list.$('tfoot td:nth(2)').text(), "32", "total should be 32"); - $tbody_selectors.first().click(); - $tbody_selectors.last().click(); + testUtils.dom.click($tbody_selectors.first()); + testUtils.dom.click($tbody_selectors.last()); assert.strictEqual(list.$('tfoot td:nth(2)').text(), "6", "total should be 6 as first and last records are selected"); - $thead_selector.click(); + testUtils.dom.click($thead_selector); assert.strictEqual(list.$('tfoot td:nth(2)').text(), "32", "total should be 32 as all records are selected"); @@ -821,8 +827,8 @@ QUnit.module('Views', { assert.strictEqual($groupHeader2.find('td:last()').text(), "9", "second group total should be 9"); assert.strictEqual(list.$('tfoot td:last()').text(), "32", "total should be 32"); - $groupHeader1.click(); - list.$('tbody .o_list_record_selector input').first().click(); + testUtils.dom.click($groupHeader1); + testUtils.dom.click(list.$('tbody .o_list_record_selector input').first()); assert.strictEqual(list.$('tfoot td:last()').text(), "10", "total should be 10 as first record of first group is selected"); list.destroy(); @@ -840,8 +846,8 @@ QUnit.module('Views', { assert.strictEqual(list.$('td[title="Sum"]').text(), "32", "current total should be 32"); - list.$('tr.o_data_row td.o_data_cell').first().click(); - list.$('td.o_data_cell input').val("15").trigger("input"); + testUtils.dom.click(list.$('tr.o_data_row td.o_data_cell').first()); + testUtils.fields.editInput(list.$('td.o_data_cell input'), "15"); assert.strictEqual(list.$('td[title="Sum"]').text(), "37", "current total should now be 37"); @@ -887,12 +893,12 @@ QUnit.module('Views', { "initial order should be 10, 5, 17"); assert.strictEqual(list.$('tfoot td:last()').text(), '32', "total should be 32"); - list.$('.o_column_sortable').click(); // sort (int_field ASC) + testUtils.dom.click(list.$('.o_column_sortable')); assert.strictEqual(list.$('tfoot td:last()').text(), '32', "total should still be 32"); assert.strictEqual(list.$('tbody .o_list_number').text(), '51017', "order should be 5, 10, 17"); - list.$('.o_column_sortable').click(); // sort (int_field DESC) + testUtils.dom.click(list.$('.o_column_sortable')); assert.strictEqual(list.$('tbody .o_list_number').text(), '17105', "initial order should be 17, 10, 5"); assert.strictEqual(list.$('tfoot td:last()').text(), '32', "total should still be 32"); @@ -923,13 +929,13 @@ QUnit.module('Views', { }, }); //we cannot sort by sort_field since it doesn't have a group_operator - list.$('.o_column_sortable:eq(2)').click(); // sort (sort_field ASC(invalid) -> default order) + testUtils.dom.click(list.$('.o_column_sortable:eq(2)')); //we can sort by int_field since it has a group_operator - list.$('.o_column_sortable:eq(1)').click(); // sort (int_field ASC) + testUtils.dom.click(list.$('.o_column_sortable:eq(1)')); //we keep previous order - list.$('.o_column_sortable:eq(2)').click(); // sort (sort_field ASC(invalid) -> int_field ASC) + testUtils.dom.click(list.$('.o_column_sortable:eq(2)')); //we can sort on foo since we are groupped by foo + previous order - list.$('.o_column_sortable:eq(0)').click(); // sort (foo ASC, int_field ASK") + testUtils.dom.click(list.$('.o_column_sortable:eq(0)')); assert.verifySteps([ 'default order', @@ -963,8 +969,8 @@ QUnit.module('Views', { assert.strictEqual($int_field_td.text(), '10', "should contain initial value"); - $foo_td.click(); - $foo_td.find('input').val('tralala').trigger('input'); + testUtils.dom.click($foo_td); + testUtils.fields.editInput($foo_td.find('input'), 'tralala'); assert.strictEqual($int_field_td.find('input').val(), "1007", "should contain input with onchange applied"); @@ -991,13 +997,13 @@ QUnit.module('Views', { var startWidth = list.$('table').addBack('table').width(); // start edition of first row - list.$('td:not(.o_list_record_selector)').first().click(); + testUtils.dom.click(list.$('td:not(.o_list_record_selector)').first()); var editionWidths = _.pluck(list.$('thead th'), 'offsetWidth'); var editionWidth = list.$('table').addBack('table').width(); // leave edition - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); var readonlyWidths = _.pluck(list.$('thead th'), 'offsetWidth'); var readonlyWidth = list.$('table').addBack('table').width(); @@ -1025,19 +1031,20 @@ QUnit.module('Views', { arch: '<tree><field name="foo"/></tree>', }); - assert.ok(list.sidebar.$el.hasClass('o_hidden'), 'sidebar should be invisible'); - assert.strictEqual(list.$('tbody td.o_list_record_selector').length, 4, "should have 4 records"); + assert.isNotVisible(list.sidebar.$el, 'sidebar should be invisible'); + assert.containsN(list, 'tbody td.o_list_record_selector', 4, "should have 4 records"); - list.$('tbody td.o_list_record_selector:first input').click(); + testUtils.dom.click(list.$('tbody td.o_list_record_selector:first input')); - assert.ok(!list.sidebar.$el.hasClass('o_hidden'), 'sidebar should be visible'); + assert.isVisible(list.sidebar.$el, 'sidebar should be visible'); - list.sidebar.$('a:contains(Delete)').click(); - assert.ok($('body').hasClass('modal-open'), 'body should have modal-open clsss'); + testUtils.dom.click(list.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + testUtils.dom.click(list.sidebar.$('a:contains(Delete)')); + assert.hasClass($('body'),'modal-open', 'body should have modal-open clsss'); - $('body .modal button span:contains(Ok)').click(); + testUtils.dom.click($('body .modal button span:contains(Ok)')); - assert.strictEqual(list.$('tbody td.o_list_record_selector').length, 3, "should have 3 records"); + assert.containsN(list, 'tbody td.o_list_record_selector', 3, "should have 3 records"); list.destroy(); }); @@ -1059,23 +1066,25 @@ QUnit.module('Views', { }, }); - assert.ok(list.sidebar.$el.hasClass('o_hidden'), 'sidebar should be invisible'); - assert.strictEqual(list.$('tbody td.o_list_record_selector').length, 4, "should have 4 records"); + assert.isNotVisible(list.sidebar.$el, 'sidebar should be invisible'); + assert.containsN(list, 'tbody td.o_list_record_selector', 4, "should have 4 records"); - list.$('tbody td.o_list_record_selector:first input').click(); + testUtils.dom.click(list.$('tbody td.o_list_record_selector:first input')); - assert.ok(!list.sidebar.$el.hasClass('o_hidden'), 'sidebar should be visible'); + assert.isVisible(list.sidebar.$el, 'sidebar should be visible'); assert.verifySteps(['/web/dataset/search_read']); - list.sidebar.$('a:contains(Archive)').click(); + testUtils.dom.click(list.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + testUtils.dom.click(list.sidebar.$('a:contains(Archive)')); assert.strictEqual($('.modal').length, 1, 'a confirm modal should be displayed'); - $('.modal-footer .btn-secondary').click(); // Click on 'Cancel' - assert.strictEqual(list.$('tbody td.o_list_record_selector').length, 4, "still should have 4 records"); + testUtils.dom.click($('.modal-footer .btn-secondary')); + assert.containsN(list, 'tbody td.o_list_record_selector', 4, "still should have 4 records"); - list.sidebar.$('a:contains(Archive)').click(); + testUtils.dom.click(list.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + testUtils.dom.click(list.sidebar.$('a:contains(Archive)')); assert.strictEqual($('.modal').length, 1, 'a confirm modal should be displayed'); - $('.modal-footer .btn-primary').click(); // Click on 'Ok' - assert.strictEqual(list.$('tbody td.o_list_record_selector').length, 3, "should have 3 records"); + testUtils.dom.click($('.modal-footer .btn-primary')); + assert.containsN(list, 'tbody td.o_list_record_selector', 3, "should have 3 records"); assert.verifySteps(['/web/dataset/search_read', '/web/dataset/call_kw/foo/write', '/web/dataset/search_read']); list.destroy(); }); @@ -1096,10 +1105,10 @@ QUnit.module('Views', { }, }); - assert.ok(!list.pager.$el.hasClass('o_hidden'), "pager should be visible"); + assert.isVisible(list.pager.$el, "pager should be visible"); assert.strictEqual(list.pager.state.size, 4, "pager's size should be 4"); list.update({ groupBy: ['bar']}); - assert.ok(list.pager.$el.hasClass('o_hidden'), "pager should be invisible"); + assert.isNotVisible(list.pager.$el, "pager should be invisible"); list.destroy(); }); @@ -1129,7 +1138,7 @@ QUnit.module('Views', { "record 3 should be first"); nbSearchRead = 0; - list.$('thead th:contains(Foo)').click(); + testUtils.dom.click(list.$('thead th:contains(Foo)')); assert.strictEqual(nbSearchRead, 1, "should have done one search_read"); assert.ok(list.$('tbody tr:first td:contains(blip)').length, "record 3 should be first"); @@ -1137,7 +1146,7 @@ QUnit.module('Views', { "record 1 should be first"); nbSearchRead = 0; - list.$('thead th:contains(Foo)').click(); + testUtils.dom.click(list.$('thead th:contains(Foo)')); assert.strictEqual(nbSearchRead, 1, "should have done one search_read"); assert.ok(list.$('tbody tr:first td:contains(yop)').length, "record 3 should be first"); @@ -1220,15 +1229,15 @@ QUnit.module('Views', { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.ok(form.$('tbody tr:first td:contains(Value 1)').length, "Value 1 should be first"); assert.ok(form.$('tbody tr:eq(1) td:contains(Value 3)').length, "Value 3 should be second"); var $o2m = form.$('.o_field_widget[name=o2m]'); - form.$('.o_field_x2many_list_row_add a').click(); - $o2m.find('.o_field_widget').val("Value 2").trigger('input'); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput($o2m.find('.o_field_widget'), "Value 2"); assert.ok(form.$('tbody tr:first td:contains(Value 1)').length, "Value 1 should be first"); assert.ok(form.$('tbody tr:eq(1) td:contains(Value 3)').length, @@ -1236,7 +1245,7 @@ QUnit.module('Views', { assert.ok(form.$('tbody tr:eq(2) td input').val(), "Value 2 should be third (shouldn't be sorted)"); - form.$buttons.find('.o_form_button_save').click(); + testUtils.form.clickSave(form); assert.ok(form.$('tbody tr:first td:contains(Value 1)').length, "Value 1 should be first"); assert.ok(form.$('tbody tr:eq(1) td:contains(Value 2)').length, @@ -1271,15 +1280,15 @@ QUnit.module('Views', { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); + testUtils.form.clickEdit(form); assert.ok(form.$('tbody tr:first td:contains(Value 1)').length, "Value 1 should be first"); assert.ok(form.$('tbody tr:eq(1) td:contains(Value 3)').length, "Value 3 should be second"); var $o2m = form.$('.o_field_widget[name=o2m]'); - form.$('.o_field_x2many_list_row_add a').click(); - $o2m.find('.o_field_widget').val("Value 2").trigger('input'); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.fields.editInput($o2m.find('.o_field_widget'), "Value 2"); assert.ok(form.$('tbody tr:first td:contains(Value 1)').length, "Value 1 should be first"); assert.ok(form.$('tbody tr:eq(1) td:contains(Value 3)').length, @@ -1287,9 +1296,9 @@ QUnit.module('Views', { assert.ok(form.$('tbody tr:eq(2) td input').val(), "Value 2 should be third (shouldn't be sorted)"); - form.$('.o_form_sheet_bg').click(); // validate the row before sorting + testUtils.dom.click(form.$('.o_form_sheet_bg')); - $o2m.find('.o_column_sortable').click(); // resort list after edition + testUtils.dom.click($o2m.find('.o_column_sortable')); assert.strictEqual(form.$('tbody tr:first').text(), 'Value 1', "Value 1 should be first"); assert.strictEqual(form.$('tbody tr:eq(1)').text(), 'Value 2', @@ -1297,7 +1306,7 @@ QUnit.module('Views', { assert.strictEqual(form.$('tbody tr:eq(2)').text(), 'Value 3', "Value 3 should be third"); - $o2m.find('.o_column_sortable').click(); + testUtils.dom.click($o2m.find('.o_column_sortable')); assert.strictEqual(form.$('tbody tr:first').text(), 'Value 3', "Value 3 should be first"); assert.strictEqual(form.$('tbody tr:eq(1)').text(), 'Value 2', @@ -1341,13 +1350,13 @@ QUnit.module('Views', { }); // Change page - form.$('.o_pager_next').click(); + testUtils.dom.click(form.$('.o_pager_next')); assert.strictEqual(form.$('tbody tr:first').text(), 'Value 44', "record 44 should be first"); assert.strictEqual(form.$('tbody tr:eq(4)').text(), 'Value 48', "record 48 should be last"); - form.$('.o_column_sortable').click(); + testUtils.dom.click(form.$('.o_column_sortable')); assert.strictEqual(form.$('tbody tr:first').text(), 'Value 08', "record 48 should be first"); assert.strictEqual(form.$('tbody tr:eq(4)').text(), 'Value 04', @@ -1368,8 +1377,8 @@ QUnit.module('Views', { '<button name="notafield" type="object" icon="fa-asterisk" class="o_yeah"/>' + '</tree>', }); - assert.ok(list.$('tbody button').length, "should have a button"); - assert.ok(list.$('tbody button').hasClass('o_yeah'), "class should be set on the button"); + assert.containsN(list, 'tbody button[name=notafield]', 4); + assert.containsN(list, 'tbody button[name=notafield].o_yeah', 4, "class o_yeah should be set on the four button"); list.destroy(); }); @@ -1455,10 +1464,10 @@ QUnit.module('Views', { '</tree>', }); - assert.strictEqual(list.$('tbody tr.text-info').length, 3, + assert.containsN(list, 'tbody tr.text-info', 3, "should have 3 columns with text-info class"); - assert.strictEqual(list.$('tbody tr').length, 4, "should have 4 rows"); + assert.containsN(list, 'tbody tr', 4, "should have 4 rows"); list.destroy(); }); @@ -1476,12 +1485,12 @@ QUnit.module('Views', { '</tree>', }); - list.$buttons.find('.o_list_button_add').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); - assert.strictEqual(list.$('tr.o_data_row.text-danger').length, 0, + assert.containsNone(list, 'tr.o_data_row.text-danger', "the data row should not have .text-danger decoration (int_field is unset)"); - list.$('input[name="int_field"]').val('-3').trigger('input'); - assert.strictEqual(list.$('tr.o_data_row.text-danger').length, 1, + testUtils.fields.editInput(list.$('input[name="int_field"]'), '-3'); + assert.containsOnce(list, 'tr.o_data_row.text-danger', "the data row should have .text-danger decoration (int_field is negative)"); list.destroy(); }); @@ -1500,13 +1509,13 @@ QUnit.module('Views', { '</tree>', }); - assert.strictEqual(list.$('tbody tr.text-info').length, 1, + assert.containsOnce(list, 'tbody tr.text-info', "should have 1 columns with text-info class with good datetime"); - assert.strictEqual(list.$('tbody tr.text-danger').length, 0, + assert.containsNone(list, 'tbody tr.text-danger', "should have 0 columns with text-danger class with wrong timezone datetime"); - assert.strictEqual(list.$('tbody tr').length, 4, "should have 4 rows"); + assert.containsN(list, 'tbody tr', 4, "should have 4 rows"); list.destroy(); }); @@ -1529,10 +1538,10 @@ QUnit.module('Views', { }, }); - assert.strictEqual(list.$('.o_view_nocontent').length, 1, + assert.containsOnce(list, '.o_view_nocontent', "should display the no content helper"); - assert.strictEqual(list.$('table').length, 0, "should not have a table in the dom"); + assert.containsNone(list, 'table', "should not have a table in the dom"); assert.strictEqual(list.$('.o_view_nocontent p.hello:contains(add a partner)').length, 1, "should have rendered no content helper from action"); @@ -1540,9 +1549,9 @@ QUnit.module('Views', { this.data.foo.records = records; list.reload(); - assert.strictEqual(list.$('.o_view_nocontent').length, 0, + assert.containsNone(list, '.o_view_nocontent', "should not display the no content helper"); - assert.strictEqual(list.$('table').length, 1, "should have a table in the dom"); + assert.containsOnce(list, 'table', "should have a table in the dom"); list.destroy(); }); @@ -1558,13 +1567,13 @@ QUnit.module('Views', { arch: '<tree><field name="foo"/></tree>', }); - assert.strictEqual(list.$('.o_view_nocontent').length, 0, + assert.containsNone(list, '.o_view_nocontent', "should not display the no content helper"); - assert.strictEqual(list.$('tr.o_data_row').length, 0, + assert.containsNone(list, 'tr.o_data_row', "should not have any data row"); - assert.strictEqual(list.$('table').length, 1, "should have a table in the dom"); + assert.containsOnce(list, 'table', "should have a table in the dom"); list.destroy(); }); @@ -1598,23 +1607,23 @@ QUnit.module('Views', { }, }); - assert.strictEqual(list.$('.o_view_nocontent').length, 1, + assert.containsOnce(list, '.o_view_nocontent', "should have a no content helper displayed"); - assert.strictEqual(list.$('div.table-responsive').length, 0, + assert.containsNone(list, 'div.table-responsive', "should not have a div.table-responsive"); - assert.strictEqual(list.$('table').length, 0, "should not have rendered a table"); + assert.containsNone(list, 'table', "should not have rendered a table"); - list.$buttons.find('.o_list_button_add').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); - assert.strictEqual(list.$('.o_view_nocontent').length, 0, + assert.containsNone(list, '.o_view_nocontent', "should not have a no content helper displayed"); - assert.strictEqual(list.$('table').length, 1, "should have rendered a table"); + assert.containsOnce(list, 'table', "should have rendered a table"); assert.strictEqual(list.$el.css('height'), list.$('div.table-responsive').css('height'), "the div for the table should take the full height"); - assert.ok(list.$('tbody tr:eq(0)').hasClass('o_selected_row'), + assert.hasClass(list.$('tbody tr:eq(0)'),'o_selected_row', "the date field td should be in edit mode"); assert.strictEqual(list.$('tbody tr:eq(0) td:eq(1)').text().trim(), "", "the date field td should not have any content"); @@ -1624,7 +1633,7 @@ QUnit.module('Views', { assert.strictEqual(list.$('.o_list_button button').prop('disabled'), true, "buttons should be disabled while the record is not yet created"); - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); assert.strictEqual(list.$('tbody tr:eq(0) .o_list_record_selector input').prop('disabled'), false, "record selector checkbox should not be disabled once the record is created"); @@ -1649,9 +1658,9 @@ QUnit.module('Views', { '</tree>', }); - list.$buttons.find('.o_list_button_add').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); - assert.strictEqual(list.$('table button.o_icon_button i.fa-phone').length, 1, + assert.containsOnce(list, 'table button.o_icon_button i.fa-phone', "should have rendered a button"); list.destroy(); }); @@ -1688,13 +1697,13 @@ QUnit.module('Views', { assert.strictEqual(list.$('td:not(.o_list_record_selector) input').length, 0, "no input should be in the table"); - list.$('tbody td:not(.o_list_record_selector):first').click(); + testUtils.dom.click(list.$('tbody td:not(.o_list_record_selector):first')); assert.strictEqual(list.$('td:not(.o_list_record_selector) input').length, 1, "first cell should be editable"); assert.ok(list.$buttons.find('.o_list_button_discard').is(':visible'), "discard button should be visible"); - list.$buttons.find('.o_list_button_discard').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_discard')); assert.strictEqual(list.$('td:not(.o_list_record_selector) input').length, 0, "no input should be in the table"); @@ -1726,18 +1735,18 @@ QUnit.module('Views', { }, }); - list.$buttons.find('.o_list_button_add').click(); - list.$('div.table-responsive').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); + testUtils.dom.click(list.$('div.table-responsive')); assert.strictEqual(createCount, 1, "should have created a record"); - list.$buttons.find('.o_list_button_add').click(); - list.$('tfoot').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); + testUtils.dom.click(list.$('tfoot')); assert.strictEqual(createCount, 2, "should have created a record"); - list.$buttons.find('.o_list_button_add').click(); - list.$('tbody tr').last().click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); + testUtils.dom.click(list.$('tbody tr').last()); assert.strictEqual(createCount, 3, "should have created a record"); list.destroy(); @@ -1773,12 +1782,12 @@ QUnit.module('Views', { }, }); - assert.strictEqual(list.$('.o_list_button').length, 4, + assert.containsN(list, '.o_list_button', 4, "there should be one button per row"); - assert.strictEqual(list.$('.o_list_button:first .o_icon_button .fa.fa-car').length, 1, + assert.containsOnce(list, '.o_list_button:first .o_icon_button .fa.fa-car', 'buttons should have correct icon'); - list.$('.o_list_button:first > button').click(); // click on the button + testUtils.dom.click(list.$('.o_list_button:first > button')); assert.verifySteps(['/web/dataset/search_read', '/web/dataset/search_read'], "should have reloaded the view (after the action is complete)"); list.destroy(); @@ -1806,16 +1815,16 @@ QUnit.module('Views', { "td that contains an invisible button should be empty"); // edit first row - list.$('tbody tr:nth(0) td:nth(2)').click(); // click on first row to edit it + testUtils.dom.click(list.$('tbody tr:nth(0) td:nth(2)')); assert.strictEqual(list.$('tbody tr:nth(0) td:nth(4) input.o_invisible_modifier').length, 1, "td that contains an invisible field should not be empty in edition"); assert.strictEqual(list.$('tbody tr:nth(0) td:nth(1) > button.o_invisible_modifier').length, 1, "td that contains an invisible button should not be empty in edition"); - list.$buttons.find('.o_list_button_discard').click(); // leave edition + testUtils.dom.click(list.$buttons.find('.o_list_button_discard')); // click on the invisible field's cell to edit first row - list.$('tbody tr:nth(0) td:nth(4)').click(); - assert.ok(list.$('tbody tr:nth(0)').hasClass('o_selected_row'), + testUtils.dom.click(list.$('tbody tr:nth(0) td:nth(4)')); + assert.hasClass(list.$('tbody tr:nth(0)'),'o_selected_row', "first row should be in edition"); list.destroy(); }); @@ -1841,7 +1850,7 @@ QUnit.module('Views', { }, }); - assert.strictEqual(list.$('tbody tr:first td').length, 3, + assert.containsN(list, 'tbody tr:first td', 3, "currency_id column should not be in the table"); assert.strictEqual(list.$('tbody tr:first td:nth(2)').text().replace(/\s/g, ' '), '1200.00 €', "currency_id column should not be in the table"); @@ -1874,7 +1883,7 @@ QUnit.module('Views', { }); QUnit.test('edit a row by clicking on a readonly field', function (assert) { - assert.expect(8); + assert.expect(9); this.data.foo.fields.foo.readonly = true; @@ -1885,26 +1894,27 @@ QUnit.module('Views', { arch: '<tree editable="bottom"><field name="foo"/><field name="int_field"/></tree>', }); - assert.ok(list.$('.o_data_row:first td:nth(1)').hasClass('o_readonly_modifier'), + assert.hasClass(list.$('.o_data_row:first td:nth(1)'),'o_readonly_modifier', "foo field cells should have class 'o_readonly_modifier'"); // edit the first row - list.$('.o_data_row:first td:nth(1)').click(); - assert.ok(list.$('.o_data_row:first').hasClass('o_selected_row'), + testUtils.dom.click(list.$('.o_data_row:first td:nth(1)')); + assert.hasClass(list.$('.o_data_row:first'),'o_selected_row', "first row should be selected"); var $cell = list.$('.o_data_row:first td:nth(1)'); - assert.ok($cell.hasClass('o_readonly_modifier') && $cell.parent().hasClass('o_selected_row'), - "foo field cells should have class 'o_readonly_modifier' and the row should be in edition"); + // review + assert.hasClass($cell, 'o_readonly_modifier'); + assert.hasClass($cell.parent(),'o_selected_row'); assert.strictEqual(list.$('.o_data_row:first td:nth(1) span').text(), 'yop', "a widget should have been rendered for readonly fields"); - assert.ok(list.$('.o_data_row:first td:nth(2)').parent().hasClass('o_selected_row'), + assert.hasClass(list.$('.o_data_row:first td:nth(2)').parent(),'o_selected_row', "field 'int_field' should be in edition"); assert.strictEqual(list.$('.o_data_row:first td:nth(2) input').length, 1, "a widget for field 'int_field should have been rendered'"); // click again on readonly cell of first line: nothing should have changed - list.$('.o_data_row:first td:nth(1)').click(); - assert.ok(list.$('.o_data_row:first').hasClass('o_selected_row'), + testUtils.dom.click(list.$('.o_data_row:first td:nth(1)')); + assert.hasClass(list.$('.o_data_row:first'),'o_selected_row', "first row should be selected"); assert.strictEqual(list.$('.o_data_row:first td:nth(2) input').length, 1, "a widget for field 'int_field' should have been rendered (only once)"); @@ -1959,12 +1969,12 @@ QUnit.module('Views', { assert.strictEqual(nbRPCs.searchRead, 0, "should have done no search_read"); // basic rendering tests - assert.strictEqual(list.$('tbody').length, 1, "there should be 1 tbody"); - assert.strictEqual(list.$('.o_group_header').length, 2, + assert.containsOnce(list, 'tbody', "there should be 1 tbody"); + assert.containsN(list, '.o_group_header', 2, "should contain 2 groups at first level"); assert.strictEqual(list.$('.o_group_name:first').text(), 'Value 1 (4)', "group should have correct name and count"); - assert.strictEqual(list.$('.o_group_name .fa-caret-right').length, 2, + assert.containsN(list, '.o_group_name .fa-caret-right', 2, "the carret of closed groups should be right"); assert.strictEqual(list.$('.o_group_name:first span').css('padding-left'), '0px', "groups of level 1 should have a 0px padding-left"); @@ -1973,15 +1983,15 @@ QUnit.module('Views', { // open the first group nbRPCs = {readGroup: 0, searchRead: 0}; - list.$('.o_group_header:first').click(); + testUtils.dom.click(list.$('.o_group_header:first')); assert.strictEqual(nbRPCs.readGroup, 1, "should have done one read_group"); assert.strictEqual(nbRPCs.searchRead, 0, "should have done no search_read"); var $openGroup = list.$('tbody:nth(1)'); assert.strictEqual(list.$('.o_group_name:first').text(), 'Value 1 (4)', "group should have correct name and count (of records, not inner subgroups)"); - assert.strictEqual(list.$('tbody').length, 3, "there should be 3 tbodys"); - assert.strictEqual(list.$('.o_group_name:first .fa-caret-down').length, 1, + assert.containsN(list, 'tbody', 3, "there should be 3 tbodys"); + assert.containsOnce(list, '.o_group_name:first .fa-caret-down', "the carret of open groups should be down"); assert.strictEqual($openGroup.find('.o_group_header').length, 3, "open group should contain 3 groups"); @@ -1995,29 +2005,29 @@ QUnit.module('Views', { // open subgroup nbRPCs = {readGroup: 0, searchRead: 0}; envIDs = [4, 5]; // the opened subgroup contains these two records - $openGroup.find('.o_group_header:nth(2)').click(); + testUtils.dom.click($openGroup.find('.o_group_header:nth(2)')); assert.strictEqual(nbRPCs.readGroup, 0, "should have done no read_group"); assert.strictEqual(nbRPCs.searchRead, 1, "should have done one search_read"); var $openSubGroup = list.$('tbody:nth(2)'); - assert.strictEqual(list.$('tbody').length, 4, "there should be 4 tbodys"); + assert.containsN(list, 'tbody', 4, "there should be 4 tbodys"); assert.strictEqual($openSubGroup.find('.o_data_row').length, 2, "open subgroup should contain 2 data rows"); assert.strictEqual($openSubGroup.find('.o_data_row:first td:last').text(), '-4', "first record in open subgroup should be res_id 4 (with int_field -4)"); // open a record (should trigger event 'open_record') - $openSubGroup.find('.o_data_row:first').click(); + testUtils.dom.click($openSubGroup.find('.o_data_row:first')); // sort by int_field (ASC) and check that open groups are still open nbRPCs = {readGroup: 0, searchRead: 0}; envIDs = [5, 4]; // order of the records changed - list.$('thead th:last').click(); + testUtils.dom.click(list.$('thead th:last')); assert.strictEqual(nbRPCs.readGroup, 2, "should have done two read_groups"); assert.strictEqual(nbRPCs.searchRead, 1, "should have done one search_read"); $openSubGroup = list.$('tbody:nth(2)'); - assert.strictEqual(list.$('tbody').length, 4, "there should be 4 tbodys"); + assert.containsN(list, 'tbody', 4, "there should be 4 tbodys"); assert.strictEqual($openSubGroup.find('.o_data_row').length, 2, "open subgroup should contain 2 data rows"); assert.strictEqual($openSubGroup.find('.o_data_row:first td:last').text(), '-7', @@ -2026,14 +2036,14 @@ QUnit.module('Views', { // close first level group nbRPCs = {readGroup: 0, searchRead: 0}; envIDs = []; // the group being closed, there is no more record in the environment - list.$('.o_group_header:nth(1)').click(); + testUtils.dom.click(list.$('.o_group_header:nth(1)')); assert.strictEqual(nbRPCs.readGroup, 0, "should have done no read_group"); assert.strictEqual(nbRPCs.searchRead, 0, "should have done no search_read"); - assert.strictEqual(list.$('tbody').length, 1, "there should be 1 tbody"); - assert.strictEqual(list.$('.o_group_header').length, 2, + assert.containsOnce(list, 'tbody', "there should be 1 tbody"); + assert.containsN(list, '.o_group_header', 2, "should contain 2 groups at first level"); - assert.strictEqual(list.$('.o_group_name .fa-caret-right').length, 2, + assert.containsN(list, '.o_group_name .fa-caret-right', 2, "the carret of closed groups should be right"); list.destroy(); @@ -2059,11 +2069,11 @@ QUnit.module('Views', { groupBy: ['m2o', 'priority'], }); - assert.strictEqual(list.$('.o_group_header').length, 2, + assert.containsN(list, '.o_group_header', 2, "should contain 2 groups at first level"); // open the first group - list.$('.o_group_header:first').click(); + testUtils.dom.click(list.$('.o_group_header:first')); var $openGroup = list.$('tbody:nth(1)'); assert.strictEqual($openGroup.find('tr').length, 3, @@ -2094,21 +2104,21 @@ QUnit.module('Views', { var headerHeight = list.$('.o_group_header').css('height'); // basic rendering checks - list.$('.o_group_header').click(); + testUtils.dom.click(list.$('.o_group_header')); assert.strictEqual(list.$('.o_group_header').css('height'), headerHeight, "height of group header shouldn't have changed"); - assert.ok(list.$('.o_group_header td:last').hasClass('o_group_pager'), + assert.hasClass(list.$('.o_group_header td:last'),'o_group_pager', "last cell of open group header should have classname 'o_group_header'"); assert.strictEqual(list.$('.o_pager_value').text(), '1-3', "pager's value should be correct"); - assert.strictEqual(list.$('.o_data_row').length, 3, + assert.containsN(list, '.o_data_row', 3, "open group should display 3 records"); // go to next page - list.$('.o_pager_next').click(); + testUtils.dom.click(list.$('.o_pager_next')); assert.strictEqual(list.$('.o_pager_value').text(), '4-4', "pager's value should be correct"); - assert.strictEqual(list.$('.o_data_row').length, 1, + assert.containsOnce(list, '.o_data_row', "open group should display 1 record"); list.destroy(); @@ -2124,19 +2134,19 @@ QUnit.module('Views', { arch: '<tree editable="bottom"><field name="foo"/><field name="bar"/></tree>', }); - assert.strictEqual(list.$('tr.o_data_row').length, 4, + assert.containsN(list, 'tr.o_data_row', 4, "should have 4 records"); assert.strictEqual(list.$buttons.find('.o_list_button_add:visible').length, 1, "create button should be visible"); assert.strictEqual(list.$buttons.find('.o_list_button_discard:visible').length, 0, "discard button should be hidden"); - list.$buttons.find('.o_list_button_add').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); assert.strictEqual(list.$buttons.find('.o_list_button_add:visible').length, 0, "create button should be hidden"); assert.strictEqual(list.$buttons.find('.o_list_button_discard:visible').length, 1, "discard button should be visible"); - list.$buttons.find('.o_list_button_discard').click(); - assert.strictEqual(list.$('tr.o_data_row').length, 4, + testUtils.dom.click(list.$buttons.find('.o_list_button_discard')); + assert.containsN(list, 'tr.o_data_row', 4, "should still have 4 records"); assert.strictEqual(list.$buttons.find('.o_list_button_add:visible').length, 1, "create button should be visible again"); @@ -2159,32 +2169,32 @@ QUnit.module('Views', { '</tree>', }); - assert.strictEqual(list.$('tbody td.o_invisible_modifier').length, 3, + assert.containsN(list, 'tbody td.o_invisible_modifier', 3, "there should be 3 invisible foo cells in readonly mode"); // Make first line editable - list.$('tbody tr:nth(0) td:nth(1)').click(); + testUtils.dom.click(list.$('tbody tr:nth(0) td:nth(1)')); assert.strictEqual(list.$('tbody tr:nth(0) td:nth(1) > input[name="foo"].o_invisible_modifier').length, 1, "the foo field widget should have been rendered as invisible"); - list.$('tbody tr:nth(0) td:nth(2) input').click(); + testUtils.dom.click(list.$('tbody tr:nth(0) td:nth(2) input')); assert.strictEqual(list.$('tbody tr:nth(0) td:nth(1) > input[name="foo"]:not(.o_invisible_modifier)').length, 1, "the foo field widget should have been marked as non-invisible"); - assert.strictEqual(list.$('tbody td.o_invisible_modifier').length, 2, + assert.containsN(list, 'tbody td.o_invisible_modifier', 2, "the foo field widget parent cell should not be invisible anymore"); - list.$('tbody tr:nth(0) td:nth(2) input').click(); + testUtils.dom.click(list.$('tbody tr:nth(0) td:nth(2) input')); assert.strictEqual(list.$('tbody tr:nth(0) td:nth(1) > input[name="foo"].o_invisible_modifier').length, 1, "the foo field widget should have been marked as invisible again"); - assert.strictEqual(list.$('tbody td.o_invisible_modifier').length, 3, + assert.containsN(list, 'tbody td.o_invisible_modifier', 3, "the foo field widget parent cell should now be invisible again"); // Reswitch the cell to editable and save the row - list.$('tbody tr:nth(0) td:nth(2) input').click(); - list.$('thead').click(); + testUtils.dom.click(list.$('tbody tr:nth(0) td:nth(2) input')); + testUtils.dom.click(list.$('thead')); - assert.strictEqual(list.$('tbody td.o_invisible_modifier').length, 2, + assert.containsN(list, 'tbody td.o_invisible_modifier', 2, "there should be 2 invisible foo cells in readonly mode"); list.destroy(); @@ -2204,37 +2214,37 @@ QUnit.module('Views', { '</tree>', }); - assert.strictEqual(list.$('tbody td.o_readonly_modifier').length, 3, + assert.containsN(list, 'tbody td.o_readonly_modifier', 3, "there should be 3 readonly foo cells in readonly mode"); // Make first line editable - list.$('tbody tr:nth(0) td:nth(1)').click(); + testUtils.dom.click(list.$('tbody tr:nth(0) td:nth(1)')); assert.strictEqual(list.$('tbody tr:nth(0) td:nth(1) > span[name="foo"]').length, 1, "the foo field widget should have been rendered as readonly"); - list.$('tbody tr:nth(0) td:nth(2) input').click(); + testUtils.dom.click(list.$('tbody tr:nth(0) td:nth(2) input')); assert.strictEqual(list.$('tbody tr:nth(0) td:nth(1) > input[name="foo"]').length, 1, "the foo field widget should have been rerendered as editable"); - assert.strictEqual(list.$('tbody td.o_readonly_modifier').length, 2, + assert.containsN(list, 'tbody td.o_readonly_modifier', 2, "the foo field widget parent cell should not be readonly anymore"); - list.$('tbody tr:nth(0) td:nth(2) input').click(); + testUtils.dom.click(list.$('tbody tr:nth(0) td:nth(2) input')); assert.strictEqual(list.$('tbody tr:nth(0) td:nth(1) > span[name="foo"]').length, 1, "the foo field widget should have been rerendered as readonly"); - assert.strictEqual(list.$('tbody td.o_readonly_modifier').length, 3, + assert.containsN(list, 'tbody td.o_readonly_modifier', 3, "the foo field widget parent cell should now be readonly again"); - list.$('tbody tr:nth(0) td:nth(2) input').click(); + testUtils.dom.click(list.$('tbody tr:nth(0) td:nth(2) input')); assert.strictEqual(list.$('tbody tr:nth(0) td:nth(1) > input[name="foo"]').length, 1, "the foo field widget should have been rerendered as editable again"); - assert.strictEqual(list.$('tbody td.o_readonly_modifier').length, 2, + assert.containsN(list, 'tbody td.o_readonly_modifier', 2, "the foo field widget parent cell should not be readonly again"); // Click outside to leave edition mode - list.$el.click(); + testUtils.dom.click(list.$el); - assert.strictEqual(list.$('tbody td.o_readonly_modifier').length, 2, + assert.containsN(list, 'tbody td.o_readonly_modifier', 2, "there should be 2 readonly foo cells in readonly mode"); list.destroy(); @@ -2254,32 +2264,32 @@ QUnit.module('Views', { '</tree>', }); - assert.strictEqual(list.$('tbody td.o_required_modifier').length, 3, + assert.containsN(list, 'tbody td.o_required_modifier', 3, "there should be 3 required foo cells in readonly mode"); // Make first line editable - list.$('tbody tr:nth(0) td:nth(1)').click(); + testUtils.dom.click(list.$('tbody tr:nth(0) td:nth(1)')); assert.strictEqual(list.$('tbody tr:nth(0) td:nth(1) > input[name="foo"].o_required_modifier').length, 1, "the foo field widget should have been rendered as required"); - list.$('tbody tr:nth(0) td:nth(2) input').click(); + testUtils.dom.click(list.$('tbody tr:nth(0) td:nth(2) input')); assert.strictEqual(list.$('tbody tr:nth(0) td:nth(1) > input[name="foo"]:not(.o_required_modifier)').length, 1, "the foo field widget should have been marked as non-required"); - assert.strictEqual(list.$('tbody td.o_required_modifier').length, 2, + assert.containsN(list, 'tbody td.o_required_modifier', 2, "the foo field widget parent cell should not be required anymore"); - list.$('tbody tr:nth(0) td:nth(2) input').click(); + testUtils.dom.click(list.$('tbody tr:nth(0) td:nth(2) input')); assert.strictEqual(list.$('tbody tr:nth(0) td:nth(1) > input[name="foo"].o_required_modifier').length, 1, "the foo field widget should have been marked as required again"); - assert.strictEqual(list.$('tbody td.o_required_modifier').length, 3, + assert.containsN(list, 'tbody td.o_required_modifier', 3, "the foo field widget parent cell should now be required again"); // Reswitch the cell to editable and save the row - list.$('tbody tr:nth(0) td:nth(2) input').click(); - list.$('thead').click(); + testUtils.dom.click(list.$('tbody tr:nth(0) td:nth(2) input')); + testUtils.dom.click(list.$('thead')); - assert.strictEqual(list.$('tbody td.o_required_modifier').length, 2, + assert.containsN(list, 'tbody td.o_required_modifier', 2, "there should be 2 required foo cells in readonly mode"); list.destroy(); @@ -2311,18 +2321,18 @@ QUnit.module('Views', { // Start first line edition var $firstFooTd = list.$('tbody tr:nth(0) td:nth(1)'); - $firstFooTd.click(); + testUtils.dom.click($firstFooTd); // Remove required foo field value - $firstFooTd.find('input').val("").trigger("input"); + testUtils.fields.editInput($firstFooTd.find('input'), "") // Try starting other line edition var $secondFooTd = list.$('tbody tr:nth(1) td:nth(1)'); - $secondFooTd.click(); + testUtils.dom.click($secondFooTd); assert.strictEqual($firstFooTd.parent('.o_selected_row').length, 1, "first line should still be in edition as invalid"); - assert.strictEqual(list.$('tbody tr.o_selected_row').length, 1, + assert.containsOnce(list, 'tbody tr.o_selected_row', "no other line should be in edition"); assert.strictEqual($firstFooTd.find('input.o_field_invalid').length, 1, "the required field should be marked as invalid"); @@ -2342,7 +2352,7 @@ QUnit.module('Views', { arch: '<tree><field name="name"/></tree>', }); - testUtils.intercept(list, 'switch_view', function (event) { + testUtils.mock.intercept(list, 'switch_view', function (event) { assert.deepEqual(_.pick(event.data, 'mode', 'model', 'res_id', 'view_type'), { mode: 'readonly', model: 'event', @@ -2350,7 +2360,7 @@ QUnit.module('Views', { view_type: 'form', }, "should trigger a switch_view event to the form view for the record virtual id"); }); - list.$('td:contains(virtual)').click(); + testUtils.dom.click(list.$('td:contains(virtual)')); list.destroy(); }); @@ -2370,20 +2380,20 @@ QUnit.module('Views', { }); // click on 3rd line - list.$('td:contains(gnap)').click(); - assert.ok(list.$('tr.o_data_row:eq(2)').hasClass('o_selected_row'), + testUtils.dom.click(list.$('td:contains(gnap)')); + assert.hasClass(list.$('tr.o_data_row:eq(2)'),'o_selected_row', "3rd row should be selected"); // press enter in input list.$('tr.o_selected_row input').trigger({type: 'keydown', which: 13}); // enter - assert.ok(list.$('tr.o_data_row:eq(3)').hasClass('o_selected_row'), + assert.hasClass(list.$('tr.o_data_row:eq(3)'),'o_selected_row', "4rd row should be selected"); - assert.notOk(list.$('tr.o_data_row:eq(2)').hasClass('o_selected_row'), + assert.doesNotHaveClass(list.$('tr.o_data_row:eq(2)'), 'o_selected_row', "3rd row should no longer be selected"); // press enter on last row list.$('tr.o_selected_row input').trigger({type: 'keydown', which: 13}); // enter - assert.strictEqual(list.$('tr.o_data_row').length, 5, "should have created a 5th row"); + assert.containsN(list, 'tr.o_data_row', 5, "should have created a 5th row"); assert.verifySteps(['/web/dataset/search_read', '/web/dataset/call_kw/foo/default_get']); list.destroy(); @@ -2403,7 +2413,7 @@ QUnit.module('Views', { }, }); - list.$('td:contains(blip)').last().click(); + testUtils.dom.click(list.$('td:contains(blip)').last()); assert.strictEqual(document.activeElement.name, "foo", "focus should be on an input with name = foo"); @@ -2417,7 +2427,7 @@ QUnit.module('Views', { list.$('tr.o_selected_row input[name="int_field"]').trigger({type: 'keydown', which: 9}); // tab - assert.ok(list.$('tr.o_data_row:eq(4)').hasClass('o_selected_row'), + assert.hasClass(list.$('tr.o_data_row:eq(4)'),'o_selected_row', "5th row should be selected"); assert.strictEqual(document.activeElement.name, "foo", "focus should be on an input with name = foo"); @@ -2455,16 +2465,16 @@ QUnit.module('Views', { }, }); - list.$('td:contains(-4)').last().click(); + testUtils.dom.click(list.$('td:contains(-4)').last()); - list.$('tr.o_selected_row input[name="int_field"]').val('1234').trigger('input'); + testUtils.fields.editInput(list.$('tr.o_selected_row input[name="int_field"]'), '1234'); list.$('tr.o_selected_row input[name="int_field"]').trigger({type: 'keydown', which: 9}); // tab defaultGetDef.resolve(); - assert.strictEqual(list.$('tbody tr.o_data_row').length, 4, + assert.containsN(list, 'tbody tr.o_data_row', 4, "should have 4 data rows"); readDef.resolve(); - assert.strictEqual(list.$('tbody tr.o_data_row').length, 5, + assert.containsN(list, 'tbody tr.o_data_row', 5, "should have 5 data rows"); assert.strictEqual(list.$('td:contains(1234)').length, 1, "should have a cell with new value"); @@ -2473,7 +2483,7 @@ QUnit.module('Views', { // operation requires that this.currentRow is properly set in the // list editable renderer. list.$('tr.o_selected_row input[name="foo"]').trigger({type: 'keydown', which: 9}); // tab - assert.ok(list.$('tr.o_data_row:eq(4)').hasClass('o_selected_row'), + assert.hasClass(list.$('tr.o_data_row:eq(4)'),'o_selected_row', "5th row should be selected"); assert.verifySteps(['write', 'read', 'default_get']); @@ -2525,20 +2535,20 @@ QUnit.module('Views', { arch: '<tree editable="top"><field name="foo"/><field name="int_field"/></tree>', }); - list.$('.o_data_row:nth(2) > td:not(.o_list_record_selector)').first().click(); + testUtils.dom.click(list.$('.o_data_row:nth(2) > td:not(.o_list_record_selector)').first()); assert.ok(list.$('.o_data_row:nth(2)').is('.o_selected_row'), "third row should be in edition"); - list.$buttons.find('.o_list_button_discard').click(); - list.$buttons.find('.o_list_button_add').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_discard')); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); assert.ok(list.$('.o_data_row:nth(0)').is('.o_selected_row'), "first row should be in edition (creation)"); - list.$buttons.find('.o_list_button_discard').click(); - assert.strictEqual(list.$('.o_selected_row').length, 0, + testUtils.dom.click(list.$buttons.find('.o_list_button_discard')); + assert.containsNone(list, '.o_selected_row', "no row should be selected"); - list.$('.o_data_row:nth(2) > td:not(.o_list_record_selector)').first().click(); + testUtils.dom.click(list.$('.o_data_row:nth(2) > td:not(.o_list_record_selector)').first()); assert.ok(list.$('.o_data_row:nth(2)').is('.o_selected_row'), "third 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(); @@ -2559,17 +2569,17 @@ QUnit.module('Views', { }); // click on first td and press TAB - list.$('td:contains(yop)').last().click(); + testUtils.dom.click(list.$('td:contains(yop)').last()); list.$('tr.o_selected_row input[name="foo"]').trigger({type: 'keydown', which: $.ui.keyCode.TAB}); - assert.ok(list.$('tr.o_data_row:eq(1)').hasClass('o_selected_row'), + assert.hasClass(list.$('tr.o_data_row:eq(1)'),'o_selected_row', "2nd row should be selected"); // we do it again. This was broken because the this.currentRow variable // was not properly set, and the second TAB could cause a crash. list.$('tr.o_selected_row input[name="foo"]').trigger({type: 'keydown', which: $.ui.keyCode.TAB}); - assert.ok(list.$('tr.o_data_row:eq(2)').hasClass('o_selected_row'), + assert.hasClass(list.$('tr.o_data_row:eq(2)'),'o_selected_row', "3rd row should be selected"); list.destroy(); @@ -2591,7 +2601,7 @@ QUnit.module('Views', { }); // click on first td and press TAB - list.$('td:contains(yop)').last().click(); + testUtils.dom.click(list.$('td:contains(yop)').last()); //modity the cell content document.activeElement.value = "blip-changed"; @@ -2599,13 +2609,13 @@ QUnit.module('Views', { list.$('tr.o_selected_row input[name="foo"]').trigger({type: 'keydown', which: $.ui.keyCode.TAB}); - assert.ok(list.$('tr.o_data_row:eq(1)').hasClass('o_selected_row'), + assert.hasClass(list.$('tr.o_data_row:eq(1)'),'o_selected_row', "2nd row should be selected"); // we do it again. This was broken because the this.currentRow variable // was not properly set, and the second TAB could cause a crash. list.$('tr.o_selected_row input[name="foo"]').trigger({type: 'keydown', which: $.ui.keyCode.TAB}); - assert.ok(list.$('tr.o_data_row:eq(2)').hasClass('o_selected_row'), + assert.hasClass(list.$('tr.o_data_row:eq(2)'),'o_selected_row', "3rd row should be selected"); list.destroy(); @@ -2623,24 +2633,24 @@ QUnit.module('Views', { '</tree>', }); - assert.strictEqual(list.$('.o_data_row').length, 4, + assert.containsN(list, '.o_data_row', 4, "the list should contain 4 rows"); - list.$('.o_data_row:nth(2) .o_data_cell:first').click(); - assert.ok(list.$('.o_data_row:nth(2)').hasClass('o_selected_row'), + testUtils.dom.click(list.$('.o_data_row:nth(2) .o_data_cell:first')); + assert.hasClass(list.$('.o_data_row:nth(2)'),'o_selected_row', "third row should be in edition"); // Press 'Tab' -> should go to next line // add a value in the cell because the Tab on an empty first cell would activate the next widget in the view - list.$('.o_selected_row input').val(11).trigger('input'); + testUtils.fields.editInput(list.$('.o_selected_row input').eq(1), 11); list.$('.o_selected_row input').trigger({type: 'keydown', which: 9}); - assert.ok(list.$('.o_data_row:nth(3)').hasClass('o_selected_row'), + assert.hasClass(list.$('.o_data_row:nth(3)'),'o_selected_row', "fourth row should be in edition"); // Press 'Tab' -> should go back to first line as the create action isn't available - list.$('.o_selected_row input').val(11).trigger('input'); + testUtils.fields.editInput(list.$('.o_selected_row input').eq(1), 11); list.$('.o_selected_row input').trigger({type: 'keydown', which: 9}); - assert.ok(list.$('.o_data_row:first').hasClass('o_selected_row'), + assert.hasClass(list.$('.o_data_row:first'),'o_selected_row', "first row should be in edition"); list.destroy(); @@ -2668,16 +2678,16 @@ QUnit.module('Views', { }, }); - assert.strictEqual(form.$('.o_field_widget[name=o2m] .o_data_row').length, 2, + assert.containsN(form, '.o_field_widget[name=o2m] .o_data_row', 2, "there should be two records in the many2many"); - form.$('.o_field_widget[name=o2m] .o_data_cell:first').click(); - assert.ok(form.$('.o_field_widget[name=o2m] .o_data_row:first').hasClass('o_selected_row'), + testUtils.dom.click(form.$('.o_field_widget[name=o2m] .o_data_cell:first')); + assert.hasClass(form.$('.o_field_widget[name=o2m] .o_data_row:first'),'o_selected_row', "first row should be in edition"); // Press 'Tab' -> should go to next line form.$('.o_field_widget[name=o2m] .o_selected_row input').trigger({type: 'keydown', which: 9}); - assert.ok(form.$('.o_field_widget[name=o2m] .o_data_row:nth(1)').hasClass('o_selected_row'), + assert.hasClass(form.$('.o_field_widget[name=o2m] .o_data_row:nth(1)'),'o_selected_row', "second row should be in edition"); // Press 'Tab' -> should get out of the one to many and go to the next field of the form @@ -2710,8 +2720,8 @@ QUnit.module('Views', { }); // click on first td and press TAB - list.$('td:contains(yop)').click(); - list.$('tr.o_selected_row input[name="foo"]').val('new value').trigger('change'); + testUtils.dom.click(list.$('td:contains(yop)')); + testUtils.fields.editSelect(list.$('tr.o_selected_row input[name="foo"]'), 'new value'); list.$('tr.o_selected_row input[name="foo"]').trigger({type: 'keydown', which: $.ui.keyCode.TAB}); assert.strictEqual(list.$('tbody tr:first td:contains(new value)').length, 1, @@ -2735,7 +2745,7 @@ QUnit.module('Views', { res_id: 1, }); - list.$('td:contains(gnap)').click(); + testUtils.dom.click(list.$('td:contains(gnap)')); assert.strictEqual(list.$('input[name="foo"]')[0], document.activeElement, "foo should be focused"); list.$('input[name="foo"]').trigger($.Event('keydown', {which: $.ui.keyCode.TAB})); @@ -2759,7 +2769,7 @@ QUnit.module('Views', { res_id: 1, }); - list.$('tbody tr:eq(2) td:eq(1)').click(); + testUtils.dom.click(list.$('tbody tr:eq(2) td:eq(1)')); assert.strictEqual(list.$('tbody tr:eq(2) input[name="foo"]')[0], document.activeElement, "foo should be focused"); list.$('tbody tr:eq(2) input[name="foo"]').trigger($.Event('keydown', {which: $.ui.keyCode.TAB})); @@ -2786,7 +2796,7 @@ QUnit.module('Views', { res_id: 1, }); - list.$('tbody tr:eq(2) td:eq(2)').click(); + testUtils.dom.click(list.$('tbody tr:eq(2) td:eq(2)')); assert.strictEqual(list.$('tbody tr:eq(2) input[name="foo"]')[0], document.activeElement, "foo should be focused"); list.$('tbody tr:eq(2) input[name="foo"]').trigger($.Event('keydown', {which: $.ui.keyCode.TAB})); @@ -2806,11 +2816,11 @@ QUnit.module('Views', { arch: '<tree editable="bottom"><field name="foo"/></tree>', }); - list.$('td:contains(yop)').click(); - assert.ok(list.$('tr.o_data_row:eq(0)').hasClass('o_selected_row'), + testUtils.dom.click(list.$('td:contains(yop)')); + assert.hasClass(list.$('tr.o_data_row:eq(0)'),'o_selected_row', "1st row should be selected"); list.$('tr.o_selected_row input[name="foo"]').trigger({type: 'keydown', which: $.ui.keyCode.DOWN}); - assert.ok(list.$('tr.o_data_row:eq(0)').hasClass('o_selected_row'), + assert.hasClass(list.$('tr.o_data_row:eq(0)'),'o_selected_row', "1st row should still be selected"); list.destroy(); }); @@ -2830,7 +2840,7 @@ QUnit.module('Views', { '</tree>', }); - list.$('td:contains(yop)').click(); + testUtils.dom.click(list.$('td:contains(yop)')); var textarea = list.$('textarea[name="foo"]')[0]; assert.strictEqual(document.activeElement, textarea, "textarea should be focused"); @@ -2865,13 +2875,13 @@ QUnit.module('Views', { assert.strictEqual(list.$('.o_data_cell:first').text(), "yop", "first cell should contain 'yop'"); - list.$('.o_data_cell:first').click(); - list.$('input[name="foo"]').val("hello").trigger('input'); - list.$buttons.find('.o_list_button_discard').click(); + testUtils.dom.click(list.$('.o_data_cell:first')); + testUtils.fields.editInput(list.$('input[name="foo"]'), "hello"); + testUtils.dom.click(list.$buttons.find('.o_list_button_discard')); assert.strictEqual($('.modal:visible').length, 1, "a modal to ask for discard should be visible"); - $('.modal:visible .btn-primary').click(); + testUtils.dom.click($('.modal:visible .btn-primary')); assert.strictEqual(list.$('.o_data_cell:first').text(), "yop", "first cell should still contain 'yop'"); @@ -2908,7 +2918,7 @@ QUnit.module('Views', { assert.strictEqual(nbCellRight, 2, "there should be two right-aligned cells"); - list.$('.o_data_cell:first').click(); + testUtils.dom.click(list.$('.o_data_cell:first')); var nbInputRight = _.filter(list.$('.o_data_row:first > .o_data_cell input'), function (el) { var style = window.getComputedStyle(el); @@ -2942,20 +2952,21 @@ QUnit.module('Views', { }, }); - list.$('.o_data_cell:first').click(); + testUtils.dom.click(list.$('.o_data_cell:first')); assert.verifySteps([], 'no switch view should have been requested'); - assert.strictEqual(list.$('.o_selected_row').length, 1, + assert.containsOnce(list, '.o_selected_row', "a row should be in edition"); + testUtils.dom.click(list.$buttons.find('.o_list_button_discard')); // reload with groupBy list.reload({groupBy: ['bar']}); // clicking on record should open the form view - list.$('.o_group_header:first').click(); - list.$('.o_data_cell:first').click(); + testUtils.dom.click(list.$('.o_group_header:first')); + testUtils.dom.click(list.$('.o_data_cell:first')); // clicking on create button should open the form view - list.$buttons.find('.o_list_button_add').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); assert.verifySteps(['switch view form 1', 'switch view form false'], 'two switch view to form should have been requested'); @@ -2986,11 +2997,11 @@ QUnit.module('Views', { // the view being grouped, it is not editable, so clicking on a record // should open the form view - list.$('.o_group_header:first').click(); // open first group - list.$('.o_data_cell:first').click(); + testUtils.dom.click(list.$('.o_group_header:first')); + testUtils.dom.click(list.$('.o_data_cell:first')); // for the same reason, clicking on 'Create' should open the form view - list.$buttons.find('.o_list_button_add').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); assert.verifySteps(['switch view form 1', 'switch view form false'], "two switch view to form should have been requested"); @@ -3000,16 +3011,16 @@ QUnit.module('Views', { // as the view is no longer grouped, it is editable, so clicking on a // row should switch it in edition - list.$('.o_data_cell:first').click(); + testUtils.dom.click(list.$('.o_data_cell:first')); assert.verifySteps(['switch view form 1', 'switch view form false'], "no more switch view should have been requested"); - assert.strictEqual(list.$('.o_selected_row').length, 1, + assert.containsOnce(list, '.o_selected_row', "a row should be in edition"); // clicking on the body should leave the edition - $('body').click(); - assert.strictEqual(list.$('.o_selected_row').length, 0, + testUtils.dom.click($('body')); + assert.containsNone(list, '.o_selected_row', "the row should no longer be in edition"); list.destroy(); @@ -3044,12 +3055,12 @@ QUnit.module('Views', { arch: '<tree editable="top"><field name="foo"/></tree>', }); - list.$buttons.find('.o_list_button_add').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); list.$('input[name="foo"]').trigger({type: 'keydown', which: $.ui.keyCode.ESCAPE}); - assert.strictEqual(list.$('tr.o_data_row').length, 4, + assert.containsN(list, 'tr.o_data_row', 4, "should have 4 data row in list"); - assert.strictEqual(list.$('tr.o_data_row.o_selected_row').length, 0, + assert.containsNone(list, 'tr.o_data_row.o_selected_row', "no rows should be selected"); assert.ok(!list.$buttons.find('.o_list_button_save').is(':visible'), "should not have a visible save button"); @@ -3066,12 +3077,12 @@ QUnit.module('Views', { arch: '<tree editable="top"><field name="foo" required="1"/></tree>', }); - list.$buttons.find('.o_list_button_add').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); list.$('input[name="foo"]').trigger({type: 'keydown', which: $.ui.keyCode.ESCAPE}); - assert.strictEqual(list.$('tr.o_data_row').length, 4, + assert.containsN(list, 'tr.o_data_row', 4, "should have 4 data row in list"); - assert.strictEqual(list.$('tr.o_data_row.o_selected_row').length, 0, + assert.containsNone(list, 'tr.o_data_row.o_selected_row', "no rows should be selected"); assert.ok(!list.$buttons.find('.o_list_button_save').is(':visible'), "should not have a visible save button"); @@ -3131,7 +3142,7 @@ QUnit.module('Views', { "default fourth record should have amount 0"); // Drag and drop the fourth line in second position - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( list.$('.ui-sortable-handle').eq(3), list.$('tbody tr').first(), {position: 'bottom'} @@ -3212,28 +3223,28 @@ QUnit.module('Views', { }); assert.strictEqual(list.$('tbody tr td.o_list_number').text(), '1234', "default should be sorted by id"); - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( list.$('.ui-sortable-handle').eq(3), list.$('tbody tr').eq(2), {position: 'top'} ); assert.strictEqual(list.$('tbody tr td.o_list_number').text(), '1243', "the int_field (sequence) should have been correctly updated"); - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( list.$('.ui-sortable-handle').eq(2), list.$('tbody tr').eq(1), {position: 'top'} ); assert.deepEqual(list.$('tbody tr td.o_list_number').text(), '1423', "the int_field (sequence) should have been correctly updated"); - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( list.$('.ui-sortable-handle').eq(1), list.$('tbody tr').eq(3), {position: 'top'} ); assert.deepEqual(list.$('tbody tr td.o_list_number').text(), '1243', "the int_field (sequence) should have been correctly updated"); - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( list.$('.ui-sortable-handle').eq(2), list.$('tbody tr').eq(1), {position: 'top'} @@ -3283,7 +3294,7 @@ QUnit.module('Views', { "default fourth record should have amount 0"); // Drag and drop the fourth line in second position - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( list.$('.ui-sortable-handle').eq(3), list.$('tbody tr').first(), {position: 'bottom'} @@ -3298,7 +3309,7 @@ QUnit.module('Views', { assert.strictEqual(list.$('tbody tr:eq(3) td:last').text(), '300', "new fourth record should have amount 300"); - list.$('tbody tr:eq(1) td:last').click(); + testUtils.dom.click(list.$('tbody tr:eq(1) td:last')); assert.strictEqual(list.$('tbody tr:eq(1) td:last input').val(), '0', "the edited record should be the good one"); @@ -3331,7 +3342,7 @@ QUnit.module('Views', { "default should be sorted by int_field"); // Drag and drop the fourth line in second position - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( list.$('.ui-sortable-handle').eq(3), list.$('tbody tr').first(), {position: 'bottom'} @@ -3342,13 +3353,13 @@ QUnit.module('Views', { "drag and drop should have succeeded, as the handle is unlocked"); // Sorting by a field different for int_field should lock the handle - list.$('.o_column_sortable').eq(1).click(); + testUtils.dom.click(list.$('.o_column_sortable').eq(1)); assert.strictEqual(list.$('tbody span[name="amount"]').text(), '0.00300.00500.001200.00', "should have been sorted by amount"); // Drag and drop the fourth line in second position (not) - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( list.$('.ui-sortable-handle').eq(3), list.$('tbody tr').first(), {position: 'bottom'} @@ -3358,13 +3369,13 @@ QUnit.module('Views', { "drag and drop should have failed as the handle is locked"); // Sorting by int_field should unlock the handle - list.$('.o_column_sortable').eq(0).click(); + testUtils.dom.click(list.$('.o_column_sortable').eq(0)); assert.strictEqual(list.$('tbody span[name="amount"]').text(), '1200.000.00500.00300.00', "records should be ordered as per the previous resequence"); // Drag and drop the fourth line in second position - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( list.$('.ui-sortable-handle').eq(3), list.$('tbody tr').first(), {position: 'bottom'} @@ -3422,14 +3433,14 @@ QUnit.module('Views', { "default fourth record should have amount 0"); // drag and drop the fourth line in second position - testUtils.dragAndDrop( + testUtils.dom.dragAndDrop( list.$('.ui-sortable-handle').eq(3), list.$('tbody tr').first(), {position: 'bottom'} ); // edit moved row before the end of resequence - list.$('tbody tr:eq(3) td:last').click(); + testUtils.dom.click(list.$('tbody tr:eq(3) td:last')); assert.strictEqual(list.$('tbody tr:eq(3) td:last input').length, 0, "shouldn't edit the line before resequence"); @@ -3442,10 +3453,10 @@ QUnit.module('Views', { assert.strictEqual(list.$('tbody tr:eq(3) td:last input').val(), '300', "fourth record should have amount 300"); - list.$('tbody tr:eq(3) td:last input').val(301).trigger('input'); - list.$('tbody tr:eq(0) td:last').click(); + testUtils.fields.editInput(list.$('tbody tr:eq(3) td:last input'), 301); + testUtils.dom.click(list.$('tbody tr:eq(0) td:last')); - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); assert.strictEqual(list.$('tbody tr:eq(0) td:last').text(), '1200', "first record should have amount 1200"); @@ -3456,7 +3467,7 @@ QUnit.module('Views', { assert.strictEqual(list.$('tbody tr:eq(3) td:last').text(), '301', "fourth record should have amount 301"); - list.$('tbody tr:eq(3) td:last').click(); + testUtils.dom.click(list.$('tbody tr:eq(3) td:last')); assert.strictEqual(list.$('tbody tr:eq(3) td:last input').val(), '301', "fourth record should have amount 301"); @@ -3485,16 +3496,16 @@ QUnit.module('Views', { }, }); - assert.strictEqual(list.$('.o_data_row').length, 4, + assert.containsN(list, '.o_data_row', 4, "should contain 4 records"); // click on Add twice, and delay the onchange - list.$buttons.find('.o_list_button_add').click(); - list.$buttons.find('.o_list_button_add').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); def.resolve(); - assert.strictEqual(list.$('.o_data_row').length, 5, + assert.containsN(list, '.o_data_row', 5, "only one record should have been created"); list.destroy(); @@ -3556,9 +3567,9 @@ QUnit.module('Views', { }, }); - list.$('.o_data_cell:first').click(); - list.$('.o_field_widget[name=foo]').val('abc').trigger('input'); - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$('.o_data_cell:first')); + testUtils.fields.editInput(list.$('.o_field_widget[name=foo]'), 'abc'); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); list.destroy(); }); @@ -3598,10 +3609,10 @@ QUnit.module('Views', { }, }); - list.$('.o_group_header:first').click(); // open the first group - assert.strictEqual(list.$('.o_data_row:first .o_toggle_button_success').length, 1, + testUtils.dom.click(list.$('.o_group_header:first')); + assert.containsOnce(list, '.o_data_row:first .o_toggle_button_success', "boolean value of the first record should be true"); - list.$('.o_data_row:first .o_icon_button').click(); // toggle the value + testUtils.dom.click(list.$('.o_data_row:first .o_icon_button')); assert.strictEqual(list.$('.o_data_row:first .text-muted:not(.o_toggle_button_success)').length, 1, "boolean button should have been updated"); @@ -3647,10 +3658,10 @@ QUnit.module('Views', { }); // open the first group - list.$('.o_group_header:first').click(); + testUtils.dom.click(list.$('.o_group_header:first')); assert.strictEqual(list.$('th.o_group_name').eq(1).children().length, 1, "There should be an empty element creating the indentation for the subgroup."); - assert.strictEqual(list.$('th.o_group_name').eq(1).children().eq(0).hasClass('fa'), true, + assert.hasClass(list.$('th.o_group_name').eq(1).children().eq(0), 'fa', "The first element of the row name should have the fa class"); assert.strictEqual(list.$('th.o_group_name').eq(1).children().eq(0).is('span'), true, "The first element of the row name should be a span"); @@ -3702,7 +3713,7 @@ QUnit.module('Views', { assert.strictEqual(list.pager.$el.text().trim(), '1-2 / 4', "pager should be correct"); - assert.strictEqual(list.$('.o_data_row').length, 2, + assert.containsN(list, '.o_data_row', 2, 'should display 2 data rows'); list.destroy(); }); @@ -3711,7 +3722,7 @@ QUnit.module('Views', { assert.expect(1); var instanceNumber = 0; - testUtils.patch(mixins.ParentedMixin, { + testUtils.mock.patch(mixins.ParentedMixin, { init: function () { instanceNumber++; return this._super.apply(this, arguments); @@ -3759,7 +3770,7 @@ QUnit.module('Views', { list.destroy(); - testUtils.unpatch(mixins.ParentedMixin); + testUtils.mock.unpatch(mixins.ParentedMixin); }); QUnit.test('concurrent reloads finishing in inverse order', function (assert) { @@ -3781,14 +3792,14 @@ QUnit.module('Views', { }, }); - assert.strictEqual(list.$('.o_list_view .o_data_row').length, 4, + assert.containsN(list, '.o_list_view .o_data_row', 4, "list view should contain 4 records"); // reload with a domain (this request is blocked) blockSearchRead = true; list.reload({domain: [['foo', '=', 'yop']]}); - assert.strictEqual(list.$('.o_list_view .o_data_row').length, 4, + assert.containsN(list, '.o_list_view .o_data_row', 4, "list view should still contain 4 records (search_read being blocked)"); // reload without the domain @@ -3797,7 +3808,7 @@ QUnit.module('Views', { // unblock the RPC def.resolve(); - assert.strictEqual(list.$('.o_list_view .o_data_row').length, 4, + assert.containsN(list, '.o_list_view .o_data_row', 4, "list view should still contain 4 records"); list.destroy(); @@ -3806,7 +3817,7 @@ QUnit.module('Views', { QUnit.test('list view on a "noCache" model', function (assert) { assert.expect(8); - testUtils.patch(BasicModel, { + testUtils.mock.patch(BasicModel, { noCacheModels: BasicModel.prototype.noCacheModels.concat(['foo']), }); @@ -3830,19 +3841,20 @@ QUnit.module('Views', { core.bus.on('clear_cache', list, assert.step.bind(assert, 'clear_cache')); // create a new record - list.$buttons.find('.o_list_button_add').click(); - list.$('.o_selected_row .o_field_widget').val('some value').trigger('input'); - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$buttons.find('.o_list_button_add')); + testUtils.fields.editInput(list.$('.o_selected_row .o_field_widget'), 'some value'); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); // edit an existing record - list.$('.o_data_cell:first').click(); - list.$('.o_selected_row .o_field_widget').val('new value').trigger('input'); - list.$buttons.find('.o_list_button_save').click(); + testUtils.dom.click(list.$('.o_data_cell:first')); + testUtils.fields.editInput(list.$('.o_selected_row .o_field_widget'), 'new value'); + testUtils.dom.click(list.$buttons.find('.o_list_button_save')); // delete a record - list.$('.o_data_row:first .o_list_record_selector input').click(); - list.sidebar.$('a:contains(Delete)').click(); - $('.modal-footer .btn-primary').click(); // confirm + testUtils.dom.click(list.$('.o_data_row:first .o_list_record_selector input')); + testUtils.dom.click(list.sidebar.$('.o_dropdown_toggler_btn:contains(Action)')); + testUtils.dom.click(list.sidebar.$('a:contains(Delete)')); + testUtils.dom.click($('.modal-footer .btn-primary')); assert.verifySteps([ 'create', @@ -3854,7 +3866,7 @@ QUnit.module('Views', { ]); list.destroy(); - testUtils.unpatch(BasicModel); + testUtils.mock.unpatch(BasicModel); }); QUnit.test('list should ask to scroll to top on page changes', function (assert) { @@ -3877,14 +3889,14 @@ QUnit.module('Views', { }); // switch pages (should ask to scroll) - list.pager.$('.o_pager_next').click(); - list.pager.$('.o_pager_previous').click(); + testUtils.dom.click(list.pager.$('.o_pager_next')); + testUtils.dom.click(list.pager.$('.o_pager_previous')); assert.verifySteps(['scroll', 'scroll'], "should ask to scroll when switching pages"); // change the limit (should not ask to scroll) - list.pager.$('.o_pager_value').click(); + testUtils.dom.click(list.pager.$('.o_pager_value')); list.pager.$('.o_pager_value input').val('1-2').blur(); assert.strictEqual(list.pager.$('.o_pager_value').text(), '1-2', "should have changed the limit"); @@ -3893,7 +3905,7 @@ QUnit.module('Views', { "should not ask to scroll when changing the limit"); // switch pages again (should still ask to scroll) - list.pager.$('.o_pager_next').click(); + testUtils.dom.click(list.pager.$('.o_pager_next')); assert.verifySteps(['scroll', 'scroll', 'scroll'], "this is still working after a limit change"); @@ -3925,9 +3937,10 @@ QUnit.module('Views', { // check line is at the correct place var inputText = 'ninja'; - $('.o_list_button_add').click(); - list.$('.o_input[name="foo"]').val(inputText).trigger('input'); - $('.o_list_button_add').click(); + testUtils.dom.click($('.o_list_button_add')); + testUtils.fields.editInput(list.$('.o_input[name="foo"]'), inputText); + testUtils.dom.click($('.o_list_button_save')); + testUtils.dom.click($('.o_list_button_add')); assert.strictEqual($('.o_data_cell').text(), "blipblipyopgnap" + inputText); diff --git a/addons/web/static/tests/views/pivot_tests.js b/addons/web/static/tests/views/pivot_tests.js index 858edcd55e4..29bbf1ec4b4 100644 --- a/addons/web/static/tests/views/pivot_tests.js +++ b/addons/web/static/tests/views/pivot_tests.js @@ -6,7 +6,7 @@ var PivotView = require('web.PivotView'); var testUtils = require('web.test_utils'); var createActionManager = testUtils.createActionManager; -var patchDate = testUtils.patchDate; +var patchDate = testUtils.mock.patchDate; var _t = core._t; var createView = testUtils.createView; @@ -106,7 +106,7 @@ QUnit.module('Views', { }, }); - assert.ok(pivot.$el.hasClass('o_enable_linking'), + assert.hasClass(pivot.$el,'o_enable_linking', "root node should have classname 'o_enable_linking'"); assert.strictEqual(pivot.$('td.o_pivot_cell_value:contains(32)').length, 1, "should contain a pivot cell with the sum of all records"); @@ -206,9 +206,9 @@ QUnit.module('Views', { } }); - assert.ok(pivot.$el.hasClass('o_enable_linking'), + assert.hasClass(pivot.$el,'o_enable_linking', "root node should have classname 'o_enable_linking'"); - pivot.$('.o_pivot_cell_value:contains(12)').click(); // should trigger a do_action + testUtils.dom.click(pivot.$('.o_pivot_cell_value:contains(12)')); // should trigger a do_action pivot.destroy(); }); @@ -230,11 +230,11 @@ QUnit.module('Views', { }, }); - assert.notOk(pivot.$el.hasClass('o_enable_linking'), + assert.doesNotHaveClass(pivot.$el, 'o_enable_linking', "root node should not have classname 'o_enable_linking'"); - assert.strictEqual(pivot.$('.o_pivot_cell_value').length, 1, + assert.containsOnce(pivot, '.o_pivot_cell_value', "should have one cell"); - pivot.$('.o_pivot_cell_value').click(); // should not trigger a do_action + testUtils.dom.click(pivot.$('.o_pivot_cell_value')); // should not trigger a do_action pivot.destroy(); }); @@ -280,7 +280,7 @@ QUnit.module('Views', { }); var $countMeasure = pivot.$buttons.find('.dropdown-item[data-field=__count]:first'); - assert.ok($countMeasure.hasClass('selected'), "The count measure should be activated"); + assert.hasClass($countMeasure,'selected', "The count measure should be activated"); pivot.destroy(); }); @@ -305,7 +305,7 @@ QUnit.module('Views', { "should contain a pivot cell with the number of all records"); assert.strictEqual(readGroupCount, 1, "should have done 1 rpc"); - pivot.update({domain: [['foo', '>', 10]]}); + testUtils.pivot.reload(pivot, {domain: [['foo', '>', 10]]}); assert.strictEqual(pivot.$('td.o_pivot_cell_value:contains(2)').length, 1, "should contain a pivot cell with the number of remaining records"); assert.strictEqual(readGroupCount, 2, "should have done 2 rpcs"); @@ -325,7 +325,7 @@ QUnit.module('Views', { '</pivot>', }); - assert.strictEqual(pivot.$('.o_pivot_header_cell_opened').length, 1, + assert.containsOnce(pivot, '.o_pivot_header_cell_opened', "should have one opened header"); assert.strictEqual(pivot.$('.o_pivot_header_cell_closed:contains(xphone)').length, 1, "should display one header with 'xphone'"); @@ -353,28 +353,28 @@ QUnit.module('Views', { }, }); - assert.strictEqual(pivot.$('tbody tr').length, 3, + assert.containsN(pivot, 'tbody tr', 3, "should have 3 rows: 1 for the opened header, and 2 for data"); // click on the opened header to close it - pivot.$('.o_pivot_header_cell_opened').click(); + testUtils.dom.click(pivot.$('.o_pivot_header_cell_opened')); - assert.strictEqual(pivot.$('tbody tr').length, 1, "should have 1 row"); + assert.containsOnce(pivot, 'tbody tr', "should have 1 row"); // click on closed header to open dropdown - pivot.$('tbody .o_pivot_header_cell_closed').click(); + testUtils.dom.click(pivot.$('tbody .o_pivot_header_cell_closed')); - assert.strictEqual(pivot.$('.o_pivot_field_menu .dropdown-item[data-field="date"]:first').length, 1, + assert.containsOnce(pivot, '.o_pivot_field_menu .dropdown-item[data-field="date"]:first', "should have the date field as proposition"); - assert.strictEqual(pivot.$('.o_field_selection .dropdown-item[data-field="product_id"]:first').length, 1, + assert.containsOnce(pivot, '.o_field_selection .dropdown-item[data-field="product_id"]:first', "should have the product_id field as proposition"); - assert.strictEqual(pivot.$('.o_field_selection .dropdown-item[data-field="non_stored_m2o"]:first').length, 0, + assert.containsNone(pivot, '.o_field_selection .dropdown-item[data-field="non_stored_m2o"]:first', "should not have the non_stored_m2o field as proposition"); - pivot.$('.o_pivot_field_menu .dropdown-item[data-field="date"]:first').click(); + testUtils.dom.click(pivot.$('.o_pivot_field_menu .dropdown-item[data-field="date"]:first')); - assert.strictEqual(pivot.$('tbody tr').length, 4, + assert.containsN(pivot, 'tbody tr', 4, "should have 4 rows: one for header, 3 for data"); assert.strictEqual(rpcCount, 3, "should have done 3 rpcs (initial load) + open header with different groupbys"); @@ -395,14 +395,15 @@ QUnit.module('Views', { }); // open dropdown to zoom into first row - pivot.$('tbody .o_pivot_header_cell_closed').first().click(); + testUtils.dom.clickFirst(pivot.$('tbody .o_pivot_header_cell_closed')); // click on date by day - pivot.$('.o_pivot_field_menu .dropdown-item[data-field="date"][data-interval="day"]').click(); + pivot.$('.dropdown-menu.show .o_inline_dropdown .dropdown-menu').toggle(); // unfold inline dropdown + testUtils.dom.click(pivot.$('.o_pivot_field_menu .dropdown-item[data-field="date"][data-interval="day"]')); // open dropdown to zoom into second row - pivot.$('tbody td.o_pivot_header_cell_closed:eq(1)').first().click(); + testUtils.dom.clickLast(pivot.$('tbody td.o_pivot_header_cell_closed')); - assert.strictEqual(pivot.$('tbody tr').length, 7, + assert.containsN(pivot, 'tbody tr', 7, "should have 7 rows (1 for total, 1 for xphone, 1 for xpad, 4 for data)"); pivot.destroy(); }); @@ -425,14 +426,14 @@ QUnit.module('Views', { }, }); - assert.strictEqual(pivot.$('tbody tr').length, 3, + assert.containsN(pivot, 'tbody tr', 3, "should have 3 rows: 1 for the open header, and 2 for data"); rpcCount = 0; - pivot.$buttons.find('.o_pivot_flip_button').click(); + testUtils.dom.click(pivot.$buttons.find('.o_pivot_flip_button')); assert.strictEqual(rpcCount, 0, "should not have done any rpc"); - assert.strictEqual(pivot.$('tbody tr').length, 1, + assert.containsOnce(pivot, 'tbody tr', "should have 1 rows: 1 for the main header"); pivot.destroy(); }); @@ -456,29 +457,31 @@ QUnit.module('Views', { }, }); - assert.strictEqual(pivot.$('.o_pivot_cell_value').length, 3, + assert.containsN(pivot, '.o_pivot_cell_value', 3, "should have 3 cells: 1 for the open header, and 2 for data"); - assert.ok(!pivot.$buttons.find('.dropdown-item[data-field=__count]:first').hasClass('selected'), + assert.doesNotHaveClass(pivot.$buttons.find('.dropdown-item[data-field=__count]:first'), 'selected', "the __count measure should not be selected"); rpcCount = 0; - pivot.$buttons.find('.dropdown-item[data-field=__count]:first').click(); + testUtils.pivot.toggleMeasuresDropdown(pivot); + testUtils.pivot.clickMeasure(pivot, '__count'); - assert.ok(pivot.$buttons.find('.dropdown-item[data-field=__count]:first').hasClass('selected'), + assert.hasClass(pivot.$buttons.find('.dropdown-item[data-field=__count]:first'),'selected', "the __count measure should be selected"); - assert.strictEqual(pivot.$('.o_pivot_cell_value').length, 6, + assert.containsN(pivot, '.o_pivot_cell_value', 6, "should have 6 cells: 2 for the open header, and 4 for data"); assert.strictEqual(rpcCount, 2, "should have done 2 rpcs to reload data"); - pivot.$buttons.find('.dropdown-item[data-field=__count]:first').click(); + testUtils.pivot.clickMeasure(pivot, '__count'); - assert.ok(!pivot.$buttons.find('.dropdown-item[data-field=__count]:first').hasClass('selected'), + assert.doesNotHaveClass(pivot.$buttons.find('.dropdown-item[data-field=__count]:first'), 'selected', "the __count measure should not be selected"); - assert.strictEqual(pivot.$('.o_pivot_cell_value').length, 3, + assert.containsN(pivot, '.o_pivot_cell_value', 3, "should have 3 cells: 1 for the open header, and 2 for data"); assert.strictEqual(rpcCount, 2, "should not have done any extra rpcs"); + pivot.destroy(); }); @@ -493,16 +496,17 @@ QUnit.module('Views', { '</pivot>', }); - assert.strictEqual(pivot.$('.o_view_nocontent').length, 0, + assert.containsNone(pivot, '.o_view_nocontent', "should not have a no_content_helper"); - assert.strictEqual(pivot.$('table').length, 1, + assert.containsOnce(pivot, 'table', "should have a table in DOM"); - pivot.$buttons.find('.dropdown-item[data-field=__count]:first').click(); + testUtils.pivot.toggleMeasuresDropdown(pivot); + testUtils.pivot.clickMeasure(pivot, '__count'); - assert.strictEqual(pivot.$('.o_view_nocontent').length, 1, + assert.containsOnce(pivot, '.o_view_nocontent', "should have a no_content_helper"); - assert.strictEqual(pivot.$('table').length, 0, + assert.containsNone(pivot, 'table', "should not have a table in DOM"); pivot.destroy(); }); @@ -518,16 +522,16 @@ QUnit.module('Views', { '</pivot>', }); - assert.strictEqual(pivot.$('.o_view_nocontent').length, 0, + assert.containsNone(pivot, '.o_view_nocontent', "should not have a no_content_helper"); - assert.strictEqual(pivot.$('table').length, 1, + assert.containsOnce(pivot, 'table', "should have a table in DOM"); - pivot.update({domain: [['foo', '=', 12345]]}); + testUtils.pivot.reload(pivot, {domain: [['foo', '=', 12345]]}); - assert.strictEqual(pivot.$('.o_view_nocontent').length, 1, + assert.containsOnce(pivot, '.o_view_nocontent', "should have a no_content_helper"); - assert.strictEqual(pivot.$('table').length, 0, + assert.containsNone(pivot, 'table', "should not have a table in DOM"); pivot.destroy(); }); @@ -544,7 +548,7 @@ QUnit.module('Views', { arch: '<pivot string="Partners"></pivot>', }); - assert.strictEqual(pivot.$('.o_view_nocontent').length, 1, + assert.containsOnce(pivot, '.o_view_nocontent', "should have a no_content_helper"); pivot.destroy(); }); @@ -562,19 +566,19 @@ QUnit.module('Views', { }, }); - assert.strictEqual(pivot.$('.o_view_nocontent').length, 1, + assert.containsOnce(pivot, '.o_view_nocontent', "should have a no_content_helper"); - pivot.update({domain: [['foo', '=', 12345]]}); - assert.strictEqual(pivot.$('.o_view_nocontent').length, 1, + testUtils.pivot.reload(pivot, {domain: [['foo', '=', 12345]]}); + assert.containsOnce(pivot, '.o_view_nocontent', "should still have a no_content_helper"); - pivot.update({domain: []}); - assert.strictEqual(pivot.$('.o_view_nocontent').length, 0, + testUtils.pivot.reload(pivot, {domain: []}); + assert.containsNone(pivot, '.o_view_nocontent', "should not have a no_content_helper"); // tries to open a field selection menu, to make sure it was not // removed from the dom. - pivot.$('.o_pivot_header_cell_closed').first().click(); - assert.strictEqual(pivot.$('.o_pivot_field_menu').length, 1, + testUtils.dom.clickFirst(pivot.$('.o_pivot_header_cell_closed')); + assert.containsOnce(pivot, '.o_pivot_field_menu', "the field selector menu exists"); pivot.destroy(); }); @@ -598,18 +602,18 @@ QUnit.module('Views', { }, }); - assert.strictEqual(pivot.$('.o_pivot_cell_value').length, 3, + assert.containsN(pivot, '.o_pivot_cell_value', 3, "should have 3 cells: 1 for the open header, and 2 for data"); assert.strictEqual(pivot.$('.o_pivot_measure_row:contains(Foo)').length, 1, "should have 1 row for measure Foo"); - pivot.update({domain: [['foo', '=', 12345]]}); + testUtils.pivot.reload(pivot, {domain: [['foo', '=', 12345]]}); rpcCount = 0; - pivot.update({domain: []}); + testUtils.pivot.reload(pivot, {domain: []}); assert.equal(rpcCount, 2, "should have reloaded data"); - assert.strictEqual(pivot.$('.o_pivot_cell_value').length, 3, + assert.containsN(pivot, '.o_pivot_cell_value', 3, "should still have 3 cells: 1 for the open header, and 2 for data"); assert.strictEqual(pivot.$('.o_pivot_measure_row:contains(Foo)').length, 1, "should still have 1 row for measure Foo"); @@ -628,16 +632,16 @@ QUnit.module('Views', { '</pivot>', }); - assert.strictEqual(pivot.$('.o_pivot_cell_value').length, 1, + assert.containsOnce(pivot, '.o_pivot_cell_value', "should have only 1 cell"); - assert.strictEqual(pivot.$('tbody tr').length, 1, + assert.containsOnce(pivot, 'tbody tr', "should have 1 rows"); - pivot.update({groupBy: ['product_id']}); + testUtils.pivot.reload(pivot, {groupBy: ['product_id']}); - assert.strictEqual(pivot.$('.o_pivot_cell_value').length, 3, + assert.containsN(pivot, '.o_pivot_cell_value', 3, "should have 3 cells"); - assert.strictEqual(pivot.$('tbody tr').length, 3, + assert.containsN(pivot, 'tbody tr', 3, "should have 3 rows"); pivot.destroy(); }); @@ -658,12 +662,12 @@ QUnit.module('Views', { assert.strictEqual($('td.o_pivot_cell_value').text(), "321220", "should have proper values in cells (total, result 1, result 2"); - pivot.$('th.o_pivot_measure_row').click(); + testUtils.dom.click(pivot.$('th.o_pivot_measure_row')); assert.strictEqual($('td.o_pivot_cell_value').text(), "322012", "should have proper values in cells (total, result 2, result 1"); - pivot.$('th.o_pivot_measure_row').click(); + testUtils.dom.click(pivot.$('th.o_pivot_measure_row')); assert.strictEqual($('td.o_pivot_cell_value').text(), "321220", "should have proper values in cells (total, result 1, result 2"); @@ -697,25 +701,25 @@ QUnit.module('Views', { // expand on date:days, product nbReadGroups = 0; - pivot.update({groupBy: ['date:days', 'product_id']}); + testUtils.pivot.reload(pivot, {groupBy: ['date:days', 'product_id']}); assert.strictEqual(nbReadGroups, 3, "should have done 3 read_group RPCS"); - assert.strictEqual(pivot.$('tbody tr').length, 8, + assert.containsN(pivot, 'tbody tr', 8, "should have 7 rows (total + 3 for December and 2 for October and April)"); // collapse the last two rows - pivot.$('.o_pivot_header_cell_opened').last().click(); - pivot.$('.o_pivot_header_cell_opened').last().click(); + testUtils.dom.clickLast(pivot.$('.o_pivot_header_cell_opened')); + testUtils.dom.clickLast(pivot.$('.o_pivot_header_cell_opened')); - assert.strictEqual(pivot.$('tbody tr').length, 6, + assert.containsN(pivot, 'tbody tr', 6, "should have 6 rows now"); // expand all nbReadGroups = 0; - pivot.$buttons.find('.o_pivot_expand_button').click(); + testUtils.dom.click(pivot.$buttons.find('.o_pivot_expand_button')); assert.strictEqual(nbReadGroups, 3, "should have done 3 read_group RPCS"); - assert.strictEqual(pivot.$('tbody tr').length, 8, + assert.containsN(pivot, 'tbody tr', 8, "should have 8 rows again"); pivot.destroy(); @@ -743,24 +747,24 @@ QUnit.module('Views', { }); // expand on date:days, product - pivot.update({groupBy: ['date:days', 'product_id']}); + testUtils.pivot.reload(pivot, {groupBy: ['date:days', 'product_id']}); - assert.strictEqual(pivot.$('tbody tr').length, 8, + assert.containsN(pivot, 'tbody tr', 8, "should have 7 rows (total + 3 for December and 2 for October and April)"); // collapse the last two rows - pivot.$('.o_pivot_header_cell_opened').last().click(); - pivot.$('.o_pivot_header_cell_opened').last().click(); + testUtils.dom.clickLast(pivot.$('.o_pivot_header_cell_opened')); + testUtils.dom.clickLast(pivot.$('.o_pivot_header_cell_opened')); - assert.strictEqual(pivot.$('tbody tr').length, 6, + assert.containsN(pivot, 'tbody tr', 6, "should have 6 rows now"); // expand all def = $.Deferred(); - pivot.$buttons.find('.o_pivot_expand_button').click(); + testUtils.dom.click(pivot.$buttons.find('.o_pivot_expand_button')); def.resolve(); - assert.strictEqual(pivot.$('tbody tr').length, 8, + assert.containsN(pivot, 'tbody tr', 8, "should have 8 rows again"); pivot.destroy(); @@ -786,7 +790,7 @@ QUnit.module('Views', { }, }); - pivot.$buttons.find('.o_pivot_download').click(); + testUtils.dom.click(pivot.$buttons.find('.o_pivot_download')); pivot.destroy(); }); @@ -805,7 +809,7 @@ QUnit.module('Views', { '</pivot>', }); - assert.strictEqual(pivot.$buttons.find('.o_pivot_download').attr('disabled'), 'disabled', + assert.hasAttrValue(pivot.$buttons.find('.o_pivot_download'), 'disabled', 'disabled', "download button should be disabled"); pivot.destroy(); }); @@ -830,8 +834,8 @@ QUnit.module('Views', { }, "context should be correct"); // expand header on field customer - pivot.$('thead .o_pivot_header_cell_closed:nth(1)').click(); - pivot.$('.o_pivot_field_menu .dropdown-item[data-field="customer"]:first').click(); + testUtils.dom.click(pivot.$('thead .o_pivot_header_cell_closed:nth(1)')); + testUtils.dom.click(pivot.$('.o_pivot_field_menu .dropdown-item[data-field="customer"]:first')); assert.deepEqual(pivot.getContext(), { pivot_column_groupby: ['date:day', 'customer'], pivot_measures: ['foo'], @@ -839,8 +843,8 @@ QUnit.module('Views', { }, "context should be correct"); // expand row on field product_id - pivot.$('tbody .o_pivot_header_cell_closed').first().click(); - pivot.$('.o_pivot_field_menu .dropdown-item[data-field="product_id"]:first').click(); + testUtils.dom.click(pivot.$('tbody .o_pivot_header_cell_closed')); + testUtils.dom.click(pivot.$('.o_pivot_field_menu .dropdown-item[data-field="product_id"]:first')); assert.deepEqual(pivot.getContext(), { pivot_column_groupby: ['date:day', 'customer'], pivot_measures: ['foo'], @@ -872,14 +876,14 @@ QUnit.module('Views', { }, }); - assert.strictEqual(pivot.$('thead .o_pivot_header_cell_opened').length, 1, + assert.containsOnce(pivot, 'thead .o_pivot_header_cell_opened', "column: should have one opened header"); assert.strictEqual(pivot.$('thead .o_pivot_header_cell_closed:contains(First)').length, 1, "column: should display one closed header with 'First'"); assert.strictEqual(pivot.$('thead .o_pivot_header_cell_closed:contains(Second)').length, 1, "column: should display one closed header with 'Second'"); - assert.strictEqual(pivot.$('tbody .o_pivot_header_cell_opened').length, 1, + assert.containsOnce(pivot, 'tbody .o_pivot_header_cell_opened', "row: should have one opened header"); assert.strictEqual(pivot.$('tbody .o_pivot_header_cell_closed:contains(xphone)').length, 1, "row: should display one closed header with 'xphone'"); @@ -917,16 +921,16 @@ QUnit.module('Views', { pivot_row_groupby: ['product_id'], }, }; - pivot.reload(reloadParams); + testUtils.pivot.reload(pivot, reloadParams); - assert.strictEqual(pivot.$('thead .o_pivot_header_cell_opened').length, 1, + assert.containsOnce(pivot, 'thead .o_pivot_header_cell_opened', "column: should have one opened header"); assert.strictEqual(pivot.$('thead .o_pivot_header_cell_closed:contains(First)').length, 1, "column: should display one closed header with 'First'"); assert.strictEqual(pivot.$('thead .o_pivot_header_cell_closed:contains(Second)').length, 1, "column: should display one closed header with 'Second'"); - assert.strictEqual(pivot.$('tbody .o_pivot_header_cell_opened').length, 1, + assert.containsOnce(pivot, 'tbody .o_pivot_header_cell_opened', "row: should have one opened header"); assert.strictEqual(pivot.$('tbody .o_pivot_header_cell_closed:contains(xphone)').length, 1, "row: should display one closed header with 'xphone'"); @@ -953,14 +957,14 @@ QUnit.module('Views', { groupBy: ['product_id'], }); - assert.strictEqual(pivot.$('thead .o_pivot_header_cell_opened').length, 1, + assert.containsOnce(pivot, 'thead .o_pivot_header_cell_opened', 'column: should have one opened header'); assert.strictEqual(pivot.$('thead .o_pivot_header_cell_closed:contains(First)').length, 1, 'column: should display one closed header with "First"'); assert.strictEqual(pivot.$('thead .o_pivot_header_cell_closed:contains(Second)').length, 1, 'column: should display one closed header with "Second"'); - assert.strictEqual(pivot.$('tbody .o_pivot_header_cell_opened').length, 1, + assert.containsOnce(pivot, 'tbody .o_pivot_header_cell_opened', 'row: should have one opened header'); assert.strictEqual(pivot.$('tbody .o_pivot_header_cell_closed:contains(xphone)').length, 1, 'row: should display one closed header with "xphone"'); @@ -998,7 +1002,7 @@ QUnit.module('Views', { }); var $countMeasure = pivot.$buttons.find('.dropdown-item[data-field=__count]:first'); - assert.ok($countMeasure.hasClass('selected'), "The count measure should be activated"); + assert.hasClass($countMeasure,'selected', "The count measure should be activated"); pivot.destroy(); }); @@ -1069,9 +1073,10 @@ QUnit.module('Views', { '<field name="product_id" type="measure"/>' + '</pivot>', }); - pivot.$('tbody .o_pivot_header_cell_closed').first().click(); + testUtils.dom.click(pivot.$('tbody .o_pivot_header_cell_closed')); // click on date by month - pivot.$('.o_pivot_field_menu .dropdown-item[data-field="date"][data-interval="month"]').click(); + pivot.$('.dropdown-menu.show .o_inline_dropdown .dropdown-menu').toggle(); // unfold inline dropdown + testUtils.dom.click(pivot.$('.o_pivot_field_menu .dropdown-item[data-field="date"][data-interval="month"]')); assert.strictEqual(pivot.$('.o_pivot_cell_value').text(), '2211', 'should have loaded the proper data'); @@ -1093,7 +1098,8 @@ QUnit.module('Views', { }, }); - pivot.$buttons.find('.dropdown-item[data-field=product_id]:first').click(); + testUtils.pivot.toggleMeasuresDropdown(pivot); + testUtils.pivot.clickMeasure(pivot, 'product_id'); assert.strictEqual(pivot.$('.o_pivot_cell_value').text(), '421131', 'should have loaded the proper data'); pivot.destroy(); @@ -1111,9 +1117,9 @@ QUnit.module('Views', { '</pivot>', }); - pivot.$('tbody .o_pivot_header_cell_closed').first().click(); + testUtils.dom.click(pivot.$('tbody .o_pivot_header_cell_closed')); - pivot.$('.o_pivot_field_menu .dropdown-item[data-field="product_id"]:first').click(); + testUtils.dom.click(pivot.$('.o_pivot_field_menu .dropdown-item[data-field="product_id"]:first')); assert.strictEqual(pivot.$('.o_pivot_cell_value').text(), '211', 'should have loaded the proper data'); @@ -1133,15 +1139,15 @@ QUnit.module('Views', { }); // Set a column groupby - pivot.$('thead .o_pivot_header_cell_closed').click(); - pivot.$('.o_field_selection .dropdown-item[data-field=customer]:first').click(); + testUtils.dom.click(pivot.$('thead .o_pivot_header_cell_closed')); + testUtils.dom.click(pivot.$('.o_field_selection .dropdown-item[data-field=customer]:first')); // Set a Row groupby - pivot.$('tbody .o_pivot_header_cell_closed').click(); - pivot.$('.o_pivot_field_menu .dropdown-item[data-field=product_id]:first').click(); + testUtils.dom.click(pivot.$('tbody .o_pivot_header_cell_closed')); + testUtils.dom.click(pivot.$('.o_pivot_field_menu .dropdown-item[data-field=product_id]:first')); // Set a domain - pivot.update({domain: [['product_id', '=', 41]]}); + testUtils.pivot.reload(pivot, {domain: [['product_id', '=', 41]]}); var expectedContext = {pivot_column_groupby: ['customer'], pivot_measures: ['foo'], @@ -1183,13 +1189,13 @@ QUnit.module('Views', { }); def = $.Deferred(); - pivot.update({groupBy: ['product_id']}); - pivot.update({groupBy: ['product_id', 'customer']}); + testUtils.pivot.reload(pivot, {groupBy: ['product_id']}); + testUtils.pivot.reload(pivot, {groupBy: ['product_id', 'customer']}); def.resolve(); - assert.strictEqual(pivot.$('.o_pivot_cell_value').length, 6, + assert.containsN(pivot, '.o_pivot_cell_value', 6, "should have 6 cells"); - assert.strictEqual(pivot.$('tbody tr').length, 6, + assert.containsN(pivot, 'tbody tr', 6, "should have 6 rows"); pivot.destroy(); }); @@ -1235,7 +1241,7 @@ QUnit.module('Views', { '</pivot>', }); - assert.ok(pivot.$('thead tr:last th:last').hasClass('o_pivot_measure_row_sorted_asc'), + assert.hasClass(pivot.$('thead tr:last th:last'),'o_pivot_measure_row_sorted_asc', "Last thead should be sorted in ascending order"); pivot.destroy(); @@ -1295,17 +1301,17 @@ QUnit.module('Views', { // with no data - $('.o_time_range_menu_button').click(); - $('.o_time_range_menu .o_comparison_checkbox').click(); + testUtils.dom.click($('.o_time_range_menu_button')); + testUtils.dom.click($('.o_time_range_menu .o_comparison_checkbox')); $('.o_time_range_selector').val('today'); - $('.o_time_range_menu .o_apply_range').click(); + testUtils.dom.click($('.o_time_range_menu .o_apply_range')); assert.strictEqual($('.o_pivot p.o_view_nocontent_empty_folder').length, 1); // with data, no row groupby - $('.o_time_range_menu_button').click(); + testUtils.dom.click($('.o_time_range_menu_button')); $('.o_time_range_selector').val('this_month'); - $('.o_time_range_menu .o_apply_range').click(); + testUtils.dom.click($('.o_time_range_menu .o_apply_range')); results = [ "13", "0", "100%", "0", "19", "-100%", "13", "19", "-31.58%" ]; @@ -1313,8 +1319,8 @@ QUnit.module('Views', { // with data, with row groupby - $('.o_pivot .o_pivot_header_cell_closed').eq(2).click(); - $('.o_pivot .o_field_selection a[data-field="product_id"]').click(); + testUtils.dom.click($('.o_pivot .o_pivot_header_cell_closed').eq(2)); + testUtils.dom.click($('.o_pivot .o_field_selection a[data-field="product_id"]')); results = [ "13", "0", "100%", "0", "19", "-100%", "13", "19", "-31.58%" , "12", "0", "100%", "12", "0" , "100%" , @@ -1322,9 +1328,9 @@ QUnit.module('Views', { ]; checkCellValues(results); - $('.o_control_panel button.btn-primary').eq(0).click(); - $('.o_control_panel div.o_pivot_measures_list a[data-field="foo"').click(); - $('.o_control_panel div.o_pivot_measures_list a[data-field="product_id"').click(); + testUtils.pivot.toggleMeasuresDropdown(actionManager.getCurrentController().widget); + testUtils.dom.click($('.o_control_panel div.o_pivot_measures_list a[data-field="foo"]')); + testUtils.dom.click($('.o_control_panel div.o_pivot_measures_list a[data-field="product_id"]')); results = [ "2", "0", "100%", "0", "1", "-100%", "2", "1", "100%" , "1", "0", "100%", "1", "0" , "100%" , @@ -1332,9 +1338,8 @@ QUnit.module('Views', { ]; checkCellValues(results); - $('.o_control_panel button.btn-primary').eq(0).click(); - $('.o_control_panel div.o_pivot_measures_list a[data-field="__count"').click(); - $('.o_control_panel div.o_pivot_measures_list a[data-field="product_id"').click(); + testUtils.dom.click($('.o_control_panel div.o_pivot_measures_list a[data-field="__count"]')); + testUtils.dom.click($('.o_control_panel div.o_pivot_measures_list a[data-field="product_id"]')); results = [ "2", "0", "100%", "0", "2", "-100%", "2", "2", "0%" , "1", "0", "100%", "1", "0" , "100%" , @@ -1342,7 +1347,7 @@ QUnit.module('Views', { ]; checkCellValues(results); - $('.o_pivot .o_pivot_header_cell_opened').eq(0).click(); + testUtils.dom.clickFirst($('.o_pivot .o_pivot_header_cell_opened')); results = [ "2", "2", "0%" , "1", "0", "100%" , @@ -1397,13 +1402,13 @@ QUnit.module('Views', { }); // open time range menu - $('.o_control_panel .o_time_range_menu_button').click(); + testUtils.dom.click($('.o_control_panel .o_time_range_menu_button')); // select 'Today' as range $('.o_control_panel .o_time_range_selector').val('today'); // check checkbox 'Compare To' - $('.o_control_panel .o_time_range_menu .o_comparison_checkbox').click(); + testUtils.dom.click($('.o_control_panel .o_time_range_menu .o_comparison_checkbox')); // Click on 'Apply' button - $('.o_control_panel .o_time_range_menu .o_apply_range').click(); + testUtils.dom.click($('.o_control_panel .o_time_range_menu .o_apply_range')); // the time range menu configuration is by now: Date, Today, checkbox checked, Previous Period // With the data above, the time ranges contain no record. @@ -1413,16 +1418,16 @@ QUnit.module('Views', { assert.ok($('.o_control_panel button.o_pivot_download').prop('disabled')); // open time range menu - $('.o_control_panel .o_time_range_menu_button').click(); + testUtils.dom.click($('.o_control_panel .o_time_range_menu_button')); // select 'This Month' as date range $('.o_control_panel .o_time_range_selector').val('this_month'); // Click on 'Apply' button - $('.o_control_panel .o_time_range_menu .o_apply_range').click(); + testUtils.dom.click($('.o_control_panel .o_time_range_menu .o_apply_range')); // the time range menu configuration is by now: Date, This Month, checkbox checked, Previous Period // With the data above, the time ranges contain some records. // export data. Should execute 'get_file' - $('.o_control_panel button.o_pivot_download').click(); + testUtils.dom.click($('.o_control_panel button.o_pivot_download')); assert.verifySteps([ // Headers @@ -1490,10 +1495,10 @@ QUnit.module('Views', { mockMock = true; // activate 'This Month' and 'Previous Period' in time range menu - $('.o_control_panel .o_time_range_menu_button').click(); + testUtils.dom.click($('.o_control_panel .o_time_range_menu_button')); $('.o_control_panel .o_time_range_selector').val('this_month'); - $('.o_control_panel .o_time_range_menu .o_comparison_checkbox').click(); - $('.o_control_panel .o_time_range_menu .o_apply_range').click(); + testUtils.dom.click($('.o_control_panel .o_time_range_menu .o_comparison_checkbox')); + testUtils.dom.click($('.o_control_panel .o_time_range_menu .o_apply_range')); var results = [ "4", "0", "100%", diff --git a/addons/web/static/tests/views/search_filters_menu_tests.js b/addons/web/static/tests/views/search_filters_menu_tests.js index 429cb6258be..a1a7617b7ad 100644 --- a/addons/web/static/tests/views/search_filters_menu_tests.js +++ b/addons/web/static/tests/views/search_filters_menu_tests.js @@ -8,7 +8,7 @@ function createFiltersMenu(filters, fields, params) { params = params || {}; var target = params.debug ? document.body : $('#qunit-fixture'); var menu = new FiltersMenu(null, filters, fields); - testUtils.addMockEnvironment(menu, params); + testUtils.mock.addMockEnvironment(menu, params); menu.appendTo(target); return menu; } @@ -36,12 +36,12 @@ QUnit.module('FiltersMenu', { assert.expect(4); var filterMenu = createFiltersMenu([], this.fields); - filterMenu.$('span.fa-filter').click(); - assert.strictEqual(filterMenu.$('.dropdown-divider').length, 1); + testUtils.dom.click(filterMenu.$('span.fa-filter')); + assert.containsOnce(filterMenu, '.dropdown-divider'); assert.ok(!filterMenu.$('.dropdown-divider').is(':visible')); - assert.strictEqual(filterMenu.$('.dropdown-divider, .dropdown-item, .dropdown-item-text').length, 3, + assert.containsN(filterMenu, '.dropdown-divider, .dropdown-item, .dropdown-item-text', 3, 'should have 3 elements: a hidden divider, a add custom filter item, a apply button + add condition button'); - assert.strictEqual(filterMenu.$('.o_add_custom_filter.o_closed_menu').length, 1); + assert.containsOnce(filterMenu, '.o_add_custom_filter.o_closed_menu'); filterMenu.destroy(); }); @@ -49,9 +49,9 @@ QUnit.module('FiltersMenu', { assert.expect(2); var filterMenu = createFiltersMenu(this.filters, this.fields); - assert.strictEqual(filterMenu.$('.dropdown-divider, .dropdown-item, .dropdown-item-text').length, 5, + assert.containsN(filterMenu, '.dropdown-divider, .dropdown-item, .dropdown-item-text', 5, 'should have 4 elements: a hidden, separator, a filter, a separator, a add custom filter item, a apply button + add condition button'); - assert.strictEqual(filterMenu.$('.o_add_custom_filter.o_closed_menu').length, 1); + assert.containsOnce(filterMenu, '.o_add_custom_filter.o_closed_menu'); filterMenu.destroy(); }); @@ -60,12 +60,12 @@ QUnit.module('FiltersMenu', { var filterMenu = createFiltersMenu([], this.fields); // open menu dropdown - filterMenu.$('span.fa-filter').click(); + testUtils.dom.click(filterMenu.$('span.fa-filter')); // open add custom filter submenu - filterMenu.$('.o_add_custom_filter').click(); - assert.ok(filterMenu.$('.o_add_custom_filter').hasClass('o_open_menu')); + testUtils.dom.click(filterMenu.$('.o_add_custom_filter')); + assert.hasClass(filterMenu.$('.o_add_custom_filter'), 'o_open_menu'); assert.ok(filterMenu.$('.o_add_filter_menu').is(':visible')); - assert.strictEqual(filterMenu.$('.dropdown-divider, .dropdown-item, .dropdown-item-text').length, 4, + assert.containsN(filterMenu, '.dropdown-divider, .dropdown-item, .dropdown-item-text', 4, 'should have 3 elements: a hidden divider, a add custom filter item, a proposition, a apply button + add condition button'); filterMenu.destroy(); @@ -76,15 +76,15 @@ QUnit.module('FiltersMenu', { var filterMenu = createFiltersMenu([], this.fields); // open menu dropdown and custom filter submenu - filterMenu.$('span.fa-filter').click(); - filterMenu.$('.o_add_custom_filter').click(); + testUtils.dom.click(filterMenu.$('span.fa-filter')); + testUtils.dom.click(filterMenu.$('.o_add_custom_filter')); // remove the current unique proposition - filterMenu.$('.o_searchview_extended_delete_prop').click(); + testUtils.dom.click(filterMenu.$('.o_searchview_extended_delete_prop')); assert.ok(filterMenu.$('.o_apply_filter').attr('disabled')); - assert.strictEqual(filterMenu.$('.dropdown-divider, .dropdown-item, .dropdown-item-text').length, 3, + assert.containsN(filterMenu, '.dropdown-divider, .dropdown-item, .dropdown-item-text', 3, 'should have 3 elements: a hidden separator, a add custom filter item, a apply button + add condition button'); filterMenu.destroy(); @@ -96,12 +96,12 @@ QUnit.module('FiltersMenu', { var filterMenu = createFiltersMenu([], this.fields); // open menu dropdown and custom filter submenu, remove existing prop - filterMenu.$('span.fa-filter').click(); - filterMenu.$('.o_add_custom_filter').click(); - filterMenu.$('.o_searchview_extended_delete_prop').click(); + testUtils.dom.click(filterMenu.$('span.fa-filter')); + testUtils.dom.click(filterMenu.$('.o_add_custom_filter')); + testUtils.dom.click(filterMenu.$('.o_searchview_extended_delete_prop')); // read a proposition - filterMenu.$('.o_add_condition').click(); + testUtils.dom.click(filterMenu.$('.o_add_condition')); assert.ok(!filterMenu.$('.o_apply_filter').attr('disabled')); @@ -115,15 +115,15 @@ QUnit.module('FiltersMenu', { var filterMenu = createFiltersMenu([], this.fields); // open menu dropdown and custom filter submenu, remove existing prop - filterMenu.$('span.fa-filter').click(); - filterMenu.$('.o_add_custom_filter').click(); + testUtils.dom.click(filterMenu.$('span.fa-filter')); + testUtils.dom.click(filterMenu.$('.o_add_custom_filter')); // click on apply to activate filter - filterMenu.$('.o_apply_filter').click(); + testUtils.dom.click(filterMenu.$('.o_apply_filter')); - assert.ok(filterMenu.$('.o_add_custom_filter').hasClass('o_closed_menu')); - assert.strictEqual(filterMenu.$('.o_filter_condition').length, 0); - assert.strictEqual(filterMenu.$('.dropdown-divider:visible').length, 1, + assert.hasClass(filterMenu.$('.o_add_custom_filter'), 'o_closed_menu'); + assert.containsNone(filterMenu, '.o_filter_condition'); + assert.containsOnce(filterMenu, '.dropdown-divider:visible', 'there should be a separator between filters and add custom filter menu'); filterMenu.destroy(); @@ -152,21 +152,21 @@ QUnit.module('FiltersMenu', { }); // open menu dropdown - filterMenu.$('span.fa-filter').click(); + testUtils.dom.click(filterMenu.$('span.fa-filter')); - assert.strictEqual(filterMenu.$('.o_menu_item ul').length, 0, + assert.containsNone(filterMenu, '.o_menu_item ul', "there should not be a sub menu item list"); // open date sub menu - filterMenu.$('.o_submenu_switcher').click(); - assert.strictEqual(filterMenu.$('.o_menu_item ul').length, 1, + testUtils.dom.click(filterMenu.$('.o_submenu_switcher')); + assert.containsOnce(filterMenu, '.o_menu_item ul', "there should be a sub menu item list"); // click on This Quarter option - assert.notOk(filterMenu.$('.o_menu_item li[data-option_id="this_quarter"] .dropdown-item').hasClass('selected'), + assert.doesNotHaveClass(filterMenu.$('.o_menu_item li[data-option_id="this_quarter"] .dropdown-item'), 'selected', "menu item should not be selected"); - filterMenu.$('.o_menu_item li[data-option_id="this_quarter"] a').click(); - assert.ok(filterMenu.$('.o_menu_item li[data-option_id="this_quarter"] .dropdown-item').hasClass('selected'), + testUtils.dom.click(filterMenu.$('.o_menu_item li[data-option_id="this_quarter"] a')); + assert.hasClass(filterMenu.$('.o_menu_item li[data-option_id="this_quarter"] .dropdown-item'),'selected', "menu item should be selected"); filterMenu.destroy(); diff --git a/addons/web/static/tests/views/search_groupby_menu_tests.js b/addons/web/static/tests/views/search_groupby_menu_tests.js index b3585dbc3db..63967f57e86 100644 --- a/addons/web/static/tests/views/search_groupby_menu_tests.js +++ b/addons/web/static/tests/views/search_groupby_menu_tests.js @@ -8,7 +8,7 @@ function createGroupByMenu(groupbys, fields, params) { params = params || {}; var target = params.debug ? document.body : $('#qunit-fixture'); var menu = new GroupByMenu(null, groupbys, fields); - testUtils.addMockEnvironment(menu, params); + testUtils.mock.addMockEnvironment(menu, params); menu.appendTo(target); return menu; } @@ -34,8 +34,8 @@ QUnit.module('GroupByMenu', { assert.expect(2); var groupByMenu = createGroupByMenu(this.groupbys, this.fields); - groupByMenu.$('button:first').click(); - assert.strictEqual(groupByMenu.$('.dropdown-divider, .dropdown-item, .dropdown-item-text').length, 2, 'should have 2 elements'); + testUtils.dom.click(groupByMenu.$('button:first')); + assert.containsN(groupByMenu, '.dropdown-divider, .dropdown-item, .dropdown-item-text', 2, 'should have 2 elements'); assert.strictEqual(groupByMenu.$('.dropdown-divider, .dropdown-item, .dropdown-item-text').eq(1).text().trim(), 'some group by', 'should have proper filter name'); groupByMenu.destroy(); @@ -45,8 +45,8 @@ QUnit.module('GroupByMenu', { assert.expect(1); var groupByMenu = createGroupByMenu([], {}); - groupByMenu.$('button:first').click(); - assert.strictEqual(groupByMenu.$('.dropdown-divider, .dropdown-item, .dropdown-item-text').length, 0, 'should have 0 element'); + testUtils.dom.click(groupByMenu.$('button:first')); + assert.containsNone(groupByMenu, '.dropdown-divider, .dropdown-item, .dropdown-item-text', 'should have 0 element'); groupByMenu.destroy(); }); @@ -57,8 +57,8 @@ QUnit.module('GroupByMenu', { [], {fieldname: {sortable: true, string: 'Super Date', type: 'date', isDate: true}} ); - groupByMenu.$('button:first').click(); - assert.strictEqual(groupByMenu.$('.dropdown-divider, .dropdown-item, .dropdown-item-text').length, 1, 'should have 1 element'); + testUtils.dom.click(groupByMenu.$('button:first')); + assert.containsOnce(groupByMenu, '.dropdown-divider, .dropdown-item, .dropdown-item-text', 'should have 1 element'); groupByMenu.destroy(); }); @@ -66,10 +66,10 @@ QUnit.module('GroupByMenu', { assert.expect(2); var groupByMenu = createGroupByMenu([], {fieldname: {sortable: true, string: 'Super Date', type: 'date', isDate: true}}); - groupByMenu.$('button:first').click(); + testUtils.dom.click(groupByMenu.$('button:first')); var selector = groupByMenu.$('select.o_group_selector'); assert.ok(!selector.is(":visible"), 'should be invisible'); - groupByMenu.$('.o_add_custom_group').click(); + testUtils.dom.click(groupByMenu.$('.o_add_custom_group')); selector = groupByMenu.$('select.o_group_selector'); assert.ok(selector.is(":visible"), 'should be visible'); groupByMenu.destroy(); @@ -84,12 +84,12 @@ QUnit.module('GroupByMenu', { fieldName: {sortable: true, name: 'candlelight', string: 'Candlelight', type: 'boolean'}, } ); - groupByMenu.$('button:first').click(); - groupByMenu.$('.o_add_custom_group').click(); + testUtils.dom.click(groupByMenu.$('button:first')); + testUtils.dom.click(groupByMenu.$('.o_add_custom_group')); assert.strictEqual(groupByMenu.$('select').val(), 'fieldName', 'the select value should be "fieldName"'); - groupByMenu.$('button.o_apply_group').click(); - assert.strictEqual(groupByMenu.$('.o_menu_item > .dropdown-item.selected').length, 1, 'there should be a groupby selected'); + testUtils.dom.click(groupByMenu.$('button.o_apply_group')); + assert.containsOnce(groupByMenu, '.o_menu_item > .dropdown-item.selected', 'there should be a groupby selected'); groupByMenu.destroy(); }); @@ -113,10 +113,10 @@ QUnit.module('GroupByMenu', { }, }, }); - groupByMenu.$('button:first').click(); - assert.ok(!groupByMenu.$('.o_menu_item:first > .dropdown-item').hasClass('selected')); - groupByMenu.$('.o_menu_item a').first().click(); - assert.ok(groupByMenu.$('.o_menu_item:first > .dropdown-item').hasClass('selected')); + testUtils.dom.click(groupByMenu.$('button:first')); + assert.doesNotHaveClass(groupByMenu.$('.o_menu_item:first > .dropdown-item'), 'selected'); + testUtils.dom.click(groupByMenu.$('.o_menu_item a').first()); + assert.hasClass(groupByMenu.$('.o_menu_item:first > .dropdown-item'), 'selected'); assert.ok(groupByMenu.$('.o_menu_item:first').is(':visible'), 'group by filter should still be visible'); groupByMenu.destroy(); @@ -127,10 +127,10 @@ QUnit.module('GroupByMenu', { var groupByMenu = createGroupByMenu(this.groupbys, {fieldname: {sortable: true, string: 'Super Date', type: 'date', isDate: true}}); - groupByMenu.$('button:first').click(); - assert.ok(!groupByMenu.$('.o_menu_item:first > .dropdown-item').hasClass('selected')); - groupByMenu.$('.o_menu_item a').first().click(); - assert.ok(!groupByMenu.$('.o_menu_item:first > .dropdown-item').hasClass('selected')); + testUtils.dom.click(groupByMenu.$('button:first')); + assert.doesNotHaveClass(groupByMenu.$('.o_menu_item:first > .dropdown-item'), 'selected'); + testUtils.dom.click(groupByMenu.$('.o_menu_item a').first()); + assert.doesNotHaveClass(groupByMenu.$('.o_menu_item:first > .dropdown-item'), 'selected'); assert.ok(groupByMenu.$('.o_menu_item:first').is(':visible'), 'group by filter should still be visible'); assert.ok(groupByMenu.$('.o_item_option').length, 5); @@ -143,11 +143,12 @@ QUnit.module('GroupByMenu', { var groupByMenu = createGroupByMenu(this.groupbys, {fieldname: {sortable: true, string: 'Super Date', type: 'date', isDate: true}} ); + testUtils.dom.click(groupByMenu.$('.o_dropdown_toggler_btn')); groupByMenu.$el.click(function (event) { // we do not want a click to get out and change the url, for example throw new Error('No click should get out of the groupby menu'); }); - groupByMenu.$('.o_menu_item a').first().click(); + testUtils.dom.click(groupByMenu.$('.o_menu_item a').first()); groupByMenu.destroy(); }); diff --git a/addons/web/static/tests/views/search_view_tests.js b/addons/web/static/tests/views/search_view_tests.js index 3ce961c483c..be657ec46ce 100644 --- a/addons/web/static/tests/views/search_view_tests.js +++ b/addons/web/static/tests/views/search_view_tests.js @@ -4,7 +4,7 @@ odoo.define('web.search_view_tests', function (require) { var FormView = require('web.FormView'); var testUtils = require('web.test_utils'); var createActionManager = testUtils.createActionManager; -var patchDate = testUtils.patchDate; +var patchDate = testUtils.mock.patchDate; var createView = testUtils.createView; QUnit.module('Search View', { @@ -277,8 +277,8 @@ QUnit.module('Search View', { }); actionManager.doAction(1); - $('span.fa-bars').prev().click(); - $('.o_menu_item a').click(); + testUtils.dom.click($('.o_dropdown_toggler_btn:contains(Group By)')); + testUtils.dom.click($('.o_menu_item a')); assert.strictEqual($('.o_searchview .o_searchview_facet .o_facet_values span').text().trim(), 'candle', 'should have a facet with candle name'); actionManager.destroy(); @@ -294,11 +294,11 @@ QUnit.module('Search View', { }); actionManager.doAction(1); - $('span.fa-bars').prev().click(); - $('.o_menu_item a').click(); + testUtils.dom.click($('.o_dropdown_toggler_btn:contains(Group By)')); + testUtils.dom.click($('.o_menu_item a')); assert.strictEqual($('.o_searchview .o_searchview_facet .o_facet_values span').text().trim(), 'candle', 'should have a facet with candle name'); - $('.o_facet_remove:first').click(); + testUtils.dom.click($('.o_facet_remove:first')); assert.strictEqual($('.o_searchview .o_searchview_facet .o_facet_values span').length, 0, 'there should be no facet'); actionManager.destroy(); @@ -314,16 +314,16 @@ QUnit.module('Search View', { }); actionManager.doAction(2); - $('span.fa-bars').click(); - $('.o_submenu_switcher').click(); + testUtils.dom.click($('span.fa-bars')); + testUtils.dom.click($('.o_submenu_switcher')); // Don't forget there is a hidden li.divider element at first place among children - $('.o_item_option:nth-child(2)').click(); + testUtils.dom.click($('.o_item_option:nth-child(2)')); assert.strictEqual($('.o_searchview .o_searchview_facet .o_facet_values span').length, 1, 'should have a facet'); - $('.o_item_option:nth-child(3)').click(); + testUtils.dom.click($('.o_item_option:nth-child(3)')); assert.strictEqual($('.o_searchview .o_searchview_facet .o_facet_values span').length, 1, 'should have a facet'); - $('.o_item_option:nth-child(3)').click(); + testUtils.dom.click($('.o_item_option:nth-child(3)')); assert.strictEqual($('.o_searchview .o_searchview_facet .o_facet_values span').length, 0, 'should have no facet'); actionManager.destroy(); @@ -339,9 +339,9 @@ QUnit.module('Search View', { }); actionManager.doAction(3); - $('span.fa-bars').click(); - $('.o_menu_item:first').click(); - $('.o_menu_item:first').click(); + testUtils.dom.click($('span.fa-bars')); + testUtils.dom.click($('.o_menu_item:first')); + testUtils.dom.click($('.o_menu_item:first')); assert.strictEqual($('.o_searchview .o_searchview_facet .o_facet_values span').length, 0, 'should have a facet'); actionManager.destroy(); @@ -357,15 +357,15 @@ QUnit.module('Search View', { archs: this.archs, data: this.data, }); - actionManager.doAction(4); - $('.o_graph_buttons div.o_graph_groupbys_menu > button').click(); - $('.o_graph_buttons div.o_graph_groupbys_menu .o_menu_item').click(); - assert.ok(!$('.o_graph_buttons div.o_graph_groupbys_menu .o_menu_item > .dropdown-item').hasClass('selected'), + testUtils.dom.click($('div.o_graph_groupbys_menu > button')); + testUtils.dom.click($('div.o_graph_groupbys_menu .o_menu_item').eq(1)); + testUtils.dom.click($('div.o_graph_groupbys_menu .o_menu_item .o_item_option > .dropdown-item').first()); + assert.doesNotHaveClass($('div.o_graph_groupbys_menu .o_menu_item > .dropdown-item').eq(1), 'selected', 'groupby should be unselected'); - $('.o_search_options button span.fa-filter').click(); - $('.o_filters_menu .o_menu_item a').click(); - assert.ok(!$('.o_graph_buttons div.o_graph_groupbys_menu .o_menu_item > .dropdown-item').hasClass('selected'), + testUtils.dom.click($('.o_search_options button span.fa-filter')); + testUtils.dom.click($('.o_filters_menu .o_menu_item a').first()); + assert.doesNotHaveClass($('div.o_graph_groupbys_menu .o_menu_item > .dropdown-item').eq(1), 'selected', 'groupby should be still unselected'); actionManager.destroy(); }); @@ -395,33 +395,33 @@ QUnit.module('Search View', { actionManager.doAction(5); // open menu 'Group By' - $('.o_search_options .fa-bars').click(); + testUtils.dom.click($('.o_search_options .fa-bars')); // Activate the groupby 'Date' - $('.o_group_by_menu .o_menu_item').click(); + testUtils.dom.click($('.o_group_by_menu .o_menu_item')); // // select option 'day' - $('.o_group_by_menu .o_menu_item .o_item_option[data-option_id="day"]').click(); + testUtils.dom.click($('.o_group_by_menu .o_menu_item .o_item_option[data-option_id="day"]')); assert.strictEqual($('div.o_facet_values span').text().trim(),'Date: Day'); assert.strictEqual($('.o_content tr.o_group_header').length, 5); // // select option 'month' - $('.o_group_by_menu .o_menu_item .o_item_option[data-option_id="month"]').click(); + testUtils.dom.click($('.o_group_by_menu .o_menu_item .o_item_option[data-option_id="month"]')); // // data should be grouped by the field 'Date' using the interval 'month' assert.strictEqual($('div.o_facet_values span').text().trim(),'Date: Month'); assert.strictEqual($('.o_content tr.o_group_header').length, 3); // // deactivate option 'month' - $('.o_group_by_menu .o_menu_item .o_item_option[data-option_id="month"]').click(); + testUtils.dom.click($('.o_group_by_menu .o_menu_item .o_item_option[data-option_id="month"]')); // // no groupby is applied assert.strictEqual($('div.o_facet_values span').length, 0); // // open 'Add custom Groupby' menu - $('.o_group_by_menu .o_add_custom_group').click(); + testUtils.dom.click($('.o_group_by_menu .o_add_custom_group')); // // click on 'Apply' button - $('.o_group_by_menu .o_generator_menu button').click(); + testUtils.dom.click($('.o_group_by_menu .o_generator_menu button')); // // data should be grouped by the field 'Birthday' using the interval 'month' assert.strictEqual($('div.o_facet_values span').text().trim(),'Birthday: Month'); assert.strictEqual($('.o_content tr.o_group_header').length, 5); // // open submenu with interval options - $('.o_group_by_menu .o_menu_item .o_submenu_switcher').eq(1).click(); + testUtils.dom.click($('.o_group_by_menu .o_menu_item .o_submenu_switcher').eq(1)); // // select option 'year' - $('.o_group_by_menu .o_menu_item .o_item_option').eq(9).click(); + testUtils.dom.click($('.o_group_by_menu .o_menu_item .o_item_option').eq(9)); // // data should be grouped by the field 'Birthday' using the interval 'year' assert.strictEqual($('div.o_facet_values span').text().trim(),'Birthday: Year'); assert.strictEqual($('.o_content tr.o_group_header').length, 4); @@ -439,23 +439,23 @@ QUnit.module('Search View', { actionManager.doAction(7); // open menu 'Group By' - $('span.fa-bars').click(); + testUtils.dom.click($('span.fa-bars')); // open options menu - $('.o_group_by_menu .o_menu_item a:first').click(); + testUtils.dom.click($('.o_group_by_menu .o_menu_item a:first')); // activate groupby with 'day' option - $('.o_group_by_menu .o_menu_item .o_item_option[data-option_id="day"]').click(); + testUtils.dom.click($('.o_group_by_menu .o_menu_item .o_item_option[data-option_id="day"]')); // activate the second groupby - $('.o_group_by_menu .o_menu_item > a').eq(1).click(); + testUtils.dom.click($('.o_group_by_menu .o_menu_item > a').eq(1)); assert.strictEqual($('.o_group_by_menu .o_menu_item').length, 2); - assert.ok($('.o_group_by_menu .o_menu_item > .dropdown-item').hasClass('selected')); + assert.strictEqual($('.o_group_by_menu .o_menu_item > .dropdown-item.selected').length, 2); // deactivate second groupby - $('.o_group_by_menu .o_menu_item > a').eq(1).click(); - assert.ok($('.o_group_by_menu .o_menu_item > .dropdown-item').eq(0).hasClass('selected')); - assert.ok(!$('.o_group_by_menu .o_menu_item > .dropdown-item').eq(1).hasClass('selected')); + testUtils.dom.click($('.o_group_by_menu .o_menu_item > a').eq(1)); + assert.hasClass($('.o_group_by_menu .o_menu_item > .dropdown-item').eq(0), 'selected'); + assert.doesNotHaveClass($('.o_group_by_menu .o_menu_item > .dropdown-item').eq(1), 'selected'); // remove facet - $('.o_facet_remove').click(); - assert.ok(!$('.o_group_by_menu .o_menu_item > .dropdown-item').eq(0).hasClass('selected')); - assert.ok(!$('.o_group_by_menu .o_menu_item > .dropdown-item').eq(1).hasClass('selected')); + testUtils.dom.click($('.o_facet_remove')); + assert.doesNotHaveClass($('.o_group_by_menu .o_menu_item > .dropdown-item').eq(0), 'selected'); + assert.doesNotHaveClass($('.o_group_by_menu .o_menu_item > .dropdown-item').eq(1), 'selected'); actionManager.destroy(); }); @@ -471,9 +471,9 @@ QUnit.module('Search View', { }); actionManager.doAction(1); - $('span.fa-filter').click(); - $('.o_add_custom_filter').click(); - $('.o_apply_filter').click(); + testUtils.dom.click($('span.fa-filter')); + testUtils.dom.click($('.o_add_custom_filter')); + testUtils.dom.click($('.o_apply_filter')); assert.strictEqual($('.o_searchview .o_searchview_facet .o_facet_values span').text().trim(), 'ID is \"0\"', 'should have a facet with candle name'); actionManager.destroy(); @@ -489,10 +489,10 @@ QUnit.module('Search View', { }); actionManager.doAction(1); - $('span.fa-filter').click(); - $('.o_add_custom_filter').click(); - $('.o_apply_filter').click(); - $('.o_menu_item').click(); + testUtils.dom.click($('span.fa-filter')); + testUtils.dom.click($('.o_add_custom_filter')); + testUtils.dom.click($('.o_apply_filter')); + testUtils.dom.click($('.o_menu_item')); assert.strictEqual($('.o_searchview .o_searchview_facet .o_facet_values span').length, 0, 'no facet should be in the search view'); actionManager.destroy(); @@ -532,9 +532,9 @@ QUnit.module('Search View', { actionManager.doAction(5); // open menu 'Filter' - $('.o_search_options .fa-filter').click(); + testUtils.dom.click($('.o_search_options .fa-filter')); // open menu options - $('.o_menu_item').click(); + testUtils.dom.click($('.o_menu_item')); var periodOptions = $('.o_menu_item .o_item_option').map(function () { return $(this).data('option_id'); @@ -542,19 +542,19 @@ QUnit.module('Search View', { assert.deepEqual(periodOptions, this.periodOptions, "13 period options should be available:"); - $('.o_menu_item .o_item_option[data-option_id="last_7_days"]').click(); - $('.o_menu_item .o_item_option[data-option_id="last_30_days"]').click(); - $('.o_menu_item .o_item_option[data-option_id="last_365_days"]').click(); - $('.o_menu_item .o_item_option[data-option_id="today"]').click(); - $('.o_menu_item .o_item_option[data-option_id="this_week"]').click(); - $('.o_menu_item .o_item_option[data-option_id="this_month"]').click(); - $('.o_menu_item .o_item_option[data-option_id="this_quarter"]').click(); - $('.o_menu_item .o_item_option[data-option_id="this_year"]').click(); - $('.o_menu_item .o_item_option[data-option_id="yesterday"]').click(); - $('.o_menu_item .o_item_option[data-option_id="last_week"]').click(); - $('.o_menu_item .o_item_option[data-option_id="last_month"]').click(); - $('.o_menu_item .o_item_option[data-option_id="last_quarter"]').click(); - $('.o_menu_item .o_item_option[data-option_id="last_year"]').click(); + testUtils.dom.click($('.o_menu_item .o_item_option[data-option_id="last_7_days"]')); + testUtils.dom.click($('.o_menu_item .o_item_option[data-option_id="last_30_days"]')); + testUtils.dom.click($('.o_menu_item .o_item_option[data-option_id="last_365_days"]')); + testUtils.dom.click($('.o_menu_item .o_item_option[data-option_id="today"]')); + testUtils.dom.click($('.o_menu_item .o_item_option[data-option_id="this_week"]')); + testUtils.dom.click($('.o_menu_item .o_item_option[data-option_id="this_month"]')); + testUtils.dom.click($('.o_menu_item .o_item_option[data-option_id="this_quarter"]')); + testUtils.dom.click($('.o_menu_item .o_item_option[data-option_id="this_year"]')); + testUtils.dom.click($('.o_menu_item .o_item_option[data-option_id="yesterday"]')); + testUtils.dom.click($('.o_menu_item .o_item_option[data-option_id="last_week"]')); + testUtils.dom.click($('.o_menu_item .o_item_option[data-option_id="last_month"]')); + testUtils.dom.click($('.o_menu_item .o_item_option[data-option_id="last_quarter"]')); + testUtils.dom.click($('.o_menu_item .o_item_option[data-option_id="last_year"]')); actionManager.destroy(); window.Date = RealDate; @@ -583,12 +583,12 @@ QUnit.module('Search View', { }); actionManager.doAction(6); - $('span.fa-filter').click(); - $('.o_filters_menu .o_menu_item a').click(); - $('.o_item_option[data-option_id="today"]').click(); - $('span.fa-star').click(); - $('.o_favorites_menu .o_save_search a').click(); - $('.o_favorites_menu .o_save_name button').click(); + testUtils.dom.click($('span.fa-filter')); + testUtils.dom.click($('.o_filters_menu .o_menu_item a')); + testUtils.dom.click($('.o_item_option[data-option_id="today"]')); + testUtils.dom.click($('span.fa-star')); + testUtils.dom.click($('.o_favorites_menu .o_save_search')); + testUtils.dom.click($('.o_favorites_menu .o_save_name button')); actionManager.destroy(); }); @@ -602,7 +602,7 @@ QUnit.module('Search View', { }); actionManager.doAction(8); - $('span.fa-filter').click(); + testUtils.dom.click($('span.fa-filter')); assert.strictEqual($('.o_filters_menu .o_menu_item').length, 11); for (var i = 0; i < 11; i++) { assert.strictEqual($('.o_filters_menu .o_menu_item').eq(i).text().trim(), (i+1).toString()); @@ -646,13 +646,13 @@ QUnit.module('Search View', { "Date Field Groupby: Day", "There should be a filter facet with label 'Date Field Groupby: Day'"); - $('button .fa-filter').click(); - $('.o_filters_menu .o_menu_item').eq(0).click(); + testUtils.dom.click($('button .fa-filter')); + testUtils.dom.click($('.o_filters_menu .o_menu_item').eq(0)); assert.strictEqual($('.o_filters_menu .o_item_option a.selected').text().trim(), "This Month", "The item 'This Month' should be selected in the filters menu"); - $('button .fa-bars').click(); - $('.o_group_by_menu .o_menu_item').eq(0).click(); + testUtils.dom.click($('button .fa-bars')); + testUtils.dom.click($('.o_group_by_menu .o_menu_item').eq(0)); assert.strictEqual($('.o_group_by_menu .o_item_option a.selected').text().trim(), "Day", "The item 'Day' should be selected in the groupby menu"); @@ -686,9 +686,9 @@ QUnit.module('Search View', { assert.strictEqual($('.o_searchview_input_container .o_facet_values span').text().trim(), "a"); - $('button .fa-star').click(); - $('.o_favorites_menu a.o_save_search').click(); - $('.o_favorites_menu div.o_save_name button').click(); + testUtils.dom.click($('button .fa-star')); + testUtils.dom.click($('.o_favorites_menu a.o_save_search')); + testUtils.dom.click($('.o_favorites_menu div.o_save_name button')); actionManager.destroy(); }); @@ -705,19 +705,19 @@ QUnit.module('Search View', { actionManager.doAction(1); // check that the fifth dropdown is the time range menu and is hidden - assert.ok($('.btn-group.o_dropdown').eq(4).hasClass('o_hidden')); - assert.ok($('.btn-group.o_dropdown').eq(4).children().eq(1).hasClass('o_time_range_menu')); + assert.isNotVisible($('.btn-group.o_dropdown').eq(4)); + assert.hasClass($('.btn-group.o_dropdown').eq(4).children().eq(1), 'o_time_range_menu'); // check if search view has no facets assert.strictEqual($('.o_facet_values').length, 0); // activate groupby - $('button .fa-bars').click(); - $('.o_menu_item a').eq(0).click(); + testUtils.dom.click($('button .fa-bars')); + testUtils.dom.click($('.o_menu_item a').eq(0)); // check that there is a facet assert.strictEqual($('div.o_facet_values').length, 1); // check that the fifth dropdown is the time range menu and is still hidden - assert.ok($('.btn-group.o_dropdown').eq(4).hasClass('o_hidden')); - assert.ok($('.btn-group.o_dropdown').eq(4).children().eq(1).hasClass('o_time_range_menu')); + assert.isNotVisible($('.btn-group.o_dropdown').eq(4)); + assert.hasClass($('.btn-group.o_dropdown').eq(4).children().eq(1), 'o_time_range_menu'); actionManager.destroy(); }); @@ -775,18 +775,18 @@ QUnit.module('Search View', { periodOptionText = $(this).text().trim(); periodOptionValue = $(this).val(); // opens time range menu dropdown - $('.o_time_range_menu_button').click(); + testUtils.dom.click($('.o_time_range_menu_button')); var $timeRangeMenu = $('.o_time_range_menu'); // comparison is not checked by default if (!$timeRangeMenu.find('.o_comparison_checkbox').is(':checked')) { - $timeRangeMenu.find('.o_comparison_checkbox').click(); + testUtils.dom.click($timeRangeMenu.find('.o_comparison_checkbox')); assert.strictEqual($('.o_comparison_time_range_selector:visible').length, 1, "Comparison has to be checked (only at the first time)"); } // select one period option to test it $timeRangeMenu.find('.o_time_range_selector').val(periodOptionValue); // apply - $timeRangeMenu.find('.o_apply_range').click(); + testUtils.dom.click($timeRangeMenu.find('.o_apply_range')); assert.strictEqual($('.o_facet_values').text().trim(), "Date: " + periodOptionText + " / Previous Period", "Facet should be updated with this period: " + periodOptionValue); @@ -857,31 +857,31 @@ QUnit.module('Search View', { res_id: 1, }); - form.$buttons.find('.o_form_button_edit').click(); - var $dropdown = form.$('.o_field_many2one input').autocomplete('widget'); - form.$('.o_field_many2one input').click(); - $dropdown.find('.o_m2o_dropdown_option:contains(Search)').mouseenter().click(); // Open Search More + testUtils.form.clickEdit(form); + + testUtils.fields.many2one.clickOpenDropdown('bar'); + testUtils.fields.many2one.clickItem('bar','Search'); assert.strictEqual($('tr.o_data_row').length, 9, "should display 9 records"); - $('button:contains(Filters)').click(); - $('.o_add_custom_filter:visible').click(); // Add a custom filter, datetime field is selected + testUtils.dom.click($('button:contains(Filters)')); + testUtils.dom.click($('.o_add_custom_filter:visible')); assert.strictEqual($('.o_filter_condition select.o_searchview_extended_prop_field').val(), 'date_field', "date field should be selected"); - $('.o_apply_filter').click(); + testUtils.dom.click($('.o_apply_filter')); assert.strictEqual($('tr.o_data_row').length, 0, "should display 0 records"); // Save this search - testUtils.intercept(form, 'create_filter', function (event) { + testUtils.mock.intercept(form, 'create_filter', function (event) { assert.strictEqual(event.data.filter.name, "Awesome Test Customer Filter", "filter name should be correct"); }); - $('button:contains(Favorites)').click(); - $('.o_save_search').click(); + testUtils.dom.click($('button:contains(Favorites)')); + testUtils.dom.click($('.o_save_search')); var filterNameInput = $('.o_save_name .o_input[type="text"]:visible'); assert.strictEqual(filterNameInput.length, 1, "should display an input field for the filter name"); - filterNameInput.val('Awesome Test Customer Filter').trigger('input'); - $('.o_save_name button').click(); + testUtils.fields.editInput(filterNameInput, 'Awesome Test Customer Filter'); + testUtils.dom.click($('.o_save_name button')); form.destroy(); }); diff --git a/addons/web/static/tests/views/view_dialogs_tests.js b/addons/web/static/tests/views/view_dialogs_tests.js index 372edbc0f24..8898e520618 100644 --- a/addons/web/static/tests/views/view_dialogs_tests.js +++ b/addons/web/static/tests/views/view_dialogs_tests.js @@ -60,7 +60,7 @@ QUnit.module('Views', { function createParent(params) { var widget = new Widget(); - testUtils.addMockEnvironment(widget, params); + testUtils.mock.addMockEnvironment(widget, params); return widget; } @@ -80,7 +80,7 @@ QUnit.module('Views', { }, }); - testUtils.intercept(parent, 'env_updated', function () { + testUtils.mock.intercept(parent, 'env_updated', function () { throw new Error("The environment should not be propagated to the action manager"); }); @@ -121,7 +121,7 @@ QUnit.module('Views', { assert.strictEqual($('.modal button.btn-primary').length, 1, "should have 1 buttons in modal"); - $('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click($('.o_field_x2many_list_row_add a')); $('input.o_input').trigger($.Event('keydown', { which: $.ui.keyCode.ESCAPE, keyCode: $.ui.keyCode.ESCAPE, @@ -199,8 +199,8 @@ QUnit.module('Views', { }, }).open(); - dialog.$('.o_searchview_facet:contains(groupby_bar) .o_facet_remove').click(); - dialog.$('.o_searchview_facet .o_facet_remove').click(); + testUtils.dom.click(dialog.$('.o_searchview_facet:contains(groupby_bar) .o_facet_remove')); + testUtils.dom.click(dialog.$('.o_searchview_facet .o_facet_remove')); parent.destroy(); }); @@ -264,7 +264,7 @@ QUnit.module('Views', { }).open(); // click on the first row to see if the list is editable - dialog.$('.o_list_view tbody tr:first td:not(.o_list_record_selector):first').click(); + testUtils.dom.click(dialog.$('.o_list_view tbody tr:first td:not(.o_list_record_selector):first')); assert.equal(dialog.$('.o_list_view tbody tr:first td:not(.o_list_record_selector):first input').length, 0, "list view should not be editable in a SelectCreateDialog"); @@ -329,17 +329,17 @@ QUnit.module('Views', { }, }); - form.$buttons.find('.o_form_button_edit').click(); - form.$('.o_field_x2many_list_row_add a').click(); - form.$('.o_field_widget .o_field_many2one[name=instrument] input').click(); - $('ul.ui-autocomplete.ui-front.ui-menu.ui-widget.ui-widget-content li.o_m2o_dropdown_option').first().click(); + testUtils.form.clickEdit(form); + testUtils.dom.click(form.$('.o_field_x2many_list_row_add a')); + testUtils.dom.click(form.$('.o_field_widget .o_field_many2one[name=instrument] input')); + testUtils.dom.click($('ul.ui-autocomplete.ui-front.ui-menu.ui-widget.ui-widget-content li.o_m2o_dropdown_option').first()); var $modal = $('.modal-lg'); assert.equal($modal.length, 1, 'There should be one modal'); - $modal.find('.o_field_x2many_list_row_add a').click(); + testUtils.dom.click($modal.find('.o_field_x2many_list_row_add a')); var $modals = $('.modal-lg'); @@ -347,9 +347,9 @@ QUnit.module('Views', { 'There should be two modals'); var $second_modal = $modals.not($modal); - $second_modal.find('.o_list_view.table.table-sm.table-striped.o_list_view_ungrouped .o_data_row input[type=checkbox]').click(); + testUtils.dom.click($second_modal.find('.o_list_view.table.table-sm.table-striped.o_list_view_ungrouped .o_data_row input[type=checkbox]')); - $second_modal.find('.o_select_button').click(); + testUtils.dom.click($second_modal.find('.o_select_button')); $modal = $('.modal-lg'); @@ -359,7 +359,7 @@ QUnit.module('Views', { assert.equal($modal.find('.o_data_cell').text(), 'Awsome', 'There should be one item in the list of the modal'); - $modal.find('.btn.btn-primary').click(); + testUtils.dom.click($modal.find('.btn.btn-primary')); form.destroy(); }); @@ -422,7 +422,7 @@ QUnit.module('Views', { QUnit.test('SelectCreateDialog: save current search', function (assert) { assert.expect(4); - testUtils.patch(ListController, { + testUtils.mock.patch(ListController, { getContext: function () { return { shouldBeInFilterContext: true, @@ -459,21 +459,23 @@ QUnit.module('Views', { res_model: 'partner', }).open(); - assert.strictEqual(dialog.$('.o_data_row').length, 3, + assert.containsN(dialog, '.o_data_row', 3, "should contain 3 records"); // filter on bar - dialog.$('.o_filters_menu a:contains(Bar)').click(); + testUtils.dom.click(dialog.$('.o_dropdown_toggler_btn:contains(Filters)')); + testUtils.dom.click(dialog.$('.o_filters_menu a:contains(Bar)')); - assert.strictEqual(dialog.$('.o_data_row').length, 2, + assert.containsN(dialog, '.o_data_row', 2, "should contain 2 records"); // save filter - dialog.$('.o_save_search a').click(); // toggle 'Save current search' + testUtils.dom.click(dialog.$('.o_dropdown_toggler_btn:contains(Favorites)')); + testUtils.dom.click(dialog.$('.o_save_search')); dialog.$('.o_save_name input[type=text]').val('some name'); // name the filter - dialog.$('.o_save_name button').click(); // click on 'Save' + testUtils.dom.click(dialog.$('.o_save_name button')); - testUtils.unpatch(ListController); + testUtils.mock.unpatch(ListController); parent.destroy(); }); }); |
