Skip to content

Commit abd096c

Browse files
committed
test: new tests and refactor
- add ui5ApiBuffer tests - restructure common and add new symbols
1 parent 4dcdea2 commit abd096c

9 files changed

Lines changed: 146 additions & 43 deletions

File tree

src/core/ui5ApiBuffer.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { LibraryApiSymbol } from "./types";
22

33
const ui5ObjectsDesignApiBufferLength = 30;
4-
const ui5ObjectsDesignApiBuffer: LibraryApiSymbol[] = [];
4+
let ui5ObjectsDesignApiBuffer: LibraryApiSymbol[] = [];
55

6-
export function searchObjectDesignApiBuffer(ui5ObjectName: string): LibraryApiSymbol | undefined {
6+
export function searchObjectDesignApiBuffer(
7+
requestedObjectName: string
8+
): LibraryApiSymbol | undefined {
79
let result;
810

911
if (ui5ObjectsDesignApiBuffer.length > 0) {
10-
result = ui5ObjectsDesignApiBuffer.find((designApi) => {
11-
return designApi.name === ui5ObjectName;
12+
result = ui5ObjectsDesignApiBuffer.find((bufferedUi5Object) => {
13+
return bufferedUi5Object.name === requestedObjectName;
1214
});
1315
}
1416

@@ -24,3 +26,11 @@ export function addToObjectDesignApiBuffer(objectApi: LibraryApiSymbol) {
2426
ui5ObjectsDesignApiBuffer.push(objectApi);
2527
}
2628
}
29+
30+
export function getBufferLength() {
31+
return ui5ObjectsDesignApiBuffer.length;
32+
}
33+
34+
export function resetBuffer() {
35+
ui5ObjectsDesignApiBuffer = [];
36+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { expect } from "chai";
2+
import * as ui5ApiBuffer from "../../../../core/ui5ApiBuffer";
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+
beforeEach(() => {
17+
ui5ApiBuffer.resetBuffer();
18+
});
19+
20+
it("should find objects in the buffer", () => {
21+
ui5ApiBuffer.addToObjectDesignApiBuffer(ColumnListItemApiSymbol);
22+
ui5ApiBuffer.addToObjectDesignApiBuffer(BaseObjectApiSymbol);
23+
24+
expect(ui5ApiBuffer.searchObjectDesignApiBuffer("sap.m.ColumnListItem")).to.equal(
25+
ColumnListItemApiSymbol
26+
);
27+
28+
expect(ui5ApiBuffer.searchObjectDesignApiBuffer("sap.ui.base.Object")).to.equal(
29+
BaseObjectApiSymbol
30+
);
31+
});
32+
33+
it("should return undefined for an object not present in the buffer", () => {
34+
ui5ApiBuffer.addToObjectDesignApiBuffer(ColumnListItemApiSymbol);
35+
ui5ApiBuffer.addToObjectDesignApiBuffer(BaseObjectApiSymbol);
36+
expect(ui5ApiBuffer.searchObjectDesignApiBuffer("sap.m.ColumnList")).to.be.undefined;
37+
});
38+
39+
it("should not add the same objects again", () => {
40+
ui5ApiBuffer.addToObjectDesignApiBuffer(ColumnListItemApiSymbol);
41+
ui5ApiBuffer.addToObjectDesignApiBuffer(ColumnListItemApiSymbol);
42+
ui5ApiBuffer.addToObjectDesignApiBuffer(BaseObjectApiSymbol);
43+
ui5ApiBuffer.addToObjectDesignApiBuffer(BaseObjectApiSymbol);
44+
expect(ui5ApiBuffer.getBufferLength()).to.equal(2);
45+
});
46+
47+
it("should shift the buffer when limit is reached", () => {
48+
ui5ApiBuffer.addToObjectDesignApiBuffer(ColumnListItemApiSymbol);
49+
50+
for (let i = 0; i <= 29; i++) {
51+
const o = Object.assign({}, BaseObjectApiSymbol);
52+
o.name = `${o.name}${i}`;
53+
ui5ApiBuffer.addToObjectDesignApiBuffer(o);
54+
}
55+
56+
ui5ApiBuffer.addToObjectDesignApiBuffer(BaseObjectApiSymbol);
57+
expect(ui5ApiBuffer.getBufferLength()).to.equal(30);
58+
});
59+
});

src/test/suite/unit/common.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { LibraryApiSymbol } from "../../../core/types";
2+
3+
export const ColumnListItemApiSymbol: LibraryApiSymbol = {
4+
name: "sap.m.ColumnListItem",
5+
description: "Some description",
6+
originalName: "sap.m.ColumnListItem",
7+
basename: "ColumnListItem",
8+
kind: "class",
9+
apiDocUrl: "https://openui5.hana.ondemand.com/#/api/sap.m.ColumnListItem",
10+
module: "sap.m",
11+
resource: "sap.m",
12+
static: false,
13+
visibility: "public",
14+
constructor: {
15+
description: "Constructor description <code>is here</code>",
16+
},
17+
};
18+
19+
export const BaseObjectApiSymbol: LibraryApiSymbol = {
20+
name: "sap.ui.base.Object",
21+
originalName: "sap.ui.base.Object",
22+
basename: "Object",
23+
kind: "class",
24+
apiDocUrl: "https://openui5.hana.ondemand.com/#/api/sap.ui.base.Object",
25+
description: "Description",
26+
module: "sap.ui",
27+
resource: "sap.ui",
28+
static: false,
29+
visibility: "public",
30+
constructor: {
31+
description: "Constructor description <code>is here</code>",
32+
},
33+
};

src/test/suite/unit/objectApi/aggregationFormat.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from "chai";
22
import * as stubber from "../../../support/stubber";
33
import { prepareAggregations } from "../../../../objectApi/aggregationFormat";
44
import { Ui5ObjectAggregation, LibraryApiSymbol } from "../../../../core/types";
5-
import { ui5ObjectApi } from "./common";
5+
import { ColumnListItemApiSymbol } from "../common";
66

77
const rawAggregation: Ui5ObjectAggregation = {
88
name: "myName",
@@ -25,7 +25,7 @@ describe("aggregationFormat tests", () => {
2525
});
2626

2727
it("should prepare basic fields", () => {
28-
const formatted = prepareAggregations([rawAggregation], ui5ObjectApi, true);
28+
const formatted = prepareAggregations([rawAggregation], ColumnListItemApiSymbol, true);
2929

3030
expect(formatted).to.have.lengthOf(1);
3131
const aggregation = formatted[0];
@@ -40,7 +40,11 @@ describe("aggregationFormat tests", () => {
4040
});
4141

4242
it("should prepare UI5 object type", () => {
43-
const formatted = prepareAggregations([rawAggregationWithUi5Type], ui5ObjectApi, true);
43+
const formatted = prepareAggregations(
44+
[rawAggregationWithUi5Type],
45+
ColumnListItemApiSymbol,
46+
true
47+
);
4448

4549
expect(formatted).to.have.lengthOf(1);
4650
expect(formatted[0].hasUi5ObjectType).to.be.true;

src/test/suite/unit/objectApi/common.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/test/suite/unit/objectApi/constructorFormat.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from "chai";
22
import * as stubber from "../../../support/stubber";
33
import { prepareConstructor } from "../../../../objectApi/constructorFormat";
44
import { Ui5ObjectConstructor, LibraryApiSymbol } from "../../../../core/types";
5-
import { ui5ObjectApi } from "./common";
5+
import { ColumnListItemApiSymbol } from "../common";
66

77
const rawConstructor: Ui5ObjectConstructor = {
88
description: "This is <code>constructor</code>",
@@ -32,7 +32,7 @@ describe("constructorFormat tests", () => {
3232
});
3333

3434
it("should prepare basic fields with parameters", () => {
35-
const formattedConstructor = prepareConstructor(rawConstructor, ui5ObjectApi, true);
35+
const formattedConstructor = prepareConstructor(rawConstructor, ColumnListItemApiSymbol, true);
3636

3737
expect(formattedConstructor).not.to.be.undefined;
3838
expect(formattedConstructor.description).to.equal("This is constructor");

src/test/suite/unit/objectApi/eventFormat.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from "chai";
22
import * as stubber from "../../../support/stubber";
33
import { prepareEvents } from "../../../../objectApi/eventFormat";
44
import { Ui5ObjectEvent, LibraryApiSymbol } from "../../../../core/types";
5-
import { ui5ObjectApi } from "./common";
5+
import { ColumnListItemApiSymbol } from "../common";
66

77
const rawEvent: Ui5ObjectEvent = {
88
description: "This is <code>event</code>",
@@ -37,7 +37,7 @@ describe("eventFormat tests", () => {
3737
});
3838

3939
it("should prepare basic fields", () => {
40-
const formatted = prepareEvents([rawEvent], ui5ObjectApi, true);
40+
const formatted = prepareEvents([rawEvent], ColumnListItemApiSymbol, true);
4141
expect(formatted).to.have.lengthOf(1);
4242
const event = formatted[0];
4343
expect(event.description).to.equal("This is event");
@@ -49,13 +49,13 @@ describe("eventFormat tests", () => {
4949
});
5050

5151
it("should prepare deprecated", () => {
52-
const formatted = prepareEvents([rawEventDeprecated], ui5ObjectApi, true);
52+
const formatted = prepareEvents([rawEventDeprecated], ColumnListItemApiSymbol, true);
5353
expect(formatted).to.have.lengthOf(1);
5454
expect(formatted[0].description).to.equal("[DEPRECATED! No longer used] This is event");
5555
});
5656

5757
it("should prepare event parameters", () => {
58-
const formatted = prepareEvents([rawEventDeprecated], ui5ObjectApi, true);
58+
const formatted = prepareEvents([rawEventDeprecated], ColumnListItemApiSymbol, true);
5959
expect(formatted).to.have.lengthOf(1);
6060
expect(formatted[0]).not.to.be.undefined;
6161
});

src/test/suite/unit/objectApi/methodFormat.test.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from "chai";
22
import * as stubber from "../../../support/stubber";
33
import { prepareMethods } from "../../../../objectApi/methodFormat";
44
import { Ui5ObjectMethod, LibraryApiSymbol } from "../../../../core/types";
5-
import { ui5ObjectApi } from "./common";
5+
import { ColumnListItemApiSymbol } from "../common";
66

77
const rawMethod: Ui5ObjectMethod = {
88
description: "This is <code>method</code>",
@@ -51,7 +51,7 @@ describe("methodFormat tests", () => {
5151
});
5252

5353
it("should prepare basic fields", () => {
54-
const formatted = prepareMethods([rawMethod], ui5ObjectApi, true, true);
54+
const formatted = prepareMethods([rawMethod], ColumnListItemApiSymbol, true, true);
5555
expect(formatted).to.have.lengthOf(1);
5656
const method = formatted[0];
5757
expect(method.description).to.equal("This is method");
@@ -63,33 +63,38 @@ describe("methodFormat tests", () => {
6363
});
6464

6565
it("should prepare deprecated", () => {
66-
const formatted = prepareMethods([rawMethodDeprecated], ui5ObjectApi, true, true);
66+
const formatted = prepareMethods([rawMethodDeprecated], ColumnListItemApiSymbol, true, true);
6767
expect(formatted).to.have.lengthOf(1);
6868
expect(formatted[0].description).to.equal("[DEPRECATED! No longer used] This is method");
6969
});
7070

7171
it("should prepare flat static name", () => {
72-
const formatted = prepareMethods([rawMethodStatic], ui5ObjectApi, true, true);
72+
const formatted = prepareMethods([rawMethodStatic], ColumnListItemApiSymbol, true, true);
7373
expect(formatted).to.have.lengthOf(1);
7474
expect(formatted[0].static).to.be.true;
7575
expect(formatted[0].name).to.equal("myMethod");
7676
});
7777

7878
it("should prepare full static name", () => {
79-
const formatted = prepareMethods([rawMethodStatic], ui5ObjectApi, true, false);
79+
const formatted = prepareMethods([rawMethodStatic], ColumnListItemApiSymbol, true, false);
8080
expect(formatted).to.have.lengthOf(1);
8181
expect(formatted[0].static).to.be.true;
8282
expect(formatted[0].name).to.equal("sap.m.ColumnListItem.myMethod");
8383
});
8484

8585
it("should prepare with params", () => {
86-
const formatted = prepareMethods([rawMethodWithParams], ui5ObjectApi, true, true);
86+
const formatted = prepareMethods([rawMethodWithParams], ColumnListItemApiSymbol, true, true);
8787
expect(formatted).to.have.lengthOf(1);
8888
expect(formatted[0].parameters).to.have.lengthOf(1);
8989
});
9090

9191
it("should prepare with simple return value", () => {
92-
const formatted = prepareMethods([rawMethodWithSimpleReturnType], ui5ObjectApi, true, true);
92+
const formatted = prepareMethods(
93+
[rawMethodWithSimpleReturnType],
94+
ColumnListItemApiSymbol,
95+
true,
96+
true
97+
);
9398
expect(formatted).to.have.lengthOf(1);
9499
const method = formatted[0];
95100
expect(method.hasReturnValue).to.be.true;
@@ -98,7 +103,12 @@ describe("methodFormat tests", () => {
98103
});
99104

100105
it("should prepare with UI5 object return value", () => {
101-
const formatted = prepareMethods([rawMethodWithUi5ReturnType], ui5ObjectApi, true, true);
106+
const formatted = prepareMethods(
107+
[rawMethodWithUi5ReturnType],
108+
ColumnListItemApiSymbol,
109+
true,
110+
true
111+
);
102112
expect(formatted).to.have.lengthOf(1);
103113
const method = formatted[0];
104114
expect(method.hasReturnValue).to.be.true;

src/test/suite/unit/objectApi/propertiesFormat.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from "chai";
22
import * as stubber from "../../../support/stubber";
33
import { prepareProperties } from "../../../../objectApi/propertiesFormat";
44
import { Ui5ObjectProperty, LibraryApiSymbol } from "../../../../core/types";
5-
import { ui5ObjectApi } from "./common";
5+
import { ColumnListItemApiSymbol } from "../common";
66

77
const rawPropertyBasic: Ui5ObjectProperty = {
88
name: "myName",
@@ -30,7 +30,7 @@ describe("propertiesFormat tests", () => {
3030
});
3131

3232
it("should prepare basic fields", () => {
33-
const formatted = prepareProperties([rawPropertyBasic], ui5ObjectApi, true);
33+
const formatted = prepareProperties([rawPropertyBasic], ColumnListItemApiSymbol, true);
3434

3535
expect(formatted).to.have.lengthOf(1);
3636
const property = formatted[0];
@@ -46,7 +46,7 @@ describe("propertiesFormat tests", () => {
4646
});
4747

4848
it("should prepare deprecated text", () => {
49-
const formatted = prepareProperties([rawPropertyDeprecated], ui5ObjectApi, true);
49+
const formatted = prepareProperties([rawPropertyDeprecated], ColumnListItemApiSymbol, true);
5050

5151
expect(formatted).to.have.lengthOf(1);
5252
expect(formatted[0].description).to.equal(
@@ -55,14 +55,18 @@ describe("propertiesFormat tests", () => {
5555
});
5656

5757
it("should prepare default value", () => {
58-
const formatted = prepareProperties([rawPropertyWithSimpleDefaultValue], ui5ObjectApi, true);
58+
const formatted = prepareProperties(
59+
[rawPropertyWithSimpleDefaultValue],
60+
ColumnListItemApiSymbol,
61+
true
62+
);
5963

6064
expect(formatted).to.have.lengthOf(1);
6165
expect(formatted[0].defaultValue).to.equal("string");
6266
});
6367

6468
it("should prepare UI5 type", () => {
65-
const formatted = prepareProperties([rawPropertyWithUi5Type], ui5ObjectApi, true);
69+
const formatted = prepareProperties([rawPropertyWithUi5Type], ColumnListItemApiSymbol, true);
6670

6771
expect(formatted).to.have.lengthOf(1);
6872
expect(formatted[0].hasUi5ObjectType).to.be.true;

0 commit comments

Comments
 (0)