-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] iterate over routes using a for loop if it is an object (#31)
Routes may be defined as an array or object in the manifest. If it its an object we use `for .. in` to iterate over it, for arrays we stay with forEach. Fixes #30
- Loading branch information
1 parent
97559c9
commit e9823f6
Showing
2 changed files
with
116 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
const {test} = require("ava"); | ||
const Path = require("path"); | ||
const ComponentAnalyzer = require("../../../../lib/lbt/analyzer/ComponentAnalyzer"); | ||
|
||
|
||
function createMockPool(path, manifest) { | ||
const expectedPath = Path.join(path, "manifest.json"); | ||
return { | ||
async findResource(name) { | ||
if (name !== expectedPath) { | ||
throw new Error(`unexpected resource name: ${name}, expected ${expectedPath}`); | ||
} | ||
return { | ||
async buffer() { | ||
return JSON.stringify(manifest); | ||
} | ||
}; | ||
} | ||
}; | ||
} | ||
|
||
test("routing with routes as array", (t) => { | ||
const mockManifest = { | ||
"sap.ui5": { | ||
routing: { | ||
config: { | ||
viewPath: "test.view", | ||
viewType: "XML" | ||
}, | ||
routes: [ | ||
{ | ||
name: "test", | ||
target: "test" | ||
} | ||
], | ||
targets: { | ||
test: {viewName: "App"} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const mockPool = createMockPool("test/", mockManifest); | ||
|
||
const mockInfo = { | ||
addDependency(name) { | ||
t.is(name, "test/view/App.view.xml"); | ||
} | ||
}; | ||
|
||
const subject = new ComponentAnalyzer(mockPool); | ||
return subject.analyze({name: "test/Component.js"}, mockInfo); | ||
}); | ||
|
||
|
||
test("routing with routes as object", (t) => { | ||
const mockManifest = { | ||
"sap.ui5": { | ||
routing: { | ||
config: { | ||
viewPath: "test.view", | ||
viewType: "XML" | ||
}, | ||
routes: { | ||
test: { | ||
target: "test" | ||
} | ||
}, | ||
targets: { | ||
test: {viewName: "App"} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const mockPool = createMockPool("test/", mockManifest); | ||
|
||
const mockInfo = { | ||
addDependency(name) { | ||
t.is(name, "test/view/App.view.xml"); | ||
} | ||
}; | ||
|
||
const subject = new ComponentAnalyzer(mockPool); | ||
return subject.analyze({name: "test/Component.js"}, mockInfo); | ||
}); |