Skip to content

Commit 0a03e77

Browse files
author
Kaushik Shetty
authored
Merge pull request #76 from contentstack/develop
v1.6.0
2 parents efa55a5 + bea67e7 commit 0a03e77

File tree

20 files changed

+251
-8162
lines changed

20 files changed

+251
-8162
lines changed

__test__/extension.test.ts

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,61 @@ import Extension from "../src/extension";
44
import { IAppConfigInitData, Region } from "../src/types";
55

66
jest.mock("post-robot", () => ({
7-
sendToParent: jest.fn(),
8-
on: jest.fn(),
7+
__esModule: true,
8+
default: {
9+
on: jest.fn(),
10+
sendToParent: jest
11+
.fn()
12+
.mockReturnValue(Promise.resolve({ data: { version: 90 } })),
13+
},
914
}));
1015

16+
const manifest = {
17+
created_by: {
18+
uid: "string",
19+
first_name: "string",
20+
last_name: "string",
21+
},
22+
icon: "string",
23+
name: "string",
24+
target_type: "string",
25+
uid: "string",
26+
updated_by: {
27+
uid: "string",
28+
first_name: "string",
29+
last_name: "string",
30+
},
31+
version: 5,
32+
visibility: "string",
33+
};
34+
1135
const initData: IAppConfigInitData = {
36+
data: {
37+
type: "APP_CONFIG_WIDGET",
38+
app_id: "app_id",
39+
installation_uid: "installation_uid",
40+
extension_uid: "extension_uid",
41+
region: "NA",
42+
stack: {
43+
created_at: "created_at",
44+
updated_at: "updated_at",
45+
uid: "uid",
46+
org_uid: "org_uid",
47+
api_key: "api_key",
48+
master_locale: "master_locale",
49+
is_asset_download_public: true,
50+
owner_uid: "owner_uid",
51+
user_uids: ["user_uids"],
52+
settings: {},
53+
name: "name",
54+
},
55+
user: {},
56+
currentBranch: "currentBranch",
57+
manifest: manifest,
58+
},
59+
};
60+
61+
const initDataWithoutManifest: IAppConfigInitData = {
1262
data: {
1363
type: "APP_CONFIG_WIDGET",
1464
app_id: "app_id",
@@ -33,6 +83,27 @@ const initData: IAppConfigInitData = {
3383
},
3484
};
3585

86+
const initDataJsonRte = {
87+
data: {
88+
type: "RTE",
89+
region: "NA",
90+
stack: {
91+
created_at: "created_at",
92+
updated_at: "updated_at",
93+
uid: "uid",
94+
org_uid: "org_uid",
95+
api_key: "api_key",
96+
master_locale: "master_locale",
97+
is_asset_download_public: true,
98+
owner_uid: "owner_uid",
99+
user_uids: ["user_uids"],
100+
settings: {},
101+
name: "name",
102+
},
103+
user: {},
104+
},
105+
};
106+
36107
describe("Extension", () => {
37108
afterEach(() => {
38109
window["postRobot"] = undefined;
@@ -83,4 +154,29 @@ describe("Extension", () => {
83154
expect(region).toBe(Region.NA);
84155
});
85156
});
157+
158+
describe("getAppVersion", () => {
159+
it("should have getAppVersion method", () => {
160+
const extensionObj = new Extension(initData);
161+
expect(extensionObj.getAppVersion).toBeDefined();
162+
});
163+
164+
it("should return an app version when invoked", async () => {
165+
const extensionObj = new Extension(initData);
166+
const version = await extensionObj.getAppVersion();
167+
expect(version).toBe(5);
168+
});
169+
170+
it("should return null when installation uid is not present", async () => {
171+
const extensionObj = new Extension(initDataJsonRte as any);
172+
const version = await extensionObj.getAppVersion();
173+
expect(version).toBe(null);
174+
});
175+
176+
it("should fetch the app version for parent using post robot", async () => {
177+
const extensionObj = new Extension(initDataWithoutManifest);
178+
const version = await extensionObj.getAppVersion();
179+
expect(version).toBe(90);
180+
});
181+
});
86182
});

__test__/fieldModifierLocation/frame.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,22 @@ describe("FieldModifierLocationFrame", () => {
185185
expect(sendToParent).toHaveBeenLastCalledWith("closeModal");
186186
});
187187
});
188+
189+
describe("preventFrameClose", () => {
190+
it("should not allow user to close frame by clicking background", async () => {
191+
await frameInstance.preventFrameClose(true);
192+
expect(sendToParent).toHaveBeenCalledTimes(1);
193+
expect(sendToParent).toHaveBeenLastCalledWith("preventFrameClose", {
194+
state: true,
195+
});
196+
});
197+
198+
it("should allow user to close frame by clicking background", async () => {
199+
await frameInstance.preventFrameClose(false);
200+
expect(sendToParent).toHaveBeenCalledTimes(1);
201+
expect(sendToParent).toHaveBeenLastCalledWith("preventFrameClose", {
202+
state: false,
203+
});
204+
});
205+
});
188206
});

0 commit comments

Comments
 (0)