Sha256: 921225d8ebbc218815ce0e68a2570bc0a7a0d9a82b9ebf4401dfbc8821a13f53

Contents?: true

Size: 2 KB

Versions: 4

Compression:

Stored size: 2 KB

Contents

require 'spec_helper'

describe Locomotive::Steam::Liquid::Tags::AltPageLinks do

  let(:locale)          { 'en' }
  let(:assigns)         { { 'page' => drop, 'base_url' => 'https://www.example.com' } }
  let(:prefix_default)  { false }
  let(:services)        { Locomotive::Steam::Services.build_instance }
  let(:locales)         { %w(en) }
  let(:site)            { instance_double('Site', locales: locales, default_locale: 'en', prefix_default_locale: prefix_default) }
  let(:drop)            { Locomotive::Steam::Liquid::Drops::Page.new(page) }
  let(:page)            { liquid_instance_double('Index', index?: true, localized_attributes: { title: true, fullpath: true }, title: { en: 'Home', fr: 'Accueil' }, fullpath: { en: 'index', fr: 'index' }, templatized?: false) }
  let(:context)         { ::Liquid::Context.new(assigns, {}, { services: services, site: site, locale: locale }) }

  subject { render_template(source, context) }

  before { allow(services).to receive(:current_site).and_return(site) }

  describe 'default rendering' do

    let(:source) { '{% alt_page_links %}' }

    it 'renders an empty string if one single locale' do
      is_expected.to eq('')
    end

    context 'multilingual site' do

      let(:locales) { %w(en fr) }

      it { is_expected.to eq((<<-HTML
<link rel="alternate" hreflang="x-default" href="https://www.example.com/" />
<link rel="alternate" hreflang="en" href="https://www.example.com/en" />
<link rel="alternate" hreflang="fr" href="https://www.example.com/fr" />
        HTML
        ).strip)
      }

      context 'the current locale is different from the default one' do

        let(:locale) { 'fr' }

        it 'has to be the same links' do
          is_expected.to eq((<<-HTML
<link rel="alternate" hreflang="x-default" href="https://www.example.com/" />
<link rel="alternate" hreflang="en" href="https://www.example.com/en" />
<link rel="alternate" hreflang="fr" href="https://www.example.com/fr" />
        HTML
          ).strip)
        end

      end

    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
locomotivecms_steam-1.5.0.rc0 spec/unit/liquid/tags/alt_page_links_spec.rb
locomotivecms_steam-1.5.0.beta3 spec/unit/liquid/tags/alt_page_links_spec.rb
locomotivecms_steam-1.5.0.beta2 spec/unit/liquid/tags/alt_page_links_spec.rb
locomotivecms_steam-1.5.0.beta1 spec/unit/liquid/tags/alt_page_links_spec.rb