Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EB-1565: Sidebar sometimes load and sometimes doesn't #117

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/liveEditor/generators/__test__/generateToolbar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ describe("appendFieldPathDropdown", () => {
expect(fieldLabelWrapper?.classList.toString()).toBe(
"visual-editor__focused-toolbar__field-label-wrapper"
);

console.log(fieldLabelWrapper?.classList.toString());
});

test("should click the closest parent if focused toolbar is a parent field", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/liveEditor/generators/generateToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function appendFieldPathDropdown(

focusedToolbarElement.addEventListener("click", (e) => {
e.preventDefault();

if (
(e.target as Element).classList.contains("visual-editor__tooltip")
) {
Expand All @@ -100,7 +100,7 @@ export function appendFieldPathDropdown(
) as string;
const parentElement = targetElement.closest(
`[${DATA_CSLP_ATTR_SELECTOR}="${cslp}"]`
) as HTMLElement;
) as HTMLElement;
if (parentElement) {
parentElement.click();
}
Expand Down
23 changes: 17 additions & 6 deletions src/liveEditor/utils/__test__/focusOverlayWrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ describe("hideFocusOverlay", () => {
bottom: 20,
})) as any;

visualEditorContainer.appendChild(editedElement);
document.body.appendChild(editedElement);

singleFocusOverlay = focusOverlayWrapper.querySelector(
`[data-testid="visual-editor__overlay--top"]`
Expand Down Expand Up @@ -225,20 +225,31 @@ describe("hideFocusOverlay", () => {
expect(focusOverlayWrapper.classList.contains("visible")).toBe(true);
});

// TODO
test("should send update field event to the parent if the focused element is an inline editable element", () => {
test("should send update field event to the parent if the focused element is an inline editable element", async () => {
editedElement.setAttribute("contenteditable", "true");

// We"ll always click one of the overlays, so we can just grab the first one. Manually pointing the global state to the editedElement as we are not simulating mouse click on window here.
VisualEditor.VisualEditorGlobalState.value.previousSelectedEditableDOM =
editedElement;

// already called addFocusOverlay, hence visible is set to true
expect(focusOverlayWrapper.classList.contains("visible")).toBe(true);
fireEvent.click(singleFocusOverlay);
fireEvent.click(singleFocusOverlay);

await fireEvent.change(editedElement, {
target: { innerHTML: "New text" },
});

expect(editedElement.textContent).toBe("New text");

// close the overlay
await fireEvent.click(focusOverlayWrapper);
expect(focusOverlayWrapper.classList.contains("visible")).toBe(false);

expect(liveEditorPostMessage?.send).toHaveBeenCalledTimes(1);
expect(liveEditorPostMessage?.send).toHaveBeenCalledWith(
LiveEditorPostMessageEvents.UPDATE_FIELD,
{
data: editedElement.innerHTML,
data: editedElement.textContent,
fieldMetadata: {
content_type_uid: "all_fields",
cslpValue: "all_fields.blt58a50b4cebae75c5.en-us.title",
Expand Down
13 changes: 5 additions & 8 deletions src/liveEditor/utils/handleIndividualFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,12 @@ export async function handleIndividualFields(

return;
}

liveEditorPostMessage?.send(
LiveEditorPostMessageEvents.OPEN_QUICK_FORM,
{
fieldMetadata: eventDetails.fieldMetadata,
cslpData: eventDetails.cslpData,
}
);
}

liveEditorPostMessage?.send(LiveEditorPostMessageEvents.OPEN_QUICK_FORM, {
fieldMetadata: eventDetails.fieldMetadata,
cslpData: eventDetails.cslpData,
});
}

export function cleanIndividualFieldResidual(elements: {
Expand Down
15 changes: 5 additions & 10 deletions src/livePreview/__test__/live-preview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
HistoryLivePreviewPostMessageEventData,
OnChangeLivePreviewPostMessageEventData,
} from "../eventManager/types/livePreviewPostMessageEvent.type";
import * as postMessageEventHooks from "../eventManager/postMessageEvent.hooks";
import { addLivePreviewQueryTags } from "../../utils";

jest.mock("../../liveEditor/utils/liveEditorPostMessage", () => {
Expand Down Expand Up @@ -473,25 +472,21 @@ describe("testing window event listeners", () => {

test("should attach a load event to call requestDataSync if document is not yet loaded", () => {
Object.defineProperty(document, "readyState", {
value: "loading",
writable: true,
get() {
return "loading";
},
});

Config.replace({
enable: true,
});

sendInitEvent = jest.spyOn(
postMessageEventHooks,
"sendInitializeLivePreviewPostMessageEvent"
);
livePreviewInstance = new LivePreview();

expect(addEventListenerMock).toHaveBeenCalledWith(
expect(addEventListenerMock).toBeCalledWith(
"load",
expect.any(Function)
);
expect(sendInitEvent).toBeCalled();
});

test("should handle link click event if ssr is set to true", async () => {
Expand All @@ -502,7 +497,7 @@ describe("testing window event listeners", () => {

const targetElement = document.createElement("a");
targetElement.href = "http://localhost:3000/";

document.body.appendChild(targetElement);

livePreviewInstance = new LivePreview();
Expand Down