Skip to content

Commit fb910f4

Browse files
author
Kaushik Shetty
authored
Merge pull request #69 from contentstack/MKT-1823/type-support
MKT 1756/improved type support
2 parents c92c213 + 51b7957 commit fb910f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+5393
-1366
lines changed

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ storybook-static
128128
tmp/
129129
temp/
130130

131-
131+
# Docs
132+
jsdocs/
132133

133134
.DS_Store
134135

@@ -139,6 +140,3 @@ temp/
139140
!.vscode/launch.json
140141
!.vscode/extensions.json
141142
*.code-workspace
142-
143-
144-
# End of https://www.toptal.com/developers/gitignore/api/node,web,vscode

.jsdoc.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"tags": {
3+
"allowUnknownTags": true,
4+
"dictionaries": ["jsdoc"]
5+
},
6+
"source": {
7+
"include": ["src"],
8+
"includePattern": ".(js|ts)$"
9+
},
10+
"opts": {
11+
"template": "node_modules/better-docs",
12+
"destination": "./jsdocs/"
13+
},
14+
"templates": {
15+
"cleverLinks": false,
16+
"monospaceLinks": false
17+
},
18+
"plugins": ["node_modules/better-docs/typescript"]
19+
}

__test__/appConfig.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ describe("app config", () => {
1111
stack: {},
1212
};
1313
const appConfig: AppConfig = new AppConfig(
14-
mockData,
15-
mockConnection,
14+
mockData as any,
15+
mockConnection as any,
1616
mockEmitter,
1717
{ currentBranch: "master" }
1818
);

__test__/assetSidebarWidget.test.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import EventEmitter from "wolfy87-eventemitter";
22

33
import AssetSidebarWidget from "../src/AssetSidebarWidget";
4-
import { IAssetSidebarInitData } from "../src/types";
4+
import { IAssetSidebarInitData, LocationType } from "../src/types";
55
import Asset from "../src/stack/api/asset";
66

77
jest.mock("post-robot", () => ({
@@ -16,18 +16,16 @@ jest.mock("../src/stack/api/asset");
1616
describe("AssetSidebarWidget", () => {
1717
let assetSidebarWidget: AssetSidebarWidget;
1818
let mockInitData: IAssetSidebarInitData = {
19-
data: {
20-
type: "ASSET_SIDEBAR_WIDGET",
21-
currentAsset: {},
22-
config: {},
23-
app_id: "mock_app_uid",
24-
installation_uid: "mock_installation_uid",
25-
extension_uid: "mock_extension_uid",
26-
stack: {} as any,
27-
user: {},
28-
currentBranch: "mock_branch",
29-
region: "region",
30-
},
19+
type: LocationType.ASSET_SIDEBAR_WIDGET,
20+
currentAsset: {} as any,
21+
config: {},
22+
app_id: "mock_app_uid",
23+
installation_uid: "mock_installation_uid",
24+
extension_uid: "mock_extension_uid",
25+
stack: {} as any,
26+
user: {} as any,
27+
currentBranch: "mock_branch",
28+
region: "region",
3129
};
3230

3331
let connection: { sendToParent: (...props: any[]) => any };
@@ -53,7 +51,7 @@ describe("AssetSidebarWidget", () => {
5351
jest.spyOn(connection, "sendToParent");
5452
assetSidebarWidget = new AssetSidebarWidget(
5553
mockInitData as IAssetSidebarInitData,
56-
connection,
54+
connection as any,
5755
emitter
5856
);
5957
});
@@ -63,17 +61,15 @@ describe("AssetSidebarWidget", () => {
6361
});
6462

6563
it("should set instance properties in constructor", () => {
66-
expect(assetSidebarWidget.currentAsset).toBe(
67-
mockInitData.data.currentAsset
68-
);
64+
expect(assetSidebarWidget.currentAsset).toBe(mockInitData.currentAsset);
6965
expect(assetSidebarWidget._emitter).toBe(emitter);
7066
expect(assetSidebarWidget._connection).toBe(connection);
7167
});
7268

7369
describe("getData", () => {
7470
it("should return the current asset", () => {
7571
const currentAsset = assetSidebarWidget.getData();
76-
expect(currentAsset).toBe(mockInitData.data.currentAsset);
72+
expect(currentAsset).toBe(mockInitData.currentAsset);
7773
});
7874
});
7975

@@ -85,15 +81,15 @@ describe("AssetSidebarWidget", () => {
8581
"setData",
8682
asset
8783
);
88-
expect(result).toEqual({ data: {} });
84+
expect(result).toEqual(undefined);
8985
});
9086
});
9187

9288
describe("syncAsset", () => {
9389
it("should sync the upstream asset with the current", async () => {
9490
const result = await assetSidebarWidget.syncAsset();
9591
expect(connection.sendToParent).toHaveBeenCalledWith("syncAsset");
96-
expect(result).toEqual({ data: {} });
92+
expect(result).toEqual(undefined);
9793
});
9894
});
9995

@@ -112,7 +108,7 @@ describe("AssetSidebarWidget", () => {
112108
"updateAssetSidebarWidth",
113109
mockWidth
114110
);
115-
expect(result).toEqual({ data: {} });
111+
expect(result).toEqual(undefined);
116112
});
117113
});
118114

__test__/entry.test.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Entry from "../src/entry";
2+
import { GenericObjectType } from "../src/types/common.types";
23
import testData from "./data/testData.json";
34
import { jest } from "@jest/globals";
45

@@ -29,8 +30,11 @@ describe("Entry", () => {
2930
const changedData = JSON.parse(JSON.stringify(testData));
3031
changedData.entry.title = "changed title";
3132

32-
// @ts-ignore
33-
entry = new Entry({ data: testData, changedData }, connection, emitter);
33+
entry = new Entry(
34+
{ ...testData, changedData } as any,
35+
connection as any,
36+
emitter
37+
);
3438
});
3539

3640
it("init", (done) => {
@@ -127,21 +131,14 @@ describe("Entry", () => {
127131
expect(field.uid).toBe(uid);
128132
expect(field.schema).toEqual(schema);
129133
expect(field.data_type).toEqual(schema.data_type);
130-
131134
});
132135
it("should use custom Field instance if internal flag is set", () => {
133-
const fieldInstance = jest.fn();
134-
entry = new Entry(
135-
// @ts-ignore
136-
{ data: testData },
137-
connection,
138-
emitter,
139-
{
140-
_internalFlags: {
141-
FieldInstance: fieldInstance,
142-
},
143-
}
144-
);
136+
const fieldInstance: any = jest.fn();
137+
entry = new Entry(testData as any, connection as any, emitter, {
138+
_internalFlags: {
139+
FieldInstance: fieldInstance,
140+
},
141+
});
145142

146143
entry.getField("title");
147144

@@ -175,15 +172,15 @@ describe("Entry", () => {
175172
it("getField within Create page", function () {
176173
const dataWithoutEntry = JSON.parse(JSON.stringify(testData));
177174
dataWithoutEntry.entry = {};
178-
// @ts-ignore
179-
entry = new Entry({ data: dataWithoutEntry }, connection, emitter);
175+
entry = new Entry(dataWithoutEntry, connection as any, emitter);
180176
expect(() => entry.getField("invaliduid")).toThrowError(
181177
"The data is unsaved. Save the data before requesting the field."
182178
);
183179
});
184180

185181
it("onSave Callback must be a function", function () {
186-
// @ts-ignore
187-
expect(() => entry.onSave()).toThrow("Callback must be a function");
182+
expect(() => (entry as any).onSave()).toThrow(
183+
"Callback must be a function"
184+
);
188185
});
189-
});
186+
});

0 commit comments

Comments
 (0)