Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] XMLTemplateAnalyzer: Handle empty XML view/fragment #471

Merged
merged 3 commits into from
Jun 29, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Cleanup XMLTemplateAnalyzer test
  • Loading branch information
matz3 committed Jun 26, 2020
commit 3adf1dabd2cc6e917ca4bf5bbcec2a02b3d864c5
53 changes: 11 additions & 42 deletions test/lib/lbt/analyzer/XMLTemplateAnalyzer.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,10 @@ const XMLTemplateAnalyzer = require("../../../../lib/lbt/analyzer/XMLTemplateAna
const ModuleInfo = require("../../../../lib/lbt/resources/ModuleInfo");
const sinon = require("sinon");

const fakeMockPool = {
findResource: () => Promise.resolve()
};

test("integration: Analysis of an xml view", async (t) => {
const xml = `<mvc:View xmlns:mvc="sap.ui.core.mvc" xmlns:m="sap.m" xmlns:l="sap.ui.layout"
controllerName="myController">
@@ -13,15 +17,10 @@ test("integration: Analysis of an xml view", async (t) => {
<m:Button />
</l:HorizontalLayout>
</mvc:View>`;
const mockPool = {async findResource(name) {
return {
buffer: () => name.endsWith(".xml") ? JSON.stringify(xml): "test"
};
}};

const moduleInfo = new ModuleInfo();

const analyzer = new XMLTemplateAnalyzer(mockPool);
const analyzer = new XMLTemplateAnalyzer(fakeMockPool);
await analyzer.analyzeView(xml, moduleInfo);
t.deepEqual(moduleInfo.dependencies,
[
@@ -39,15 +38,10 @@ test("integration: Analysis of an xml view with data binding in properties", asy
controllerName="myController">
<core:ComponentContainer async="true" name="{/component}" />
</mvc:View>`;
const mockPool = {async findResource(name) {
return {
buffer: () => name.endsWith(".xml") ? JSON.stringify(xml): "test"
};
}};

const moduleInfo = new ModuleInfo();

const analyzer = new XMLTemplateAnalyzer(mockPool);
const analyzer = new XMLTemplateAnalyzer(fakeMockPool);
await analyzer.analyzeView(xml, moduleInfo);
t.deepEqual(moduleInfo.dependencies,
[
@@ -70,15 +64,10 @@ test("integration: Analysis of an xml view with core:require", async (t) => {
<Button core:require="{Toast:'sap/m/MessageToast'}" text="Show Toast" press="Toast.show(\${$source>text})"/>

</mvc:View>`;
const mockPool = {async findResource(name) {
return {
buffer: () => name.endsWith(".xml") ? JSON.stringify(xml): "test"
};
}};

const moduleInfo = new ModuleInfo();

const analyzer = new XMLTemplateAnalyzer(mockPool);
const analyzer = new XMLTemplateAnalyzer(fakeMockPool);
await analyzer.analyzeView(xml, moduleInfo);
t.deepEqual(moduleInfo.dependencies,
[
@@ -104,15 +93,10 @@ test("integration: Analysis of an xml view with core:require (invalid module nam
<Button core:require="{ Toast: '' }" text="Show Toast" press="Toast.show(\${$source>text})"/>

</mvc:View>`;
const mockPool = {async findResource(name) {
return {
buffer: () => name.endsWith(".xml") ? JSON.stringify(xml): "test"
};
}};

const moduleInfo = new ModuleInfo();

const analyzer = new XMLTemplateAnalyzer(mockPool);
const analyzer = new XMLTemplateAnalyzer(fakeMockPool);
await analyzer.analyzeView(xml, moduleInfo);
t.deepEqual(moduleInfo.dependencies,
[
@@ -135,15 +119,10 @@ test("integration: Analysis of an xml view with core:require (parsing error)", a
<Button core:require="this can't be parsed" text="Show Toast" press="Toast.show(\${$source>text})"/>

</mvc:View>`;
const mockPool = {async findResource(name) {
return {
buffer: () => name.endsWith(".xml") ? JSON.stringify(xml): "test"
};
}};

const moduleInfo = new ModuleInfo();

const analyzer = new XMLTemplateAnalyzer(mockPool);
const analyzer = new XMLTemplateAnalyzer(fakeMockPool);
await analyzer.analyzeView(xml, moduleInfo);
t.deepEqual(moduleInfo.dependencies,
[
@@ -165,15 +144,10 @@ test("integration: Analysis of an xml fragment", async (t) => {
</l:HorizontalLayout>
</items>
</HBox>`;
const mockPool = {async findResource(name) {
return {
buffer: () => name.endsWith(".xml") ? JSON.stringify(xml): "test"
};
}};

const moduleInfo = new ModuleInfo();

const analyzer = new XMLTemplateAnalyzer(mockPool);
const analyzer = new XMLTemplateAnalyzer(fakeMockPool);
await analyzer.analyzeFragment(xml, moduleInfo);
t.deepEqual(moduleInfo.dependencies,
[
@@ -187,15 +161,10 @@ test("integration: Analysis of an xml fragment", async (t) => {

test("integration: Analysis of an empty xml view", async (t) => {
const xml = "";
const mockPool = {async findResource(name) {
return {
buffer: () => name.endsWith(".xml") ? JSON.stringify(xml): "test"
};
}};

const moduleInfo = new ModuleInfo("empty.xml");

const analyzer = new XMLTemplateAnalyzer(mockPool);
const analyzer = new XMLTemplateAnalyzer(fakeMockPool);

await t.throwsAsync(analyzer.analyzeView(xml, moduleInfo), {
message: "Invalid empty XML document: empty.xml"