Skip to content

Commit

Permalink
[FIX] Close gaps in routing support of ComponentAnalyzer (#46)
Browse files Browse the repository at this point in the history
- accept routes with multiple targets
- merge target-local configuration with main router configuration
  • Loading branch information
codeworrior committed Jul 6, 2018
1 parent 445c067 commit 4697531
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 9 deletions.
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");
});
});

0 comments on commit 4697531

Please sign in to comment.