1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
|
odoo.define('pad.pad_tests', function (require) {
"use strict";
var FieldPad = require('pad.pad');
var FormView = require('web.FormView');
var testUtils = require('web.test_utils');
var createView = testUtils.createView;
QUnit.module('pad widget', {
beforeEach: function () {
this.data = {
task: {
fields: {
description: {string: "Description", type: "char"},
use_pad: {string: "Use pad", type: "boolean"},
},
records: [
{id: 1, description: false},
{id: 2, description: "https://pad.odoo.pad/p/test-03AK6RCJT"},
],
pad_is_configured: function () {
return true;
},
pad_generate_url: function (route, args) {
return {
url:'https://pad.odoo.pad/p/test/' + args.context.object_id
};
},
pad_get_content: function () {
return "we should rewrite this server in haskell";
},
},
};
},
});
QUnit.test('pad widget display help if server not configured', async function (assert) {
assert.expect(4);
var form = await createView({
View: FormView,
model: 'task',
data: this.data,
arch:'<form>' +
'<sheet>' +
'<group>' +
'<field name="description" widget="pad"/>' +
'</group>' +
'</sheet>' +
'</form>',
res_id: 1,
mockRPC: function (route, args) {
if (args.method === 'pad_is_configured') {
return Promise.resolve(false);
}
return this._super.apply(this, arguments);
},
});
assert.isVisible(form.$('p.oe_unconfigured'),
"help message should be visible");
assert.containsNone(form, 'p.oe_pad_content',
"content should not be displayed");
await testUtils.form.clickEdit(form);
assert.isVisible(form.$('p.oe_unconfigured'),
"help message should be visible");
assert.containsNone(form, 'p.oe_pad_content',
"content should not be displayed");
form.destroy();
delete FieldPad.prototype.isPadConfigured;
});
QUnit.test('pad widget works, basic case', async function (assert) {
assert.expect(5);
var form = await createView({
View: FormView,
model: 'task',
data: this.data,
arch:'<form>' +
'<sheet>' +
'<group>' +
'<field name="description" widget="pad"/>' +
'</group>' +
'</sheet>' +
'</form>',
res_id: 1,
mockRPC: function (route, args) {
if (route === 'https://pad.odoo.pad/p/test/1?showChat=false&userName=batman') {
assert.ok(true, "should have an iframe with correct src");
return Promise.resolve(true);
}
return this._super.apply(this, arguments);
},
session: {
name: "batman",
},
});
assert.isNotVisible(form.$('p.oe_unconfigured'),
"help message should not be visible");
assert.isVisible(form.$('.oe_pad_content'),
"content should be visible");
assert.containsOnce(form, '.oe_pad_content:contains(This pad will be)',
"content should display a message when not initialized");
await testUtils.form.clickEdit(form);
assert.containsOnce(form, '.oe_pad_content iframe',
"should have an iframe");
form.destroy();
delete FieldPad.prototype.isPadConfigured;
});
QUnit.test('pad widget works, with existing data', async function (assert) {
assert.expect(3);
var contentDef = testUtils.makeTestPromise();
var form = await createView({
View: FormView,
model: 'task',
data: this.data,
arch:'<form>' +
'<sheet>' +
'<group>' +
'<field name="description" widget="pad"/>' +
'</group>' +
'</sheet>' +
'</form>',
res_id: 2,
mockRPC: function (route, args) {
if (_.str.startsWith(route, 'http')) {
return Promise.resolve(true);
}
var result = this._super.apply(this, arguments);
if (args.method === 'pad_get_content') {
return contentDef.then(_.constant(result));
}
if (args.method === 'write') {
assert.ok('description' in args.args[1],
"should always send the description value");
}
return result;
},
session: {
name: "batman",
},
});
assert.strictEqual(form.$('.oe_pad_content').text(), "Loading",
"should display loading message");
contentDef.resolve();
await testUtils.nextTick();
assert.strictEqual(form.$('.oe_pad_content').text(), "we should rewrite this server in haskell",
"should display proper value");
await testUtils.form.clickEdit(form);
await testUtils.form.clickSave(form);
form.destroy();
delete FieldPad.prototype.isPadConfigured;
});
QUnit.test('pad widget is not considered dirty at creation', async function (assert) {
assert.expect(2);
var form = await createView({
View: FormView,
model: 'task',
data: this.data,
arch:'<form>' +
'<sheet>' +
'<group>' +
'<field name="description" widget="pad"/>' +
'</group>' +
'</sheet>' +
'</form>',
mockRPC: function (route, args) {
if (!args.method) {
return Promise.resolve(true);
}
return this._super.apply(this, arguments);
},
session: {
name: "batman",
},
});
var def = form.canBeDiscarded();
var defState = 'unresolved';
def.then(function () {
defState = 'resolved';
});
assert.strictEqual($('.modal').length, 0,
"should have no confirmation modal opened");
await testUtils.nextTick();
assert.strictEqual(defState, 'resolved',
"can be discarded was successfully resolved");
form.destroy();
delete FieldPad.prototype.isPadConfigured;
});
QUnit.test('pad widget is not considered dirty at edition', async function (assert) {
assert.expect(2);
var form = await createView({
View: FormView,
model: 'task',
data: this.data,
arch:'<form>' +
'<sheet>' +
'<group>' +
'<field name="description" widget="pad"/>' +
'</group>' +
'</sheet>' +
'</form>',
res_id: 2,
mockRPC: function (route, args) {
if (!args.method) {
return Promise.resolve(true);
}
return this._super.apply(this, arguments);
},
session: {
name: "batman",
},
});
await testUtils.form.clickEdit(form);
var def = form.canBeDiscarded();
var defState = 'unresolved';
def.then(function () {
defState = 'resolved';
});
assert.strictEqual($('.modal').length, 0,
"should have no confirmation modal opened");
await testUtils.nextTick();
assert.strictEqual(defState, 'resolved',
"can be discarded was successfully resolved");
form.destroy();
delete FieldPad.prototype.isPadConfigured;
});
QUnit.test('record should be discarded properly even if only pad has changed', async function (assert) {
assert.expect(1);
var form = await createView({
View: FormView,
model: 'task',
data: this.data,
arch:'<form>' +
'<sheet>' +
'<group>' +
'<field name="description" widget="pad"/>' +
'</group>' +
'</sheet>' +
'</form>',
res_id: 2,
mockRPC: function (route, args) {
if (!args.method) {
return Promise.resolve(true);
}
return this._super.apply(this, arguments);
},
session: {
name: "batman",
},
});
await testUtils.form.clickEdit(form);
await testUtils.form.clickDiscard(form);
assert.strictEqual(form.$('.oe_pad_readonly').text(), this.data.task.pad_get_content(),
"pad content should not have changed");
form.destroy();
delete FieldPad.prototype.isPadConfigured;
});
QUnit.test('no pad deadlock on form change modifying pad readonly modifier', async function (assert) {
assert.expect(1);
var form = await createView({
View: FormView,
model: 'task',
data: this.data,
arch:'<form>' +
'<sheet>' +
'<group>' +
'<field name="use_pad" widget="toggle_button"/>' +
'<field name="description" widget="pad" attrs="{\'readonly\': [(\'use_pad\', \'=\', False)]}"/>' +
'</group>' +
'</sheet>' +
'</form>',
res_id: 2,
mockRPC: function (route, args) {
if (!args.method) {
return Promise.resolve(true);
}
if (args.method === "write") {
assert.strictEqual(args.args[1].description,
"https://pad.odoo.pad/p/test-03AK6RCJT");
}
return this._super.apply(this, arguments);
},
});
await testUtils.form.clickEdit(form);
await testUtils.dom.click(form.$('.o_field_widget[name="use_pad"]'));
await testUtils.form.clickSave(form);
form.destroy();
delete FieldPad.prototype.isPadConfigured;
});
});
|