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

Only set url on attachment select if attachment found #2882

Merged
merged 1 commit into from
May 22, 2024
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: 1 addition & 1 deletion app/components/alchemy/admin/link_dialog/file_tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def attachment

def attachment_select
label = label_tag("file_link", Alchemy.t(:file), class: "control-label")
input = text_field_tag("file_link", url, id: "file_link")
input = text_field_tag("file_link", attachment && url, id: "file_link")
select = render Alchemy::Admin::AttachmentSelect.new(attachment).with_content(input)
content_tag("div", label + select, class: "input select")
end
Expand Down
27 changes: 12 additions & 15 deletions spec/components/alchemy/admin/link_dialog/file_tab_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,21 @@
it_behaves_like "a link dialog tab", :file, "File"
it_behaves_like "a link dialog - target select", :file

context "file link" do
it "has a file select" do
expect(page).to have_selector("alchemy-attachment-select [name=file_link]")
end

context "tab selected" do
let(:is_selected) { true }
it "has a file select" do
expect(page).to have_selector("alchemy-attachment-select [name=file_link]")
end

it "has a selected value" do
expect(page).to have_selector("alchemy-attachment-select [value='#{url}']")
end
context "with attachment found by url" do
it "has value set" do
expect(page).to have_selector("alchemy-attachment-select [value='#{url}']")
end
end

context "with attachment not found by url" do
let(:url) { Alchemy::Engine.routes.url_helpers.show_page_path(urlname: "foo") }

context "tab not selected" do
it "has a selected value" do
expect(page).to have_selector("alchemy-attachment-select [value='#{url}']")
# expect(page).to_not have_selector("alchemy-attachment-select [name=file_link] option[selected='selected']")
end
it "has no value set" do
expect(page).to_not have_selector("alchemy-attachment-select [value='#{url}']")
end
end
end