Skip to content

Commit a5d3d96

Browse files
committed
fix: renamed org full page to global full page
1 parent 77e7812 commit a5d3d96

File tree

5 files changed

+121
-83
lines changed

5 files changed

+121
-83
lines changed
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { IOrgFullPageLocationInitData, LocationType } from "../src/types";
1+
import { IGlobalFullPageLocationInitData, LocationType } from "../src/types";
22
import { OrganizationDetails } from "../src/types/organization.types";
33

4-
const mockData: IOrgFullPageLocationInitData = {
5-
type: LocationType.ORGANIZATION_FULL_PAGE,
4+
const mockData: IGlobalFullPageLocationInitData = {
5+
type: LocationType.GLOBAL_FULL_PAGE_LOCATION,
66
app_id: "app_id",
77
installation_uid: "installation_uid",
88
extension_uid: "extension_uid",
99
region: "NA",
10-
endpoints:{CMA:"",APP:"",DEVELOPER_HUB:""},
10+
endpoints: { CMA: "", APP: "", DEVELOPER_HUB: "" },
1111
stack: {} as any,
1212
user: {} as any,
1313
currentBranch: "currentBranch",
@@ -22,16 +22,18 @@ afterEach(() => {
2222
});
2323

2424
test("should return organization details", () => {
25-
expect(organizationFullPage.currentOrganization).toBe(mockData.organization);
25+
expect(organizationFullPage.currentOrganization).toBe(
26+
mockData.organization
27+
);
2628
});
2729

2830
test("should handle missing organization details", () => {
29-
const invalidData: IOrgFullPageLocationInitData = {
31+
const invalidData: IGlobalFullPageLocationInitData = {
3032
...mockData,
3133
organization: null as any, // check missing organization details
3234
};
3335
const invalidOrganizationFullPage = {
3436
currentOrganization: invalidData.organization,
3537
};
3638
expect(invalidOrganizationFullPage.currentOrganization).toBeNull();
37-
});
39+
});

__test__/uiLocation.test.ts

Lines changed: 91 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { AxiosRequestConfig, AxiosResponse } from "axios";
2+
13
import postRobot from "post-robot";
24

35
import UiLocation from "../src/uiLocation";
@@ -12,9 +14,8 @@ import {
1214
LocationType,
1315
Region,
1416
} from "../src/types";
15-
import { RequestOption } from '../src/types/common.types';
16-
import { RequestConfig } from '../src/types/api.type';
17-
import { AxiosRequestConfig, AxiosResponse } from 'axios';
17+
import { RequestOption } from "../src/types/common.types";
18+
import { RequestConfig } from "../src/types/api.type";
1819

1920
jest.mock("post-robot");
2021
jest.mock("wolfy87-eventemitter");
@@ -60,7 +61,11 @@ const initData: IAppConfigInitData = {
6061
installation_uid: "installation_uid",
6162
extension_uid: "extension_uid",
6263
region: "NA",
63-
endpoints: { CMA: "https://api.contentstack.io", APP: "https://app.contentstack.app",DEVELOPER_HUB:"" },
64+
endpoints: {
65+
CMA: "https://api.contentstack.io",
66+
APP: "https://app.contentstack.app",
67+
DEVELOPER_HUB: "",
68+
},
6469
stack: mockStackData,
6570
user: {} as any,
6671
currentBranch: "currentBranch",
@@ -135,43 +140,48 @@ describe("UI Location", () => {
135140
});
136141
});
137142

138-
describe('dispatchPostRobotRequest', () => {
143+
describe("dispatchPostRobotRequest", () => {
139144
let mockPostRobot: typeof postRobot;
140145
let opts: RequestOption;
141146
let uiLocationInstance: UiLocation;
142147
let onError: jest.Mock;
143148

144149
beforeEach(() => {
145150
mockPostRobot = postRobot;
146-
opts = { method: 'GET' };
151+
opts = { method: "GET" };
147152
uiLocationInstance = new UiLocation(initData);
148153
onError = jest.fn();
149154
uiLocationInstance.api = jest.fn().mockResolvedValue({
150-
method: 'GET',
151-
url: "https://test.com/test?limit=10&skip=0"
155+
method: "GET",
156+
url: "https://test.com/test?limit=10&skip=0",
152157
});
153158
});
154159

155-
it('should call sendToParent with the correct arguments and resolve with data', async () => {
160+
it("should call sendToParent with the correct arguments and resolve with data", async () => {
156161
const mockData = { success: true };
157162
// Call the method that uses uiLocationInstance.api
158-
const result = await uiLocationInstance.api("https://test.com/test?limit=10&skip=0",{
159-
method: 'GET'
160-
});
163+
const result = await uiLocationInstance.api(
164+
"https://test.com/test?limit=10&skip=0",
165+
{
166+
method: "GET",
167+
}
168+
);
161169

162170
// Assertions
163-
expect(uiLocationInstance.api).toHaveBeenCalledWith('https://test.com/test?limit=10&skip=0',{
164-
method: 'GET'
165-
});
171+
expect(uiLocationInstance.api).toHaveBeenCalledWith(
172+
"https://test.com/test?limit=10&skip=0",
173+
{
174+
method: "GET",
175+
}
176+
);
166177
expect(result).toEqual({
167-
method: 'GET',
168-
url: 'https://test.com/test?limit=10&skip=0',
178+
method: "GET",
179+
url: "https://test.com/test?limit=10&skip=0",
169180
});
170-
171181
});
172182

173-
it('should call onError if sendToParent rejects', async () => {
174-
const mockError = new Error('Test error');
183+
it("should call onError if sendToParent rejects", async () => {
184+
const mockError = new Error("Test error");
175185

176186
// Mock the api method to reject with an error
177187
uiLocationInstance.api = jest.fn().mockRejectedValue(mockError);
@@ -182,84 +192,102 @@ describe("UI Location", () => {
182192
});
183193

184194
// Call the method that uses uiLocationInstance.api and expect it to throw an error
185-
await expect(uiLocationInstance.api("https://test.com/test?limit=10&skip=0",{
186-
method: 'GET'
187-
})).rejects.toThrow('Test error');
195+
await expect(
196+
uiLocationInstance.api(
197+
"https://test.com/test?limit=10&skip=0",
198+
{
199+
method: "GET",
200+
}
201+
)
202+
).rejects.toThrow("Test error");
188203
});
189204
});
190205

191-
192206
describe("createSDKAdapter", () => {
193207
let mockPostRobot: typeof postRobot;
194208
let opts: RequestConfig;
195209
let uiLocationInstance: UiLocation;
196210
let onError: jest.Mock;
197-
211+
198212
beforeEach(() => {
199213
mockPostRobot = postRobot;
200-
opts = { method: 'GET', baseURL: "https://test.com", url: "/test?limit10&skip=0" };
214+
opts = {
215+
method: "GET",
216+
baseURL: "https://test.com",
217+
url: "/test?limit10&skip=0",
218+
};
201219
uiLocationInstance = new UiLocation(initData);
202220
onError = jest.fn();
203-
uiLocationInstance.createAdapter = jest.fn().mockImplementation(() => async (config: AxiosRequestConfig) => {
204-
return {
205-
method: 'GET',
206-
url: '/test?limit=10&skip=0',
207-
baseURL: 'https://test.com',
208-
data: {}
209-
} as unknown as AxiosResponse;
210-
});
221+
uiLocationInstance.createAdapter = jest
222+
.fn()
223+
.mockImplementation(
224+
() => async (config: AxiosRequestConfig) => {
225+
return {
226+
method: "GET",
227+
url: "/test?limit=10&skip=0",
228+
baseURL: "https://test.com",
229+
data: {},
230+
} as unknown as AxiosResponse;
231+
}
232+
);
211233
});
212-
234+
213235
afterEach(() => {
214236
postRobotOnMock.mockClear();
215237
postRobotSendToParentMock.mockClear();
216-
238+
217239
jest.clearAllMocks();
218240
window["postRobot"] = undefined;
219241
window["iframeRef"] = undefined;
220242
});
221-
222-
it('should call createAdapter with the correct arguments and resolve with data', async () => {
243+
244+
it("should call createAdapter with the correct arguments and resolve with data", async () => {
223245
const mockData = { success: true };
224246
// Call the method that uses uiLocationInstance.createAdapter
225247
const result = await uiLocationInstance.createAdapter()({
226-
method: 'GET',
227-
url: '/test?limit=10&skip=0',
228-
baseURL: 'https://test.com',
229-
data: {}
248+
method: "GET",
249+
url: "/test?limit=10&skip=0",
250+
baseURL: "https://test.com",
251+
data: {},
230252
});
231-
253+
232254
expect(result).toEqual({
233-
method: 'GET',
234-
url: '/test?limit=10&skip=0',
235-
baseURL: 'https://test.com',
236-
data: {}
255+
method: "GET",
256+
url: "/test?limit=10&skip=0",
257+
baseURL: "https://test.com",
258+
data: {},
237259
});
238260
});
239-
240-
it('should call onError if createAdapter rejects', async () => {
241-
const mockError = new Error('Test error');
242-
261+
262+
it("should call onError if createAdapter rejects", async () => {
263+
const mockError = new Error("Test error");
264+
243265
// Mock the createAdapter method to reject with an error
244-
uiLocationInstance.createAdapter = jest.fn().mockImplementation(() => async (config: AxiosRequestConfig) => {
245-
throw mockError;
246-
});
247-
266+
uiLocationInstance.createAdapter = jest
267+
.fn()
268+
.mockImplementation(
269+
() => async (config: AxiosRequestConfig) => {
270+
throw mockError;
271+
}
272+
);
273+
248274
// Mock the onError implementation
249275
onError.mockImplementation((error) => {
250276
throw error;
251277
});
252-
278+
253279
// Call the method that uses uiLocationInstance.createAdapter and expect it to throw an error
254-
await expect(uiLocationInstance.createAdapter()({
255-
method: 'GET',
256-
url: '/test?limit=10&skip=0',
257-
baseURL: 'https://test.com',
258-
data: {}
259-
})).rejects.toThrow('Test error');
280+
await expect(
281+
uiLocationInstance.createAdapter()({
282+
method: "GET",
283+
url: "/test?limit=10&skip=0",
284+
baseURL: "https://test.com",
285+
data: {},
286+
})
287+
).rejects.toThrow("Test error");
260288
});
261289
});
262-
290+
263291
describe("getConfig", () => {
264292
it("should return config if no installation uid present", async () => {
265293
const uiLocation = new UiLocation(initDataJsonRte as any);

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/types.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { GenericObjectType } from "./types/common.types";
77
import { Entry } from "./types/entry.types";
88
import { Asset, ContentType, Schema, StackDetail } from "./types/stack.types";
99
import { OrganizationDetails } from "./types/organization.types";
10-
import { ContentstackEndpoints } from './types/api.type';
10+
import { ContentstackEndpoints } from "./types/api.type";
1111
import { User } from "./types/user.types";
1212
import Window from "./window";
1313

@@ -69,7 +69,7 @@ export declare interface IAppConfigWidget {
6969
stack: Stack;
7070
}
7171

72-
export declare interface IOrgFullPageLocation {
72+
export declare interface IGlobalFullPageLocation {
7373
currentOrganization: OrganizationDetails;
7474
}
7575

@@ -88,7 +88,7 @@ export enum LocationType {
8888
RTE = "RTE",
8989
WIDGET = "WIDGET",
9090
CONTENT_TYPE_SIDEBAR_WIDGET = "CONTENT_TYPE_SIDEBAR_WIDGET",
91-
ORGANIZATION_FULL_PAGE = "ORGANIZATION_FULL_PAGE",
91+
GLOBAL_FULL_PAGE_LOCATION = "GLOBAL_FULL_PAGE_LOCATION",
9292
}
9393

9494
// Init data
@@ -106,10 +106,11 @@ declare interface ICommonInitData {
106106
endpoints: ContentstackEndpoints;
107107
}
108108

109-
export declare interface IOrgFullPageLocationInitData extends ICommonInitData {
109+
export declare interface IGlobalFullPageLocationInitData
110+
extends ICommonInitData {
110111
organization: OrganizationDetails;
111112
config?: GenericObjectType;
112-
type: LocationType.ORGANIZATION_FULL_PAGE;
113+
type: LocationType.GLOBAL_FULL_PAGE_LOCATION;
113114
}
114115

115116
export declare interface IDashboardInitData extends ICommonInitData {
@@ -217,7 +218,7 @@ export type InitializationData =
217218
| IRTEInitData
218219
| ISidebarInitData
219220
| IContentTypeSidebarInitData
220-
| IOrgFullPageLocationInitData;
221+
| IGlobalFullPageLocationInitData;
221222

222223
/**
223224
* installation details API response
@@ -259,4 +260,11 @@ export enum Region {
259260
GCP_EU = "GCP_EU",
260261
}
261262

262-
export type RegionType = "UNKNOWN" | "NA" | "EU" | "AZURE_NA" | "AZURE_EU" | "GCP_NA" | string;
263+
export type RegionType =
264+
| "UNKNOWN"
265+
| "NA"
266+
| "EU"
267+
| "AZURE_NA"
268+
| "AZURE_EU"
269+
| "GCP_NA"
270+
| string;

src/uiLocation.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
InitializationData,
2828
LocationType,
2929
Manifest,
30-
IOrgFullPageLocation,
30+
IGlobalFullPageLocation,
3131
RegionType,
3232
} from "./types";
3333
import { GenericObjectType } from "./types/common.types";
@@ -132,7 +132,7 @@ class UiLocation {
132132
FullPage: IFullPageLocation | null;
133133
FieldModifierLocation: IFieldModifierLocation | null;
134134
ContentTypeSidebarWidget: ContentTypeSidebarWidget | null;
135-
OrganizationFullPage: IOrgFullPageLocation | null;
135+
GlobalFullPageLocation: IGlobalFullPageLocation | null;
136136
};
137137

138138
constructor(initData: InitializationData) {
@@ -180,7 +180,7 @@ class UiLocation {
180180
FullPage: null,
181181
FieldModifierLocation: null,
182182
ContentTypeSidebarWidget: null,
183-
OrganizationFullPage: null,
183+
GlobalFullPageLocation: null,
184184
};
185185

186186
window["postRobot"] = postRobot;
@@ -289,8 +289,8 @@ class UiLocation {
289289
break;
290290
}
291291

292-
case LocationType.ORGANIZATION_FULL_PAGE: {
293-
this.location.OrganizationFullPage = {
292+
case LocationType.GLOBAL_FULL_PAGE_LOCATION: {
293+
this.location.GlobalFullPageLocation = {
294294
currentOrganization: initializationData.organization,
295295
};
296296
break;

0 commit comments

Comments
 (0)