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

Support trailing slash in internal link tab selection #2895

Merged
merged 1 commit into from
May 27, 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
4 changes: 2 additions & 2 deletions app/components/alchemy/admin/link_dialog/internal_tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Alchemy
module Admin
module LinkDialog
class InternalTab < BaseTab
PAGE_URL_PATTERN = /\/(?<locale>[a-z]{2})?(?<slash>\/)?(?<urlname>.*)/
PAGE_URL_PATTERN = /\A\/(?<locale>[a-z]{2})?(?<slash>\/)?(?<urlname>.*?)(?<trailing-slash>\/)?\z/

def title
Alchemy.t("link_overlay_tab_label.internal")
Expand Down Expand Up @@ -49,7 +49,7 @@ def page
end

def page_attributes
locale, _slash, urlname = uri.path.match(PAGE_URL_PATTERN)&.captures
locale, _, urlname, _ = uri.path.match(PAGE_URL_PATTERN)&.captures

if locale && urlname.present?
{language_code: locale, urlname: urlname}
Expand Down
35 changes: 35 additions & 0 deletions spec/components/alchemy/admin/link_dialog/internal_tab_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@
expect(page.find(:css, "input[name=internal_link]").value).to eq(url)
end

context "with trailing slash" do
let(:language) { create(:alchemy_language, default: true, site: site) }
let(:alchemy_page) { create(:alchemy_page, language: language) }
let(:url) { alchemy_page.url_path + "/" + "#" + fragment }

it "has url value set" do
expect(page.find(:css, "input[name=internal_link]").value).to eq(url)
end

it "has hash fragment set" do
expect(page.find(:css, "select[name=element_anchor]").value).to eq("#" + fragment)
end
end

it "has hash fragment set" do
expect(page.find(:css, "select[name=element_anchor]").value).to eq("#" + fragment)
end
Expand All @@ -35,6 +49,16 @@
it "has url value set" do
expect(page.find(:css, "input[name=internal_link]").value).to eq(url)
end

context "with trailing slash" do
let(:language) { create(:alchemy_language, default: true, site: site) }
let(:alchemy_page) { create(:alchemy_page, language: language) }
let(:url) { "/#{alchemy_page.language_code}/#{alchemy_page.urlname}/" }

it "has url value set" do
expect(page.find(:css, "input[name=internal_link]").value).to eq(url)
end
end
end

context "with root url" do
Expand All @@ -57,6 +81,17 @@
it "has url value set to root url" do
expect(page.find(:css, "input[name=internal_link]").value).to eq(url)
end

context "with trailing slash" do
let(:language) { create(:alchemy_language, default: true, site: site) }
let(:alchemy_page) { create(:alchemy_page, language: language) }

let(:url) { alchemy_page && "/en/" }

it "has url value set to root url" do
expect(page.find(:css, "input[name=internal_link]").value).to eq(url)
end
end
end
end

Expand Down