[REF] pad: adapt code after jQuery update
Part of task 1896658 Co-authored-by: Aaron Bohy <aab@odoo.com> Co-authored-by: Christophe Matthieu <chm@odoo.com> Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com> Co-authored-by: David Monjoie <dmo@odoo.com> Co-authored-by: Martin Geubelle <mge@odoo.com> Co-authored-by: svs-odoo <svs@odoo.com> Co-authored-by: Vincent Schippefilt <vsc@odoo.com>
This commit is contained in:
committed by
Aaron Bohy
co-authored by
Aaron Bohy
Christophe Matthieu
Mathieu Duckerts-Antoine
David Monjoie
Martin Geubelle
svs-odoo
parent
237b9e8ef5
commit
bfed574255
@@ -28,7 +28,7 @@ var FieldPad = AbstractField.extend({
|
|||||||
FieldPad.prototype.isPadConfigured = result;
|
FieldPad.prototype.isPadConfigured = result;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return $.when();
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
@@ -37,8 +37,9 @@ var FieldPad = AbstractField.extend({
|
|||||||
if (!this.isPadConfigured) {
|
if (!this.isPadConfigured) {
|
||||||
this.$(".oe_unconfigured").removeClass('d-none');
|
this.$(".oe_unconfigured").removeClass('d-none');
|
||||||
this.$(".oe_configured").addClass('d-none');
|
this.$(".oe_configured").addClass('d-none');
|
||||||
return;
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
var defs = [];
|
||||||
if (this.mode === 'edit' && _.str.startsWith(this.value, 'http')) {
|
if (this.mode === 'edit' && _.str.startsWith(this.value, 'http')) {
|
||||||
this.url = this.value;
|
this.url = this.value;
|
||||||
// please close your eyes and look elsewhere...
|
// please close your eyes and look elsewhere...
|
||||||
@@ -55,10 +56,11 @@ var FieldPad = AbstractField.extend({
|
|||||||
// Guess what we decided...
|
// Guess what we decided...
|
||||||
var url = {};
|
var url = {};
|
||||||
url.toJSON = _.constant(this.url);
|
url.toJSON = _.constant(this.url);
|
||||||
this._setValue(url, {doNotSetDirty: true});
|
defs.push(this._setValue(url, {doNotSetDirty: true}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._super.apply(this, arguments);
|
defs.push(this._super.apply(this, arguments));
|
||||||
|
return Promise.all(defs);
|
||||||
},
|
},
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
@@ -156,7 +158,7 @@ var FieldPad = AbstractField.extend({
|
|||||||
.removeClass('oe_pad_loading')
|
.removeClass('oe_pad_loading')
|
||||||
.html('<div class="oe_pad_readonly"><div>');
|
.html('<div class="oe_pad_readonly"><div>');
|
||||||
self.$('.oe_pad_readonly').html(data);
|
self.$('.oe_pad_readonly').html(data);
|
||||||
}).fail(function () {
|
}).guardedCatch(function () {
|
||||||
self.$('.oe_pad_content').text(_t('Unable to load pad'));
|
self.$('.oe_pad_content').text(_t('Unable to load pad'));
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ QUnit.module('pad widget', {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('pad widget display help if server not configured', function (assert) {
|
QUnit.test('pad widget display help if server not configured', async function (assert) {
|
||||||
assert.expect(4);
|
assert.expect(4);
|
||||||
|
|
||||||
var form = createView({
|
var form = await createView({
|
||||||
View: FormView,
|
View: FormView,
|
||||||
model: 'task',
|
model: 'task',
|
||||||
data: this.data,
|
data: this.data,
|
||||||
@@ -51,28 +51,28 @@ QUnit.module('pad widget', {
|
|||||||
res_id: 1,
|
res_id: 1,
|
||||||
mockRPC: function (route, args) {
|
mockRPC: function (route, args) {
|
||||||
if (args.method === 'pad_is_configured') {
|
if (args.method === 'pad_is_configured') {
|
||||||
return $.when(false);
|
return Promise.resolve(false);
|
||||||
}
|
}
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
assert.ok(form.$('p.oe_unconfigured').is(':visible'),
|
assert.isVisible(form.$('p.oe_unconfigured'),
|
||||||
"help message should be visible");
|
"help message should be visible");
|
||||||
assert.notOk(form.$('p.oe_pad_content').is(':visible'),
|
assert.containsNone(form, 'p.oe_pad_content',
|
||||||
"content should not be visible");
|
"content should not be displayed");
|
||||||
testUtils.form.clickEdit(form);
|
await testUtils.form.clickEdit(form);
|
||||||
assert.ok(form.$('p.oe_unconfigured').is(':visible'),
|
assert.isVisible(form.$('p.oe_unconfigured'),
|
||||||
"help message should be visible");
|
"help message should be visible");
|
||||||
assert.notOk(form.$('p.oe_pad_content').is(':visible'),
|
assert.containsNone(form, 'p.oe_pad_content',
|
||||||
"content should not be visible");
|
"content should not be displayed");
|
||||||
form.destroy();
|
form.destroy();
|
||||||
delete FieldPad.prototype.isPadConfigured;
|
delete FieldPad.prototype.isPadConfigured;
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('pad widget works, basic case', function (assert) {
|
QUnit.test('pad widget works, basic case', async function (assert) {
|
||||||
assert.expect(5);
|
assert.expect(5);
|
||||||
|
|
||||||
var form = createView({
|
var form = await createView({
|
||||||
View: FormView,
|
View: FormView,
|
||||||
model: 'task',
|
model: 'task',
|
||||||
data: this.data,
|
data: this.data,
|
||||||
@@ -87,7 +87,7 @@ QUnit.module('pad widget', {
|
|||||||
mockRPC: function (route, args) {
|
mockRPC: function (route, args) {
|
||||||
if (route === 'https://pad.odoo.pad/p/test/1?showChat=false&userName=batman') {
|
if (route === 'https://pad.odoo.pad/p/test/1?showChat=false&userName=batman') {
|
||||||
assert.ok(true, "should have an iframe with correct src");
|
assert.ok(true, "should have an iframe with correct src");
|
||||||
return $.when(true);
|
return Promise.resolve(true);
|
||||||
}
|
}
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
@@ -95,14 +95,14 @@ QUnit.module('pad widget', {
|
|||||||
userName: "batman",
|
userName: "batman",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
assert.notOk(form.$('p.oe_unconfigured').is(':visible'),
|
assert.isNotVisible(form.$('p.oe_unconfigured'),
|
||||||
"help message should not be visible");
|
"help message should not be visible");
|
||||||
assert.ok(form.$('.oe_pad_content').is(':visible'),
|
assert.isVisible(form.$('.oe_pad_content'),
|
||||||
"content should be visible");
|
"content should be visible");
|
||||||
assert.strictEqual(form.$('.oe_pad_content:contains(This pad will be)').length, 1,
|
assert.containsOnce(form, '.oe_pad_content:contains(This pad will be)',
|
||||||
"content should display a message when not initialized");
|
"content should display a message when not initialized");
|
||||||
|
|
||||||
testUtils.form.clickEdit(form);
|
await testUtils.form.clickEdit(form);
|
||||||
|
|
||||||
assert.containsOnce(form, '.oe_pad_content iframe',
|
assert.containsOnce(form, '.oe_pad_content iframe',
|
||||||
"should have an iframe");
|
"should have an iframe");
|
||||||
@@ -111,12 +111,12 @@ QUnit.module('pad widget', {
|
|||||||
delete FieldPad.prototype.isPadConfigured;
|
delete FieldPad.prototype.isPadConfigured;
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('pad widget works, with existing data', function (assert) {
|
QUnit.test('pad widget works, with existing data', async function (assert) {
|
||||||
assert.expect(3);
|
assert.expect(3);
|
||||||
|
|
||||||
var contentDef = $.Deferred();
|
var contentDef = testUtils.makeTestPromise();
|
||||||
|
|
||||||
var form = createView({
|
var form = await createView({
|
||||||
View: FormView,
|
View: FormView,
|
||||||
model: 'task',
|
model: 'task',
|
||||||
data: this.data,
|
data: this.data,
|
||||||
@@ -130,7 +130,7 @@ QUnit.module('pad widget', {
|
|||||||
res_id: 2,
|
res_id: 2,
|
||||||
mockRPC: function (route, args) {
|
mockRPC: function (route, args) {
|
||||||
if (_.str.startsWith(route, 'http')) {
|
if (_.str.startsWith(route, 'http')) {
|
||||||
return $.when(true);
|
return Promise.resolve(true);
|
||||||
}
|
}
|
||||||
var result = this._super.apply(this, arguments);
|
var result = this._super.apply(this, arguments);
|
||||||
if (args.method === 'pad_get_content') {
|
if (args.method === 'pad_get_content') {
|
||||||
@@ -149,19 +149,20 @@ QUnit.module('pad widget', {
|
|||||||
assert.strictEqual(form.$('.oe_pad_content').text(), "Loading",
|
assert.strictEqual(form.$('.oe_pad_content').text(), "Loading",
|
||||||
"should display loading message");
|
"should display loading message");
|
||||||
contentDef.resolve();
|
contentDef.resolve();
|
||||||
|
await testUtils.nextTick();
|
||||||
assert.strictEqual(form.$('.oe_pad_content').text(), "we should rewrite this server in haskell",
|
assert.strictEqual(form.$('.oe_pad_content').text(), "we should rewrite this server in haskell",
|
||||||
"should display proper value");
|
"should display proper value");
|
||||||
|
|
||||||
testUtils.form.clickEdit(form);
|
await testUtils.form.clickEdit(form);
|
||||||
testUtils.form.clickSave(form);
|
await testUtils.form.clickSave(form);
|
||||||
form.destroy();
|
form.destroy();
|
||||||
delete FieldPad.prototype.isPadConfigured;
|
delete FieldPad.prototype.isPadConfigured;
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('pad widget is not considered dirty at creation', function (assert) {
|
QUnit.test('pad widget is not considered dirty at creation', async function (assert) {
|
||||||
assert.expect(2);
|
assert.expect(2);
|
||||||
|
|
||||||
var form = createView({
|
var form = await createView({
|
||||||
View: FormView,
|
View: FormView,
|
||||||
model: 'task',
|
model: 'task',
|
||||||
data: this.data,
|
data: this.data,
|
||||||
@@ -174,7 +175,7 @@ QUnit.module('pad widget', {
|
|||||||
'</form>',
|
'</form>',
|
||||||
mockRPC: function (route, args) {
|
mockRPC: function (route, args) {
|
||||||
if (!args.method) {
|
if (!args.method) {
|
||||||
return $.when(true);
|
return Promise.resolve(true);
|
||||||
}
|
}
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
@@ -183,20 +184,24 @@ QUnit.module('pad widget', {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
var def = form.canBeDiscarded();
|
var def = form.canBeDiscarded();
|
||||||
|
var defState = 'unresolved';
|
||||||
|
def.then(function () {
|
||||||
|
defState = 'resolved';
|
||||||
|
});
|
||||||
|
|
||||||
assert.strictEqual($('.modal').length, 0,
|
assert.strictEqual($('.modal').length, 0,
|
||||||
"should have no confirmation modal opened");
|
"should have no confirmation modal opened");
|
||||||
|
await testUtils.nextTick();
|
||||||
assert.strictEqual(def.state(), 'resolved',
|
assert.strictEqual(defState, 'resolved',
|
||||||
"can be discarded was succesfully resolved");
|
"can be discarded was succesfully resolved");
|
||||||
form.destroy();
|
form.destroy();
|
||||||
delete FieldPad.prototype.isPadConfigured;
|
delete FieldPad.prototype.isPadConfigured;
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('pad widget is not considered dirty at edition', function (assert) {
|
QUnit.test('pad widget is not considered dirty at edition', async function (assert) {
|
||||||
assert.expect(2);
|
assert.expect(2);
|
||||||
|
|
||||||
var form = createView({
|
var form = await createView({
|
||||||
View: FormView,
|
View: FormView,
|
||||||
model: 'task',
|
model: 'task',
|
||||||
data: this.data,
|
data: this.data,
|
||||||
@@ -210,7 +215,7 @@ QUnit.module('pad widget', {
|
|||||||
res_id: 2,
|
res_id: 2,
|
||||||
mockRPC: function (route, args) {
|
mockRPC: function (route, args) {
|
||||||
if (!args.method) {
|
if (!args.method) {
|
||||||
return $.when(true);
|
return Promise.resolve(true);
|
||||||
}
|
}
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
@@ -218,22 +223,26 @@ QUnit.module('pad widget', {
|
|||||||
userName: "batman",
|
userName: "batman",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
testUtils.form.clickEdit(form);
|
await testUtils.form.clickEdit(form);
|
||||||
var def = form.canBeDiscarded();
|
var def = form.canBeDiscarded();
|
||||||
|
var defState = 'unresolved';
|
||||||
|
def.then(function () {
|
||||||
|
defState = 'resolved';
|
||||||
|
});
|
||||||
|
|
||||||
assert.strictEqual($('.modal').length, 0,
|
assert.strictEqual($('.modal').length, 0,
|
||||||
"should have no confirmation modal opened");
|
"should have no confirmation modal opened");
|
||||||
|
await testUtils.nextTick();
|
||||||
assert.strictEqual(def.state(), 'resolved',
|
assert.strictEqual(defState, 'resolved',
|
||||||
"can be discarded was succesfully resolved");
|
"can be discarded was succesfully resolved");
|
||||||
form.destroy();
|
form.destroy();
|
||||||
delete FieldPad.prototype.isPadConfigured;
|
delete FieldPad.prototype.isPadConfigured;
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('record should be discarded properly even if only pad has changed', function (assert) {
|
QUnit.test('record should be discarded properly even if only pad has changed', async function (assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
var form = createView({
|
var form = await createView({
|
||||||
View: FormView,
|
View: FormView,
|
||||||
model: 'task',
|
model: 'task',
|
||||||
data: this.data,
|
data: this.data,
|
||||||
@@ -247,7 +256,7 @@ QUnit.module('pad widget', {
|
|||||||
res_id: 2,
|
res_id: 2,
|
||||||
mockRPC: function (route, args) {
|
mockRPC: function (route, args) {
|
||||||
if (!args.method) {
|
if (!args.method) {
|
||||||
return $.when(true);
|
return Promise.resolve(true);
|
||||||
}
|
}
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
@@ -255,8 +264,8 @@ QUnit.module('pad widget', {
|
|||||||
userName: "batman",
|
userName: "batman",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
testUtils.form.clickEdit(form);
|
await testUtils.form.clickEdit(form);
|
||||||
testUtils.form.clickDiscard(form);
|
await testUtils.form.clickDiscard(form);
|
||||||
assert.strictEqual(form.$('.oe_pad_readonly').text(), this.data.task.pad_get_content(),
|
assert.strictEqual(form.$('.oe_pad_readonly').text(), this.data.task.pad_get_content(),
|
||||||
"pad content should not have changed");
|
"pad content should not have changed");
|
||||||
form.destroy();
|
form.destroy();
|
||||||
|
|||||||
Reference in New Issue
Block a user