Skip to content

Commit cec4be1

Browse files
committed
[INTERNAL] FioriElementsAnalyzer, SmartTemplateAnalyzer, XMLCompositeAnalyzer: add tests for SpreadElement handling
1 parent dfc952b commit cec4be1

File tree

3 files changed

+87
-4
lines changed

3 files changed

+87
-4
lines changed

test/lib/lbt/analyzer/FioriElementsAnalyzer.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,32 @@ test("_analyzeAST: get template name from ast (ArrowFunction with implicit retur
315315
t.deepEqual(result, "donkey");
316316
});
317317

318+
test("_analyzeAST: get template name from ast (with SpreadElement)", async (t) => {
319+
const code = `sap.ui.define(["a", "sap/fe/core/TemplateAssembler"], (a, TemplateAssembler) => {
320+
const myTemplate = {
321+
templateName: {
322+
type: "string",
323+
defaultValue: "sap.fe.templates.Page.view.Page"
324+
}
325+
};
326+
return TemplateAssembler.getTemplateComponent(getMethods,
327+
"sap.fe.templates.Page.Component", {
328+
metadata: {
329+
properties: {
330+
...myTemplate
331+
},
332+
"manifest": "json"
333+
}
334+
});});`;
335+
const ast = parseUtils.parseJS(code);
336+
const analyzer = new FioriElementsAnalyzer();
337+
const templateName = await analyzer._analyzeAST("sap.fe.templates.Page.Component", ast);
338+
339+
t.is(templateName, "", "The TemplateName is correctly empty");
340+
// TODO: Support SpreadElement
341+
// t.is(templateName, "sap.fe.templates.Page.view.Page", "The TemplateName is correctly determined");
342+
});
343+
318344
test("_analyzeAST: no template name from ast", async (t) => {
319345
const code = `sap.ui.define(["a", "sap/fe/core/TemplateAssembler"], function(a, TemplateAssembler){
320346
return TemplateAssembler.getTemplateComponent(getMethods,

test/lib/lbt/analyzer/SmartTemplateAnalyzer.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,34 @@ test("_analyzeAST: get template name from ast (ArrowFunction with implicit retur
462462
t.deepEqual(result, "donkey");
463463
});
464464

465+
test("_analyzeAST: get template name from ast (with SpreadElement)", async (t) => {
466+
const code = `sap.ui.define(["a", "sap/suite/ui/generic/template/lib/TemplateAssembler"],
467+
(a, TemplateAssembler) => {
468+
const myTemplate = {
469+
templateName: {
470+
type: "string",
471+
defaultValue: "sap.fe.templates.Page.view.Page"
472+
}
473+
};
474+
return TemplateAssembler.getTemplateComponent(getMethods,
475+
"sap.fe.templates.Page.Component", {
476+
metadata: {
477+
properties: {
478+
...myTemplate
479+
},
480+
"manifest": "json"
481+
}
482+
});});`;
483+
const ast = parseUtils.parseJS(code);
484+
const analyzer = new SmartTemplateAnalyzer();
485+
const templateName = await analyzer._analyzeAST("sap.fe.templates.Page.Component", ast);
486+
487+
t.is(templateName, "", "The TemplateName is correctly empty");
488+
// TODO: Support SpreadElement
489+
// t.is(templateName, "sap.fe.templates.Page.view.Page", "The TemplateName is correctly determined");
490+
});
491+
492+
465493
test("_analyzeAST: no template name from ast", async (t) => {
466494
const code = `sap.ui.define(["a", "sap/suite/ui/generic/template/lib/TemplateAssembler"],
467495
function(a, TemplateAssembler){

test/lib/lbt/analyzer/XMLCompositeAnalyzer.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test("integration: XMLComposite code", async (t) => {
2020
const moduleInfo = new ModuleInfo();
2121
await analyzer.analyze(ast, name, moduleInfo);
2222
t.deepEqual(moduleInfo.dependencies, ["composites/ButtonList.control.xml"],
23-
"Dependency should be created from component name");
23+
"Dependency should be created from composite name");
2424
});
2525

2626
test("integration: XMLComposite code without VariableDeclaration", async (t) => {
@@ -38,7 +38,7 @@ test("integration: XMLComposite code without VariableDeclaration", async (t) =>
3838
const moduleInfo = new ModuleInfo();
3939
await analyzer.analyze(ast, name, moduleInfo);
4040
t.deepEqual(moduleInfo.dependencies, ["composites/ButtonList.control.xml"],
41-
"Dependency should be created from component name");
41+
"Dependency should be created from composite name");
4242
});
4343

4444
test("integration: XMLComposite code with arrow function", async (t) => {
@@ -55,7 +55,7 @@ test("integration: XMLComposite code with arrow function", async (t) => {
5555
const moduleInfo = new ModuleInfo();
5656
await analyzer.analyze(ast, name, moduleInfo);
5757
t.deepEqual(moduleInfo.dependencies, ["composites/ButtonList.control.xml"],
58-
"Dependency should be created from component name");
58+
"Dependency should be created from composite name");
5959
});
6060

6161
test("integration: XMLComposite code with arrow function with implicit return", async (t) => {
@@ -70,7 +70,36 @@ test("integration: XMLComposite code with arrow function with implicit return",
7070
const moduleInfo = new ModuleInfo();
7171
await analyzer.analyze(ast, name, moduleInfo);
7272
t.deepEqual(moduleInfo.dependencies, ["composites/ButtonList.control.xml"],
73-
"Dependency should be created from component name");
73+
"Dependency should be created from composite name");
74+
});
75+
76+
test.only("integration: XMLComposite code with SpreadElement", async (t) => {
77+
const code = `sap.ui.define([
78+
'jquery.sap.global', 'sap/ui/core/XMLComposite'],
79+
(jQuery, XMLComposite) => {
80+
const myXMLComposite = {
81+
fragment: "composites.custom.ButtonList"
82+
};
83+
return XMLComposite.extend("composites.ButtonList", {
84+
...myXMLComposite
85+
});
86+
});`;
87+
88+
89+
const ast = parseJS(code);
90+
91+
const analyzer = new XMLCompositeAnalyzer();
92+
const name = "composites.ButtonList";
93+
const moduleInfo = new ModuleInfo();
94+
await analyzer.analyze(ast, name, moduleInfo);
95+
96+
t.deepEqual(moduleInfo.dependencies, ["composites/ButtonList.control.xml"],
97+
"Dependency should be created from composite name because overriden by the 'fragment' property " +
98+
" is not possible to lacking SpreadElement support");
99+
100+
// TODO: Support SpreadElement
101+
// t.deepEqual(moduleInfo.dependencies, ["composites/custom/ButtonList.control.xml"],
102+
// "Dependency should be created from composite name");
74103
});
75104

76105
test("analyze: not an XMLComposite module", async (t) => {

0 commit comments

Comments
 (0)