[FIX] web: fix keyboard related crash in client actions

This commit is contained in:
Vincent Schippefilt
2018-04-16 09:35:33 +02:00
parent 9b2b5eddd4
commit 65d8a082df
4 changed files with 73 additions and 6 deletions
@@ -51,6 +51,11 @@ var AbstractAction = Widget.extend({
canBeRemoved: function () {
return $.when();
},
/**
* Gives the focus to the action
*/
giveFocus: function () {
},
/**
* Renders the buttons to append, in most cases, to the control panel (in
* the bottom left corner). When the action is rendered in a dialog, those
@@ -319,7 +319,9 @@ var InputField = DebouncedField.extend({
|| (ev.data.direction === "right" && (selecting || input.selectionStart !== input.value.length))) {
ev.stopPropagation();
}
if (ev.data.direction ==='next' && this.attrs.modifiersValue.required) {
if (ev.data.direction ==='next' &&
this.attrs.modifiersValue &&
this.attrs.modifiersValue.required) {
if (!this.$input.val()){
this.setInvalidClass();
ev.stopPropagation();
@@ -5,14 +5,15 @@ var ReportClientAction = require('report.client_action');
var AbstractAction = require('web.AbstractAction');
var AbstractStorageService = require('web.AbstractStorageService');
var BasicFields = require('web.basic_fields');
var ControlPanelMixin = require('web.ControlPanelMixin');
var core = require('web.core');
var ListController = require('web.ListController');
var StandaloneFieldManagerMixin = require('web.StandaloneFieldManagerMixin');
var RamStorage = require('web.RamStorage');
var ReportService = require('web.ReportService');
var testUtils = require('web.test_utils');
var Widget = require('web.Widget');
var createActionManager = testUtils.createActionManager;
QUnit.module('ActionManager', {
@@ -3094,6 +3095,64 @@ QUnit.module('ActionManager', {
delete core.action_registry.map.slowAction;
});
QUnit.test('abstract action does not crash on navigation_moves', function (assert) {
assert.expect(1);
var ClientAction = AbstractAction.extend({
});
core.action_registry.add('ClientAction', ClientAction);
var actionManager = createActionManager({
actions: this.actions,
archs: this.archs,
data: this.data,
});
actionManager.doAction('ClientAction');
actionManager.trigger_up('navigation_move', {direction:'down'});
assert.ok(true); // no error so it's good
actionManager.destroy();
delete core.action_registry.ClientAction;
});
QUnit.test('fields in abstract action do not crash on navigation_moves', function (assert) {
assert.expect(1);
var self = this;
// create a client action with 1 input field
var inputWidget;
var ClientAction = AbstractAction.extend(StandaloneFieldManagerMixin,{
init: function() {
this._super.apply(this, arguments);
StandaloneFieldManagerMixin.init.call(this);
},
start: function(){
var _self = this;
return this.model.makeRecord('partner', [{
name: 'display_name',
type: 'char',
}]).then(function (recordID) {
var record = _self.model.get(recordID);
inputWidget = new BasicFields.InputField(_self, 'display_name', record, {mode: 'edit',});
_self._registerWidget(recordID, 'display_name', inputWidget);
inputWidget.appendTo(_self.$el);
});
}
});
core.action_registry.add('ClientAction', ClientAction);
var actionManager = createActionManager({
actions: this.actions,
archs: this.archs,
data: this.data,
});
actionManager.doAction('ClientAction');
inputWidget.$el.trigger($.Event('keydown', {which: $.ui.keyCode.TAB}));
assert.ok(true); // no error so it's good
actionManager.destroy();
delete core.action_registry.ClientAction;
});
});
});
@@ -77,6 +77,7 @@ var createActionManager = function (params) {
var $target = $('#qunit-fixture');
if (params.debug) {
$target = $('body');
$target.addClass('debug');
}
var widget = new Widget();
@@ -733,17 +734,17 @@ function patch (target, props) {
* In Phantomjs, there is a crash when calling window.getSelection
* in order for the tests to work, for the specific test that uses it, replace
* the default window.getSelection by a mock
*
*
* usage:
* QUnit.test('...',function(done){
* var unpatchWindowGetSelection = testUtils.patchWindowGetSelection();
*
*
* // do something that needs to use window.getSelection()
* assert.strictEqual(....);
*
*
* // restore the original function
* unpatchWindowGetSelection();
*
*
* // finish the test
* done();
* })