diff --git a/app/assets/javascripts/alchemy/admin.js b/app/assets/javascripts/alchemy/admin.js index 98c553cc1a..4ff490c2bb 100644 --- a/app/assets/javascripts/alchemy/admin.js +++ b/app/assets/javascripts/alchemy/admin.js @@ -9,4 +9,3 @@ //= require alchemy/alchemy.fixed_elements //= require alchemy/alchemy.image_overlay //= require alchemy/alchemy.link_dialog -//= require alchemy/alchemy.preview_window diff --git a/app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee b/app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee deleted file mode 100644 index ef495393f5..0000000000 --- a/app/assets/javascripts/alchemy/alchemy.preview_window.js.coffee +++ /dev/null @@ -1,82 +0,0 @@ -window.Alchemy = {} if typeof(window.Alchemy) is 'undefined' - -Alchemy.PreviewWindow = - MIN_WIDTH: 240 - HEIGHT: 75 # Top menu height - - init: (previewUrl) -> - @select = document.querySelector('#preview_url') - @previewUrl = @_getCurrentPreviewUrl() || previewUrl[1] - $iframe = $(" + <%= turbo_frame_tag "alchemy_elements_window", src: alchemy.admin_elements_path(page_version_id: @page_version.id) do %> <% end %> @@ -147,24 +154,6 @@ }); Alchemy.PagePublicationFields(); Alchemy.PageLeaveObserver(); - Alchemy.PreviewWindow.init(<%== @preview_urls.first %>); - - $('#preview_size').bind('open.selectBoxIt', function (e) { - $('#top_menu').css('z-index', 5000); - }); - - $('#preview_size').bind('blur.selectBoxIt', function (e) { - $('#top_menu').css('z-index', 30); - }); - - $('select#preview_size').on('change', function() { - var width = this.value; - if (width === 'auto') { - Alchemy.PreviewWindow.currentWindow.css('width', ''); - } else { - Alchemy.PreviewWindow.resize(width); - } - }); }); diff --git a/spec/features/admin/edit_elements_feature_spec.rb b/spec/features/admin/edit_elements_feature_spec.rb index cfe54a5825..097bae7c81 100644 --- a/spec/features/admin/edit_elements_feature_spec.rb +++ b/spec/features/admin/edit_elements_feature_spec.rb @@ -156,7 +156,6 @@ before { visit alchemy.edit_admin_page_path(element.page) } scenario "expanded ingredient groups persist between visits", :js do - expect(page).not_to have_selector("#element_#{element.id}_ingredient_group_details", visible: true) page.find("details#element_#{element.id}_ingredient_group_details", text: "Details").click expect(page).to have_selector("#element_#{element.id}_ingredient_group_details", visible: true) visit alchemy.edit_admin_page_path(element.page) diff --git a/spec/javascript/alchemy_admin/components/element_editor.spec.js b/spec/javascript/alchemy_admin/components/element_editor.spec.js index d3b5171d4e..f19ad54168 100644 --- a/spec/javascript/alchemy_admin/components/element_editor.spec.js +++ b/spec/javascript/alchemy_admin/components/element_editor.spec.js @@ -178,8 +178,14 @@ describe("alchemy-element-editor", () => { it("focuses element in preview", () => { const click = new Event("click", { bubbles: true }) + const postMessage = jest.fn() + jest.spyOn(editor, "previewWindow", "get").mockImplementation(() => { + return { + postMessage + } + }) editor.dispatchEvent(click) - expect(Alchemy.PreviewWindow.postMessage).toHaveBeenCalledWith({ + expect(postMessage).toHaveBeenCalledWith({ message: "Alchemy.focusElement", element_id: "123" }) diff --git a/spec/javascript/alchemy_admin/components/element_editor/publish_element_button.spec.js b/spec/javascript/alchemy_admin/components/element_editor/publish_element_button.spec.js index 9ee8375031..d8d42a962f 100644 --- a/spec/javascript/alchemy_admin/components/element_editor/publish_element_button.spec.js +++ b/spec/javascript/alchemy_admin/components/element_editor/publish_element_button.spec.js @@ -1,6 +1,16 @@ import "alchemy_admin/components/element_editor/publish_element_button" import { renderComponent } from "../component.helper" +const mockReloadPreview = jest.fn() + +jest.mock("alchemy_admin/components/preview_window", () => { + return { + reloadPreview: () => { + mockReloadPreview() + } + } +}) + jest.mock("alchemy_admin/utils/ajax", () => { return { __esModule: true, @@ -63,7 +73,7 @@ describe("alchemy-publish-element-button", () => { return new Promise((resolve) => { setTimeout(() => { expect(button.tooltip.getAttribute("content")).toEqual("Hide element") - expect(Alchemy.reloadPreview).toHaveBeenCalled() + expect(mockReloadPreview).toHaveBeenCalled() resolve() }, 1) })