|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'rails_helper' |
| 4 | + |
| 5 | +module BetterTogether |
| 6 | + RSpec.describe ApplicationHelper, type: :helper do |
| 7 | + before do |
| 8 | + allow(helper).to receive(:host_platform).and_return(double(name: 'Test Platform', cache_key_with_version: 'test-platform')) |
| 9 | + allow(helper).to receive(:host_community_logo_url).and_return(nil) |
| 10 | + allow(controller.request).to receive(:original_url).and_return('http://test.host/en/current') |
| 11 | + allow(I18n).to receive(:available_locales).and_return(%i[en fr]) |
| 12 | + allow(helper).to receive(:url_for) do |opts| |
| 13 | + "http://test.host/#{opts[:locale]}/current" |
| 14 | + end |
| 15 | + end |
| 16 | + |
| 17 | + describe '#seo_meta_tags' do |
| 18 | + it 'includes default canonical and hreflang links' do |
| 19 | + html = helper.seo_meta_tags |
| 20 | + expect(html).to include('<link rel="canonical" href="http://test.host/en/current"') |
| 21 | + expect(html).to include('<link rel="alternate" hreflang="fr" href="http://test.host/fr/current"') |
| 22 | + end |
| 23 | + |
| 24 | + it 'merges content_for overrides' do |
| 25 | + helper.content_for(:canonical_url, 'http://example.com/custom') |
| 26 | + helper.content_for(:hreflang_links, tag.link(rel: 'alternate', hreflang: 'es', href: 'http://test.host/es/current')) |
| 27 | + |
| 28 | + html = helper.seo_meta_tags |
| 29 | + expect(html).to include('<link rel="canonical" href="http://example.com/custom"') |
| 30 | + expect(html).to include('<link rel="alternate" hreflang="fr" href="http://test.host/fr/current"') |
| 31 | + expect(html).to include('<link rel="alternate" hreflang="es" href="http://test.host/es/current"') |
| 32 | + end |
| 33 | + end |
| 34 | + |
| 35 | + describe '#open_graph_meta_tags' do |
| 36 | + it 'defaults og:url to canonical_url' do |
| 37 | + allow(helper).to receive(:canonical_url).and_return('http://test.host/en/current') |
| 38 | + html = helper.open_graph_meta_tags |
| 39 | + expect(html).to include('<meta property="og:url" content="http://test.host/en/current"') |
| 40 | + end |
| 41 | + |
| 42 | + it 'allows og_url override' do |
| 43 | + helper.content_for(:og_url, 'http://example.com/og') |
| 44 | + allow(helper).to receive(:canonical_url).and_return('http://test.host/en/current') |
| 45 | + html = helper.open_graph_meta_tags |
| 46 | + expect(html).to include('<meta property="og:url" content="http://example.com/og"') |
| 47 | + end |
| 48 | + end |
| 49 | + end |
| 50 | +end |
0 commit comments