|
3 | 3 | require "rails_helper" |
4 | 4 |
|
5 | 5 | RSpec.describe Alchemy::Admin::LinkDialog::InternalTab, type: :component do |
| 6 | + let(:site) { create(:alchemy_site) } |
6 | 7 | let(:alchemy_page) { create(:alchemy_page) } |
7 | 8 | let(:url) { alchemy_page.url_path + "#" + fragment } |
8 | 9 | let(:fragment) { "bar" } |
|
12 | 13 | let(:link_target) { nil } |
13 | 14 |
|
14 | 15 | before do |
| 16 | + Alchemy::Current.site = site |
15 | 17 | render_inline(described_class.new(url, is_selected: is_selected, link_title: link_title, link_target: link_target)) |
16 | 18 | end |
17 | 19 |
|
18 | 20 | it_behaves_like "a link dialog tab", :internal, "Internal" |
19 | 21 | it_behaves_like "a link dialog - target select", :internal |
20 | 22 |
|
21 | | - context "link field" do |
22 | | - context "tab not selected" do |
23 | | - it "should not have the value of the url" do |
24 | | - expect(page.find(:css, "input[name=internal_link]").value).to be_empty |
25 | | - end |
| 23 | + context "with page found by url" do |
| 24 | + it "has url value set" do |
| 25 | + expect(page.find(:css, "input[name=internal_link]").value).to eq(url) |
| 26 | + end |
| 27 | + |
| 28 | + it "has hash fragment set" do |
| 29 | + expect(page.find(:css, "select[name=element_anchor]").value).to eq("#" + fragment) |
| 30 | + end |
| 31 | + |
| 32 | + context "with locale in url" do |
| 33 | + let(:url) { "/#{alchemy_page.language_code}/#{alchemy_page.urlname}" } |
26 | 34 |
|
27 | | - it "should not have the value of the hash fragment" do |
28 | | - expect(page.find(:css, "select[name=element_anchor]").value).to be_empty |
| 35 | + it "has url value set" do |
| 36 | + expect(page.find(:css, "input[name=internal_link]").value).to eq(url) |
29 | 37 | end |
30 | 38 | end |
31 | 39 |
|
32 | | - context "tab selected" do |
33 | | - let(:is_selected) { true } |
| 40 | + context "with root url" do |
| 41 | + let(:language) { create(:alchemy_language, default: true, site: site) } |
| 42 | + let(:alchemy_page) { create(:alchemy_page, language: language) } |
| 43 | + |
| 44 | + let(:url) { alchemy_page && "/" } |
34 | 45 |
|
35 | | - it "should have the value of the url" do |
| 46 | + it "has url value set to root url" do |
36 | 47 | expect(page.find(:css, "input[name=internal_link]").value).to eq(url) |
37 | 48 | end |
| 49 | + end |
| 50 | + |
| 51 | + context "with locale root url" do |
| 52 | + let(:language) { create(:alchemy_language, default: true, site: site) } |
| 53 | + let(:alchemy_page) { create(:alchemy_page, language: language) } |
38 | 54 |
|
39 | | - it "should not have the value of the hash fragment" do |
40 | | - expect(page.find(:css, "select[name=element_anchor]").value).to eq("#" + fragment) |
| 55 | + let(:url) { alchemy_page && "/en" } |
| 56 | + |
| 57 | + it "has url value set to root url" do |
| 58 | + expect(page.find(:css, "input[name=internal_link]").value).to eq(url) |
41 | 59 | end |
42 | 60 | end |
43 | 61 | end |
| 62 | + |
| 63 | + context "with page not found by url" do |
| 64 | + let(:url) { "/foo" } |
| 65 | + |
| 66 | + it "has no url value set" do |
| 67 | + expect(page.find(:css, "input[name=internal_link]").value).to be_nil |
| 68 | + end |
| 69 | + |
| 70 | + it "has no hash fragment set" do |
| 71 | + expect(page.find(:css, "select[name=element_anchor]").value).to be_empty |
| 72 | + end |
| 73 | + end |
44 | 74 | end |
0 commit comments