Skip to content

Commit

Permalink
Support trailing slash in internal link tab selection
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdeyen committed May 24, 2024
1 parent 682f201 commit 4725bf6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
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

0 comments on commit 4725bf6

Please sign in to comment.