Skip to content

Commit 8842249

Browse files
committed
[INTERNAL] Add tests with async factory function
1 parent f3df91a commit 8842249

File tree

4 files changed

+124
-10
lines changed

4 files changed

+124
-10
lines changed

test/lib/lbt/analyzer/FioriElementsAnalyzer.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,26 @@ test("_analyzeAST: get template name from ast", async (t) => {
245245
t.is(templateName, "sap.fe.templates.Page.view.Page");
246246
});
247247

248+
test("_analyzeAST: get template name from ast (async function)", async (t) => {
249+
const code = `sap.ui.define(["a", "sap/fe/core/TemplateAssembler"], async function(a, TemplateAssembler){
250+
return TemplateAssembler.getTemplateComponent(getMethods,
251+
"sap.fe.templates.Page.Component", {
252+
metadata: {
253+
properties: {
254+
"templateName": {
255+
"type": "string",
256+
"defaultValue": "sap.fe.templates.Page.view.Page"
257+
}
258+
},
259+
"manifest": "json"
260+
}
261+
});});`;
262+
const ast = parseUtils.parseJS(code);
263+
const analyzer = new FioriElementsAnalyzer();
264+
const templateName = await analyzer._analyzeAST("sap.fe.templates.Page.Component", ast);
265+
t.is(templateName, "sap.fe.templates.Page.view.Page");
266+
});
267+
248268
test("_analyzeAST: get template name from ast (ArrowFunction)", async (t) => {
249269
const code = `sap.ui.define(["a", "sap/fe/core/TemplateAssembler"], (a, TemplateAssembler) => {
250270
return TemplateAssembler.getTemplateComponent(getMethods,
@@ -285,6 +305,26 @@ test("_analyzeAST: get template name from ast (ArrowFunction with implicit retur
285305
t.is(templateName, "sap.fe.templates.Page.view.Page");
286306
});
287307

308+
test("_analyzeAST: get template name from ast (async factory function)", async (t) => {
309+
const code = `sap.ui.define(["a", "sap/fe/core/TemplateAssembler"],
310+
async (a, TemplateAssembler) => TemplateAssembler.getTemplateComponent(getMethods,
311+
"sap.fe.templates.Page.Component", {
312+
metadata: {
313+
properties: {
314+
"templateName": {
315+
"type": "string",
316+
"defaultValue": "sap.fe.templates.Page.view.Page"
317+
}
318+
},
319+
"manifest": "json"
320+
}
321+
}));`;
322+
const ast = parseUtils.parseJS(code);
323+
const analyzer = new FioriElementsAnalyzer();
324+
const templateName = await analyzer._analyzeAST("sap.fe.templates.Page.Component", ast);
325+
t.is(templateName, "sap.fe.templates.Page.view.Page");
326+
});
327+
288328
test("_analyzeAST: get template name from ast (with SpreadElement)", async (t) => {
289329
const code = `sap.ui.define(["a", "sap/fe/core/TemplateAssembler"], (a, TemplateAssembler) => {
290330
const myTemplate = {

test/lib/lbt/analyzer/SmartTemplateAnalyzer.js

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -447,19 +447,51 @@ test("_analyzeAST: get template name from ast (ArrowFunction with implicit retur
447447
}
448448
}));`;
449449
const ast = parseUtils.parseJS(code);
450-
451450
const analyzer = new SmartTemplateAnalyzer();
451+
const templateName = await analyzer._analyzeAST("sap.fe.templates.Page.Component", ast);
452+
t.is(templateName, "sap.fe.templates.Page.view.Page");
453+
});
452454

453-
const stubAnalyzeTemplateClassDefinition = sinon.stub(analyzer,
454-
"_analyzeTemplateClassDefinition").returns("donkey");
455-
456-
const result = await analyzer._analyzeAST("pony", ast);
457-
458-
459-
t.true(stubAnalyzeTemplateClassDefinition.calledOnce, "_analyzeTemplateClassDefinition was called once");
455+
test("_analyzeAST: get template name from ast (async ArrowFunction)", async (t) => {
456+
const code = `sap.ui.define(["a", "sap/suite/ui/generic/template/lib/TemplateAssembler"],
457+
async (a, TemplateAssembler) => TemplateAssembler.getTemplateComponent(getMethods,
458+
"sap.fe.templates.Page.Component", {
459+
metadata: {
460+
properties: {
461+
"templateName": {
462+
"type": "string",
463+
"defaultValue": "sap.fe.templates.Page.view.Page"
464+
}
465+
},
466+
"manifest": "json"
467+
}
468+
}));`;
469+
const ast = parseUtils.parseJS(code);
470+
const analyzer = new SmartTemplateAnalyzer();
471+
const templateName = await analyzer._analyzeAST("sap.fe.templates.Page.Component", ast);
472+
t.is(templateName, "sap.fe.templates.Page.view.Page");
473+
});
460474

461-
stubAnalyzeTemplateClassDefinition.restore();
462-
t.is(result, "donkey");
475+
test("_analyzeAST: get template name from ast (async function)", async (t) => {
476+
const code = `sap.ui.define(["a", "sap/suite/ui/generic/template/lib/TemplateAssembler"],
477+
async function (a, TemplateAssembler) {
478+
return TemplateAssembler.getTemplateComponent(getMethods,
479+
"sap.fe.templates.Page.Component", {
480+
metadata: {
481+
properties: {
482+
"templateName": {
483+
"type": "string",
484+
"defaultValue": "sap.fe.templates.Page.view.Page"
485+
}
486+
},
487+
"manifest": "json"
488+
}
489+
}
490+
);});`;
491+
const ast = parseUtils.parseJS(code);
492+
const analyzer = new SmartTemplateAnalyzer();
493+
const templateName = await analyzer._analyzeAST("sap.fe.templates.Page.Component", ast);
494+
t.is(templateName, "sap.fe.templates.Page.view.Page");
463495
});
464496

465497
test("_analyzeAST: get template name from ast (with SpreadElement)", async (t) => {

test/lib/lbt/analyzer/XMLCompositeAnalyzer.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ test("integration: XMLComposite code without VariableDeclaration", async (t) =>
4141
"Dependency should be created from composite name");
4242
});
4343

44+
test("integration: XMLComposite code without VariableDeclaration (async function)", async (t) => {
45+
const code = `sap.ui.define([
46+
'jquery.sap.global', 'sap/ui/core/XMLComposite'],
47+
async function(jQuery, XMLComposite) {
48+
"use strict";
49+
return XMLComposite.extend("composites.ButtonList", {});
50+
});`;
51+
52+
const ast = parseJS(code);
53+
54+
const analyzer = new XMLCompositeAnalyzer();
55+
const name = "composites.ButtonList";
56+
const moduleInfo = new ModuleInfo();
57+
await analyzer.analyze(ast, name, moduleInfo);
58+
t.deepEqual(moduleInfo.dependencies, ["composites/ButtonList.control.xml"],
59+
"Dependency should be created from composite name");
60+
});
61+
4462
test("integration: XMLComposite code with arrow function", async (t) => {
4563
const code = `sap.ui.define([
4664
'jquery.sap.global', 'sap/ui/core/XMLComposite'],
@@ -58,6 +76,23 @@ test("integration: XMLComposite code with arrow function", async (t) => {
5876
"Dependency should be created from composite name");
5977
});
6078

79+
test("integration: XMLComposite code with async arrow function", async (t) => {
80+
const code = `sap.ui.define([
81+
'jquery.sap.global', 'sap/ui/core/XMLComposite'],
82+
async(jQuery, XMLComposite) => {
83+
return XMLComposite.extend("composites.ButtonList", {});
84+
});`;
85+
86+
const ast = parseJS(code);
87+
88+
const analyzer = new XMLCompositeAnalyzer();
89+
const name = "composites.ButtonList";
90+
const moduleInfo = new ModuleInfo();
91+
await analyzer.analyze(ast, name, moduleInfo);
92+
t.deepEqual(moduleInfo.dependencies, ["composites/ButtonList.control.xml"],
93+
"Dependency should be created from composite name");
94+
});
95+
6196
test("integration: XMLComposite code with arrow function with implicit return", async (t) => {
6297
const code = `sap.ui.define([
6398
'jquery.sap.global', 'sap/ui/core/XMLComposite'],

test/lib/lbt/calls/SapUiDefine.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ test("Find Import Name (destructuring)", (t) => {
9292
t.is(call.findImportName("invalid1.js"), null);
9393
});
9494

95+
test("Find Import Name (async function)", (t) => {
96+
const ast = parse("sap.ui.define(['wanted'], async function(johndoe) {});");
97+
const call = new SapUiDefineCall(ast, "FileSystemName");
98+
t.is(call.findImportName("wanted.js"), "johndoe");
99+
});
100+
101+
95102
test("Export as Global: omitted", (t) => {
96103
const ast = parse("sap.ui.define(['wanted'], function(johndoe) {});");
97104
const call = new SapUiDefineCall(ast, "FileSystemName");

0 commit comments

Comments
 (0)