|
1 | 1 | import { render, fireEvent, screen } from "@testing-library/preact"; |
2 | | -import StartEditingButtonComponent from "../startEditingButton"; |
| 2 | +import StartEditingButtonComponent, { getEditButtonPosition } from "../startEditingButton"; |
3 | 3 | import Config from "../../../configManager/configManager"; |
4 | 4 | import { asyncRender } from "../../../__test__/utils"; |
5 | 5 |
|
@@ -45,4 +45,52 @@ describe("StartEditingButtonComponent", () => { |
45 | 45 | "https://app.contentstack.com/#!/stack/bltapikey/visual-builder?branch=main&environment=bltenvironment&target-url=http%3A%2F%2Flocalhost%3A3000%2F&locale=en-us" |
46 | 46 | ); |
47 | 47 | }); |
| 48 | + |
| 49 | + test("should not render when enable is false", async () => { |
| 50 | + Config.set("editButtonBuilder.enable", false); |
| 51 | + const { container } = await asyncRender(<StartEditingButtonComponent />); |
| 52 | + expect(container).toBeEmptyDOMElement(); |
| 53 | + }); |
| 54 | + |
| 55 | + test("should render when enable is true", async () => { |
| 56 | + Config.set("editButtonBuilder.enable", true); |
| 57 | + const { getByTestId } = await asyncRender(<StartEditingButtonComponent />); |
| 58 | + const button = getByTestId("vcms-start-editing-btn"); |
| 59 | + expect(button).toBeInTheDocument(); |
| 60 | + }); |
| 61 | + |
| 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 | + }); |
| 70 | + |
| 71 | + test.each([ |
| 72 | + 'invalid-position', |
| 73 | + 'center', |
| 74 | + '', |
| 75 | + undefined, |
| 76 | + null, |
| 77 | + 123, |
| 78 | + {}, |
| 79 | + [], |
| 80 | + false, |
| 81 | + ])('should return bottom-right for invalid input: %s', (invalidPosition) => { |
| 82 | + expect(getEditButtonPosition(invalidPosition)).toBe('bottom-right'); |
| 83 | + }); |
| 84 | + |
| 85 | + test("should render with default values when editButtonBuilder config is missing", async () => { |
| 86 | + Config.reset(); |
| 87 | + Config.set("stackDetails.apiKey", "bltapikey"); |
| 88 | + Config.set("stackDetails.environment", "bltenvironment"); |
| 89 | + |
| 90 | + const { getByTestId } = await asyncRender(<StartEditingButtonComponent />); |
| 91 | + const button = getByTestId("vcms-start-editing-btn"); |
| 92 | + |
| 93 | + expect(Config.get().editButtonBuilder.position).toBe("bottom-right") |
| 94 | + expect(button).toBeInTheDocument(); |
| 95 | + }); |
48 | 96 | }); |
0 commit comments