-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerateStartEditingButton.test.ts
More file actions
63 lines (49 loc) · 2.02 KB
/
generateStartEditingButton.test.ts
File metadata and controls
63 lines (49 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { getDefaultConfig } from "../../../configManager/config.default";
import { IConfig } from "../../../types/types";
import { generateStartEditingButton } from "./../../generators/generateStartEditingButton";
describe("generateStartEditingButton", () => {
let config: IConfig;
beforeEach(() => {
config = getDefaultConfig();
config.stackDetails.apiKey = "bltapikey";
config.stackDetails.environment = "bltenvironment";
});
afterEach(() => {
vi.clearAllMocks();
const existingButton = document.querySelector(
".visual-builder__start-editing-btn"
);
if (existingButton) {
existingButton.remove();
}
});
test("should return an anchor tag", () => {
const button = generateStartEditingButton();
expect(button).toBeInstanceOf(HTMLAnchorElement);
});
test("should append the button within document.body", () => {
const initialBodyChildren = document.body.children.length;
generateStartEditingButton();
expect(document.body.children.length).toBe(initialBodyChildren + 1);
});
test("should update the href when clicked", () => {
const button = generateStartEditingButton();
button?.click();
expect(button?.getAttribute("href")).toBe(
"https://app.contentstack.com/#!/stack//visual-editor?branch=main&target-url=http%3A%2F%2Flocalhost%3A3000%2F&locale=en-us"
);
});
test("should get the href detail from cslp attribute if present", () => {
const h1 = document.createElement("h1");
h1.setAttribute(
"data-cslp",
"all_fields.blt58a50b4cebae75c5.en-us.single_line"
);
document.body.appendChild(h1);
const button = generateStartEditingButton();
button?.click();
expect(button?.getAttribute("href")).toBe(
"https://app.contentstack.com/#!/stack//visual-editor?branch=main&target-url=http%3A%2F%2Flocalhost%3A3000%2F&locale=en-us"
);
});
});