Skip to content

Commit

Permalink
Merge pull request #76 from contentstack/develop
Browse files Browse the repository at this point in the history
v1.6.0
  • Loading branch information
Kaushik Shetty authored Jul 7, 2023
2 parents efa55a5 + bea67e7 commit 0a03e77
Show file tree
Hide file tree
Showing 20 changed files with 251 additions and 8,162 deletions.
100 changes: 98 additions & 2 deletions __test__/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,61 @@ import Extension from "../src/extension";
import { IAppConfigInitData, Region } from "../src/types";

jest.mock("post-robot", () => ({
sendToParent: jest.fn(),
on: jest.fn(),
__esModule: true,
default: {
on: jest.fn(),
sendToParent: jest
.fn()
.mockReturnValue(Promise.resolve({ data: { version: 90 } })),
},
}));

const manifest = {
created_by: {
uid: "string",
first_name: "string",
last_name: "string",
},
icon: "string",
name: "string",
target_type: "string",
uid: "string",
updated_by: {
uid: "string",
first_name: "string",
last_name: "string",
},
version: 5,
visibility: "string",
};

const initData: IAppConfigInitData = {
data: {
type: "APP_CONFIG_WIDGET",
app_id: "app_id",
installation_uid: "installation_uid",
extension_uid: "extension_uid",
region: "NA",
stack: {
created_at: "created_at",
updated_at: "updated_at",
uid: "uid",
org_uid: "org_uid",
api_key: "api_key",
master_locale: "master_locale",
is_asset_download_public: true,
owner_uid: "owner_uid",
user_uids: ["user_uids"],
settings: {},
name: "name",
},
user: {},
currentBranch: "currentBranch",
manifest: manifest,
},
};

const initDataWithoutManifest: IAppConfigInitData = {
data: {
type: "APP_CONFIG_WIDGET",
app_id: "app_id",
Expand All @@ -33,6 +83,27 @@ const initData: IAppConfigInitData = {
},
};

const initDataJsonRte = {
data: {
type: "RTE",
region: "NA",
stack: {
created_at: "created_at",
updated_at: "updated_at",
uid: "uid",
org_uid: "org_uid",
api_key: "api_key",
master_locale: "master_locale",
is_asset_download_public: true,
owner_uid: "owner_uid",
user_uids: ["user_uids"],
settings: {},
name: "name",
},
user: {},
},
};

describe("Extension", () => {
afterEach(() => {
window["postRobot"] = undefined;
Expand Down Expand Up @@ -83,4 +154,29 @@ describe("Extension", () => {
expect(region).toBe(Region.NA);
});
});

describe("getAppVersion", () => {
it("should have getAppVersion method", () => {
const extensionObj = new Extension(initData);
expect(extensionObj.getAppVersion).toBeDefined();
});

it("should return an app version when invoked", async () => {
const extensionObj = new Extension(initData);
const version = await extensionObj.getAppVersion();
expect(version).toBe(5);
});

it("should return null when installation uid is not present", async () => {
const extensionObj = new Extension(initDataJsonRte as any);
const version = await extensionObj.getAppVersion();
expect(version).toBe(null);
});

it("should fetch the app version for parent using post robot", async () => {
const extensionObj = new Extension(initDataWithoutManifest);
const version = await extensionObj.getAppVersion();
expect(version).toBe(90);
});
});
});
18 changes: 18 additions & 0 deletions __test__/fieldModifierLocation/frame.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,22 @@ describe("FieldModifierLocationFrame", () => {
expect(sendToParent).toHaveBeenLastCalledWith("closeModal");
});
});

describe("preventFrameClose", () => {
it("should not allow user to close frame by clicking background", async () => {
await frameInstance.preventFrameClose(true);
expect(sendToParent).toHaveBeenCalledTimes(1);
expect(sendToParent).toHaveBeenLastCalledWith("preventFrameClose", {
state: true,
});
});

it("should allow user to close frame by clicking background", async () => {
await frameInstance.preventFrameClose(false);
expect(sendToParent).toHaveBeenCalledTimes(1);
expect(sendToParent).toHaveBeenLastCalledWith("preventFrameClose", {
state: false,
});
});
});
});
Loading

0 comments on commit 0a03e77

Please sign in to comment.