Skip to content

Commit f40a1ce

Browse files
Merge branch 'VE-6750/redirection-url-without-query-string-vb' of https://github.com/contentstack/live-preview-sdk into VE-6750/redirection-url-without-query-string-vb
2 parents 95c1c02 + a1ade92 commit f40a1ce

3 files changed

Lines changed: 89 additions & 115 deletions

File tree

.talismanrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fileignoreconfig:
1111
- filename: src/visualBuilder/components/Collab/ThreadPopup/__test__/CommentTextArea.test.tsx
1212
checksum: d0ef271ee5381d9feab06bda6e7e89bd0a882fee87495627bd811c1f0a5459c7
1313
- filename: src/visualBuilder/utils/__test__/getVisualBuilderRedirectionUrl.test.ts
14-
checksum: c50dc0a34b3aeb8ff50ac36af38e4ace9b6ee137522faa3d82ae2309ee285040
14+
checksum: 136be2b65e28df8a0fec100cb0f2dfb735341162038f46b5492c803771b58d55
1515
- filename: package-lock.json
1616
checksum: fd06363871d0ee16ebfb5d9d0cc479e0922a615bb76584b80bb6933ee6c3e237
1717
- filename: src/visualBuilder/components/FieldLocationIcon.tsx
Lines changed: 46 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import { render, fireEvent, screen } from "@testing-library/preact";
2-
import StartEditingButtonComponent, {
3-
getEditButtonPosition,
4-
} from "../startEditingButton";
2+
import StartEditingButtonComponent, { getEditButtonPosition } from "../startEditingButton";
53
import Config from "../../../configManager/configManager";
64
import { asyncRender } from "../../../__test__/utils";
75

86
describe("StartEditingButtonComponent", () => {
97
let visualBuilderContainer: HTMLDivElement;
108

119
beforeEach(() => {
12-
document.getElementsByTagName("html")[0].innerHTML = "";
10+
document.getElementsByTagName('html')[0].innerHTML = '';
1311
Config.reset();
1412
Config.set("stackDetails.apiKey", "bltapikey");
1513
Config.set("stackDetails.environment", "bltenvironment");
@@ -40,9 +38,7 @@ describe("StartEditingButtonComponent", () => {
4038
});
4139

4240
test("should update the href when clicked", async () => {
43-
const { getByTestId } = await asyncRender(
44-
<StartEditingButtonComponent />
45-
);
41+
const { getByTestId } = await asyncRender(<StartEditingButtonComponent />);
4642
const button = getByTestId("vcms-start-editing-btn");
4743

4844
expect(button?.getAttribute("href")).toBe(
@@ -52,108 +48,93 @@ describe("StartEditingButtonComponent", () => {
5248

5349
test("should not render when enable is false", async () => {
5450
Config.set("editInVisualBuilderButton.enable", false);
55-
const { container } = await asyncRender(
56-
<StartEditingButtonComponent />
57-
);
51+
const { container } = await asyncRender(<StartEditingButtonComponent />);
5852
expect(container).toBeEmptyDOMElement();
5953
});
6054

6155
test("should render when enable is true", async () => {
6256
Config.set("editInVisualBuilderButton.enable", true);
63-
const { getByTestId } = await asyncRender(
64-
<StartEditingButtonComponent />
65-
);
57+
const { getByTestId } = await asyncRender(<StartEditingButtonComponent />);
6658
const button = getByTestId("vcms-start-editing-btn");
6759
expect(button).toBeInTheDocument();
6860
});
6961

70-
test.each(["bottom-right", "bottom-left", "top-left", "top-right"])(
71-
"should return valid position %s",
72-
(position) => {
73-
expect(getEditButtonPosition(position)).toBe(position);
74-
}
75-
);
62+
test.each([
63+
'bottom-right',
64+
'bottom-left',
65+
'top-left',
66+
'top-right'
67+
])('should return valid position %s', (position) => {
68+
expect(getEditButtonPosition(position)).toBe(position);
69+
});
7670

7771
test.each([
78-
"invalid-position",
79-
"center",
80-
"",
72+
'invalid-position',
73+
'center',
74+
'',
8175
undefined,
8276
null,
8377
123,
8478
{},
8579
[],
8680
false,
87-
])(
88-
"should return bottom-right for invalid input: %s",
89-
(invalidPosition) => {
90-
expect(getEditButtonPosition(invalidPosition)).toBe("bottom-right");
91-
}
92-
);
93-
81+
])('should return bottom-right for invalid input: %s', (invalidPosition) => {
82+
expect(getEditButtonPosition(invalidPosition)).toBe('bottom-right');
83+
});
84+
9485
test("should render with default values when editInVisualBuilderButton config is missing", async () => {
9586
Config.reset();
9687
Config.set("stackDetails.apiKey", "bltapikey");
9788
Config.set("stackDetails.environment", "bltenvironment");
9889

99-
const { getByTestId } = await asyncRender(
100-
<StartEditingButtonComponent />
101-
);
90+
const { getByTestId } = await asyncRender(<StartEditingButtonComponent />);
10291
const button = getByTestId("vcms-start-editing-btn");
103-
104-
expect(Config.get().editInVisualBuilderButton.position).toBe(
105-
"bottom-right"
106-
);
92+
93+
expect(Config.get().editInVisualBuilderButton.position).toBe("bottom-right")
10794
expect(button).toBeInTheDocument();
10895
});
10996

11097
test("should update href with current URL when mouse enters button", async () => {
111-
Object.defineProperty(window, "location", {
112-
value: new URL("http://localhost:3000"),
98+
Object.defineProperty(window, 'location', {
99+
value: new URL('http://localhost:3000'),
113100
});
114-
115-
const { getByTestId } = await asyncRender(
116-
<StartEditingButtonComponent />
117-
);
101+
102+
const { getByTestId } = await asyncRender(<StartEditingButtonComponent />);
118103
const button = getByTestId("vcms-start-editing-btn");
119104
const initialHref = button.getAttribute("href");
120-
121-
Object.defineProperty(window, "location", {
122-
value: new URL("http://localhost:3000/about"),
123-
writable: true,
105+
106+
Object.defineProperty(window, 'location', {
107+
value: new URL('http://localhost:3000/about'),
108+
writable: true
124109
});
125110

126111
fireEvent.mouseEnter(button);
127-
112+
128113
const updatedHref = button.getAttribute("href");
129114
expect(updatedHref).not.toBe(initialHref);
130-
expect(updatedHref).toContain(
131-
encodeURIComponent("http://localhost:3000/about")
132-
);
115+
expect(updatedHref).toContain(encodeURIComponent("http://localhost:3000/about"));
133116
});
134117

135118
test("should update href with current URL when button is focused", async () => {
136-
Object.defineProperty(window, "location", {
137-
value: new URL("http://localhost:3000"),
119+
Object.defineProperty(window, 'location', {
120+
value: new URL('http://localhost:3000'),
138121
});
139-
140-
const { getByTestId } = await asyncRender(
141-
<StartEditingButtonComponent />
142-
);
122+
123+
const { getByTestId } = await asyncRender(<StartEditingButtonComponent />);
143124
const button = getByTestId("vcms-start-editing-btn");
144125
const initialHref = button.getAttribute("href");
145-
146-
Object.defineProperty(window, "location", {
147-
value: new URL("http://localhost:3000/contact"),
148-
writable: true,
126+
127+
Object.defineProperty(window, 'location', {
128+
value: new URL('http://localhost:3000/contact'),
129+
writable: true
149130
});
150131

151132
fireEvent.focus(button);
152-
133+
153134
const updatedHref = button.getAttribute("href");
154135
expect(updatedHref).not.toBe(initialHref);
155-
expect(updatedHref).toContain(
156-
encodeURIComponent("http://localhost:3000/contact")
157-
);
136+
expect(updatedHref).toContain(encodeURIComponent("http://localhost:3000/contact"));
158137
});
159-
});
138+
139+
140+
});

src/visualBuilder/utils/__test__/getVisualBuilderRedirectionUrl.test.ts

Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
import { describe, it, expect, vi } from "vitest";
2-
import getVisualBuilderRedirectionUrl from "../getVisualBuilderRedirectionUrl";
3-
import Config from "../../../configManager/configManager";
4-
import { extractDetailsFromCslp } from "../../../cslp";
1+
import { describe, it, expect, vi } from 'vitest';
2+
import getVisualBuilderRedirectionUrl from '../getVisualBuilderRedirectionUrl';
3+
import Config from '../../../configManager/configManager';
4+
import { extractDetailsFromCslp } from '../../../cslp';
55

6-
vi.mock("../../../configManager/configManager");
7-
vi.mock("../../../cslp");
6+
vi.mock('../../../configManager/configManager');
7+
vi.mock('../../../cslp');
88

9-
describe("getVisualBuilderRedirectionUrl", () => {
9+
describe('getVisualBuilderRedirectionUrl', () => {
1010
beforeEach(() => {
1111
vi.clearAllMocks();
12-
delete window.location;
13-
window.location = new URL("https://example.com");
12+
delete window.location
13+
window.location = new URL('https://example.com')
1414
});
1515

16-
it("should return the correct URL with branch and environment", () => {
16+
it('should return the correct URL with branch and environment', () => {
1717
Config.get.mockReturnValue({
1818
stackDetails: {
19-
branch: "main",
20-
apiKey: "12345",
21-
environment: "production",
22-
locale: "en-US",
19+
branch: 'main',
20+
apiKey: '12345',
21+
environment: 'production',
22+
locale: 'en-US'
2323
},
2424
clientUrlParams: {
25-
url: "https://app.example.com",
26-
},
25+
url: 'https://app.example.com'
26+
}
2727
});
2828

2929
const result = getVisualBuilderRedirectionUrl();
@@ -32,67 +32,60 @@ describe("getVisualBuilderRedirectionUrl", () => {
3232
);
3333
});
3434

35-
it("should return the correct URL without branch and environment", () => {
35+
it('should return the correct URL without branch and environment', () => {
3636
Config.get.mockReturnValue({
3737
stackDetails: {
38-
branch: "",
39-
apiKey: "12345",
40-
environment: "",
41-
locale: "en-US",
38+
branch: '',
39+
apiKey: '12345',
40+
environment: '',
41+
locale: 'en-US'
4242
},
4343
clientUrlParams: {
44-
url: "https://app.example.com",
45-
},
44+
url: 'https://app.example.com'
45+
}
4646
});
4747

4848
const result = getVisualBuilderRedirectionUrl();
49-
expect(result.toString()).toBe(
50-
"https://app.example.com/#!/stack/12345/visual-builder?target-url=https%3A%2F%2Fexample.com&locale=en-US"
51-
);
49+
expect(result.toString()).toBe('https://app.example.com/#!/stack/12345/visual-builder?target-url=https%3A%2F%2Fexample.com&locale=en-US');
5250
});
5351

54-
it("should use locale from data-cslp attribute if present", () => {
52+
it('should use locale from data-cslp attribute if present', () => {
5553
document.body.innerHTML = '<div data-cslp="some-cslp-data"></div>';
5654
Config.get.mockReturnValue({
5755
stackDetails: {
58-
branch: "main",
59-
apiKey: "12345",
60-
environment: "production",
61-
locale: "en-US",
56+
branch: 'main',
57+
apiKey: '12345',
58+
environment: 'production',
59+
locale: 'en-US'
6260
},
6361
clientUrlParams: {
64-
url: "https://app.example.com",
65-
},
62+
url: 'https://app.example.com'
63+
}
6664
});
6765

68-
extractDetailsFromCslp.mockReturnValue({ locale: "fr-FR" });
66+
extractDetailsFromCslp.mockReturnValue({ locale: 'fr-FR' });
6967

7068
const result = getVisualBuilderRedirectionUrl();
71-
expect(result.toString()).toBe(
72-
"https://app.example.com/#!/stack/12345/visual-builder?target-url=https%3A%2F%2Fexample.com&branch=main&environment=production&locale=fr-FR"
73-
);
69+
expect(result.toString()).toBe('https://app.example.com/#!/stack/12345/visual-builder?target-url=https%3A%2F%2Fexample.com&branch=main&environment=production&locale=fr-FR');
7470
});
7571

76-
it("should return the correct URL without locale", () => {
77-
document.body.innerHTML = "";
72+
it('should return the correct URL without locale', () => {
73+
document.body.innerHTML = '';
7874
Config.get.mockReturnValue({
7975
stackDetails: {
80-
branch: "main",
81-
apiKey: "12345",
82-
environment: "production",
83-
locale: "",
76+
branch: 'main',
77+
apiKey: '12345',
78+
environment: 'production',
79+
locale: ''
8480
},
8581
clientUrlParams: {
86-
url: "https://app.example.com",
87-
},
82+
url: 'https://app.example.com'
83+
}
8884
});
8985

9086
const result = getVisualBuilderRedirectionUrl();
91-
expect(result.toString()).toBe(
92-
"https://app.example.com/#!/stack/12345/visual-builder?target-url=https%3A%2F%2Fexample.com&branch=main&environment=production"
93-
);
87+
expect(result.toString()).toBe('https://app.example.com/#!/stack/12345/visual-builder?target-url=https%3A%2F%2Fexample.com&branch=main&environment=production');
9488
});
95-
9689
it("should return the correct URL without query parameters in target-url", () => {
9790
Object.defineProperty(window, "location", {
9891
writable: true,

0 commit comments

Comments
 (0)