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] Close gaps in routing support of ComponentAnalyzer #46

Merged
merged 1 commit into from
Jul 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 20 additions & 9 deletions lib/lbt/analyzer/ComponentAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ function each(obj, fn) {
}
}

function makeArray(value) {
if ( Array.isArray(value) ) {
return value;
}
return value == null ? [] : [value];
}

/**
* Analyzes the manifest for a Component.js to find more dependencies.
* @since 1.47.0
Expand Down Expand Up @@ -142,15 +149,19 @@ class ComponentAnalyzer {
* @private
*/
_visitRoute( route, routing, info ) {
const viewPath = routing.config.viewPath ? routing.config.viewPath + "." : "";
const viewType = routing.config.viewType.toLowerCase();
const target = routing.targets[route.target];
if ( target && target.viewName ) {
const module = ModuleName.fromUI5LegacyName(viewPath + target.viewName, ".view." + viewType);
log.verbose("converting route to view dependency ", module);
// TODO make this a conditional dependency, depending on the pattern?
info.addDependency(module);
}
makeArray(route.target).forEach((targetRef) => {
const target = routing.targets[targetRef];
if ( target && target.viewName ) {
// merge target config with default config
const config = Object.assign({}, routing.config, target);
const module = ModuleName.fromUI5LegacyName(
(config.viewPath ? config.viewPath + "." : "") +
config.viewName, ".view." + config.viewType.toLowerCase() );
log.verbose("converting routing target '%s' to view dependency '%s'", targetRef, module);
// TODO make this a conditional dependency, depending on the pattern?
info.addDependency(module);
}
});
}
}

Expand Down
88 changes: 88 additions & 0 deletions test/lib/lbt/analyzer/ComponentAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,91 @@ test("routing with routes as object", (t) => {
const subject = new ComponentAnalyzer(mockPool);
return subject.analyze({name: "test/Component.js"}, mockInfo);
});

test("routing with route with multiple targets", (t) => {
const mockManifest = {
"sap.ui5": {
routing: {
config: {
viewPath: "test.view",
viewType: "XML"
},
routes: {
test: {
target: ["test1", "test2"]
}
},
targets: {
test1: {viewName: "Master"},
test2: {viewName: "Detail"}
}
}
}
};

const mockPool = createMockPool("test/", mockManifest);

const mockInfo = {
deps: [],
addDependency(name) {
this.deps.push(name);
}
};

const subject = new ComponentAnalyzer(mockPool);
return subject.analyze({name: "test/Component.js"}, mockInfo).then( () => {
t.deepEqual(mockInfo.deps, [
"test/view/Master.view.xml",
"test/view/Detail.view.xml"
], "dependencies should be correct");
});
});

test("routing with targets with local config", (t) => {
const mockManifest = {
"sap.ui5": {
routing: {
config: {
viewPath: "test.view",
viewType: "XML"
},
routes: {
test1: {
target: "test1"
},
test2: {
target: "test2"
}
},
targets: {
test1: {
viewName: "Master",
viewType: "JS"
},
test2: {
viewName: "Detail",
viewPath: "test.subview"
}
}
}
}
};

const mockPool = createMockPool("test/", mockManifest);

const mockInfo = {
deps: [],
addDependency(name) {
this.deps.push(name);
}
};

const subject = new ComponentAnalyzer(mockPool);
return subject.analyze({name: "test/Component.js"}, mockInfo).then( () => {
t.deepEqual(mockInfo.deps, [
"test/view/Master.view.js",
"test/subview/Detail.view.xml"
], "dependencies should be correct");
});
});