Skip to content

Commit 80b5c7d

Browse files
committed
test: add ui5ApiService unit tests
1 parent cc7ab6b commit 80b5c7d

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/core/ui5ApiService.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ function prepareUi5Objects(apiIndexEntry: ui5Api.ApiIndex | ui5Api.ApiIndexNode)
197197
}
198198
}
199199

200-
function enhanceApiIndexNode(apiIndexNode: ui5Api.ApiIndexNode): ui5Api.ApiIndexNodeEnhanced {
200+
export function enhanceApiIndexNode(
201+
apiIndexNode: ui5Api.ApiIndexNode
202+
): ui5Api.ApiIndexNodeEnhanced {
201203
return {
202204
name: getNormalizedName(apiIndexNode.name),
203205
originalName: apiIndexNode.name,
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { expect } from "chai";
2+
import * as ui5ApiService from "../../../../core/ui5ApiService";
3+
import * as stubber from "../../../support/stubber";
4+
import * as vscode from "vscode";
5+
import { ColumnListItemApiSymbol, BaseObjectApiSymbol } from "../../unit/common";
6+
7+
describe("ui5ApiBuffer tests", () => {
8+
before(() => {
9+
stubber.stubUI5Service();
10+
});
11+
12+
after(() => {
13+
stubber.restore();
14+
});
15+
16+
it("should return normalized name", () => {
17+
expect(ui5ApiService.getNormalizedName("module:sap/base/assert")).to.equal("sap.base.assert");
18+
expect(ui5ApiService.getNormalizedName("sap/base/assert")).to.equal("sap.base.assert");
19+
});
20+
21+
it("should return API doc URL", () => {
22+
expect(
23+
ui5ApiService.getUi5ObjectApiDocUrl("module:sap/base/assert", "http://somewhere")
24+
).to.equal("http://somewhere/#/api/module%3Asap%2Fbase%2Fassert");
25+
26+
expect(ui5ApiService.getUi5ObjectApiDocUrl("sap/base/assert", "http://somewhere")).to.equal(
27+
"http://somewhere/#/api/sap/base/assert"
28+
);
29+
});
30+
31+
it("should enhance API index node", () => {
32+
ui5ApiService.setApiBaseURL("http://somewhere");
33+
34+
const result = ui5ApiService.enhanceApiIndexNode({
35+
name: "sap.m.Button",
36+
kind: "class",
37+
lib: "sap.m",
38+
displayName: "sap.m.Button",
39+
visibility: "public",
40+
});
41+
42+
expect(result.apiDocUrl).to.equal("http://somewhere/#/api/sap.m.Button");
43+
expect(result.library).to.equal("sap.m");
44+
expect(result.basename).to.equal("Button");
45+
expect(result.name).to.equal("sap.m.Button");
46+
expect(result.originalName).to.equal("sap.m.Button");
47+
expect(result.kind).to.equal("class");
48+
});
49+
});

0 commit comments

Comments
 (0)