-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample_code_snippets.js
236 lines (179 loc) · 5.15 KB
/
sample_code_snippets.js
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
/*
* This file contains some code snippets that are used as a examples in the
* presentation slides.
*
*/
// -----------------------------------------------------------------------------
// QUnit
// -----------------------------------------------------------------------------
QUnit.module("My Module", function (hooks) {
// Tests comes here
QUnit.module("Nested Module", function (hooks) {
// Tests comes here
});
});
QUnit.module("My Module", function (hooks) {
hooks.before(function () {
// Runs once before all tests in "My Module"
});
hooks.beforeEach(function () {
// Runs before each test in "My Module"
});
hooks.afterEach(function () {
// Runs after each test in "My Module"
});
hooks.after(function () {
// Runs once after all tests in "My Module"
});
QUnit.module("Nested Module", function (hooks) {
hooks.before(function () {
// Runs once before all tests in "Nested Module"
});
});
});
QUnit.module("Math Tests", function () {
QUnit.test("Addition should work correctly", function (assert) {
assert.expect(1);
let result = 2 + 3;
assert.equal(result, 5);
});
});
QUnit.test("My test", function (assert) {
const data = {
models: {
partner: { records: [{ id: 1, name: "Jean" }] },
bar: { records: [{ name: "zzz", partner_id: 1 }] },
foo: { records: [] },
},
};
const server = new MockServer(data, {});
let result = 2 + 3;
assert.equal(result, 5);
});
QUnit.test("My view test", async function (assert) {
const target = getFixture();
serverData = {
models: {
partner: {
fields: {
id: { string: "ID", type: "number" },
type: { string: "Type", type: "char" }
},
records: [
{
id: 7,
type: "purchase",
},
],
},
},
views: {
"partner,false,list": `<list>
<field name="id"/>
<field name="display_name"/>
</list>`,
},
};
await makeView({
type: "form",
resModel: "partner",
serverData,
mockRPC(route, args) {
if (args.method === "search_read") {
return [{ id: 7, type: 'purchase' }];
}
},
});
assert.containsOnce(target, '.abcd');
});
class Counter extends Components {
static defaultValue = "abc";
setup() {
this.index = 0;
}
increment() {
this.index++;
}
}
// PATCHING
patch(Counter.prototype, {
setup() {
this.index = 10;
}
});
const unpatch = patch(Counter.prototype, {
setup() {
this.index = 10;
}
});
unpatch();
class MyClass { }
// ORIGINAL CLASS
class SomeService {
setup() {
this.orm = services.orm;
this.data;
}
async fetchData() {
this.data = await this.orm.call(
"some.model",
"some_method"
);
}
}
// PATCHED CLASS IN TEST
patch(SomeService.prototype, {
fetchData() {
return { data: "test data" };
}
})
// -----------------------------------------------------------------------------
// MOCHA
// -----------------------------------------------------------------------------
describe("Mocha test group", () => {
it("mocha test", () => {
window.chai.expect("hello").to.be.equal(
"Hello",
"Your error message"
);
})
})
describe('bold', () => {
it('should make a few characters bold', async () => {
await testEditor({
contentBefore: '<p>ab[cde]fg</p>',
stepFunction: (editor) => editor.execCommand('bold'),
contentAfter: `<p>ab<strong>[cde]</strong>fg</p>`,
});
})
})
await testEditor(BasicEditor, {
contentBefore: '<p><i class="fa fa-star"></i>[Abc]</p>',
contentBeforeEdit: '<p><i class="fa fa-star" contenteditable="false">\u200b</i>[Abc]</p>',
stepFunction: (editor) => editor.execCommand("italic"),
contentAfterEdit: '<p><i class="fa fa-star" contenteditable="false">\u200b</i><em>[Abc]</em></p>',
contentAfter: '<p><i class="fa fa-star"></i><em>[Abc]</em></p>',
})
// -----------------------------------------------------------------------------
// Web Tour
// -----------------------------------------------------------------------------
import { registry } from "@web/core/registry";
registry.category("web_tour.tours").add("drop_text_snippet", {
url: "/",
steps: () => [
{
content: "Go in Edit mode",
trigger: ".o_menu_systray a:contains('Edit')",
run: "click",
},
{
content: "Drag text snippet on page",
trigger: ".oe_snippet[name='text'] .oe_snippet_thumbnail",
run: "drag_and_drop :iframe #wrapwrap > footer",
},
{
content: "Check if text snippet is added",
trigger: ":iframe .s_text_snippet",
},
]
});