Sha256: 770d9115fa7d73eed8603ce4fcd52f2383c3e1c6ec6161c18b14e7fc1a461f4b

Contents?: true

Size: 1.94 KB

Versions: 8

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

RSpec.describe 'Locale Selector', js: true do
  let(:exhibit) { FactoryBot.create(:exhibit, published: true) }
  let!(:language_es) { FactoryBot.create(:language, exhibit: exhibit, locale: 'es', public: true) }
  let!(:language_zh) { FactoryBot.create(:language, exhibit: exhibit, locale: 'zh') }

  before { login_as user }

  before(:all) do
    # mimics setting config.i18n.fallbacks = [I18n.default_locale] in the rails environment
    I18n.fallbacks[:es] = [:es, I18n.default_locale]
  end


  context 'with an anonymous user' do
    let(:user) { FactoryBot.create(:exhibit_visitor) }

    it 'only sees public languages' do
      visit spotlight.exhibit_path(exhibit)

      expect(page).to have_css('li.dropdown', text: 'English')
      click_link 'English'

      within('.dropdown-menu', visible: true) do
        expect(page).to have_css('li', count: 1)
        expect(page).to have_css('li', text: 'Español')
      end
    end
  end

  context 'with an exhibit curator' do
    let(:user) { FactoryBot.create(:exhibit_curator, exhibit: exhibit) }

    it 'can see any saved languages' do
      visit spotlight.exhibit_path(exhibit)

      expect(page).to have_css('li.dropdown', text: 'English')
      click_link 'English'

      within('.dropdown-menu', visible: true) do
        expect(page).to have_css('li', count: 2)
        expect(page).to have_css('li', text: '中文')
        expect(page).to have_css('li', text: 'Español')
      end
    end
  end

  describe 'switching locales' do
    let(:user) { FactoryBot.create(:exhibit_visitor) }

    it 'works' do
      visit spotlight.exhibit_path(exhibit)

      expect(page).to have_css('input[placeholder="Search..."]')

      click_link 'English'

      within('.dropdown-menu', visible: true) do
        click_link 'Español'
      end

      expect(page).not_to have_css('input[placeholder="Search..."]')
      expect(page).to have_css('input[placeholder="Buscar..."]')
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
blacklight-spotlight-2.13.0 spec/features/javascript/locale_selector_spec.rb
blacklight-spotlight-2.12.1 spec/features/javascript/locale_selector_spec.rb
blacklight-spotlight-2.12.0 spec/features/javascript/locale_selector_spec.rb
blacklight-spotlight-2.11.0 spec/features/javascript/locale_selector_spec.rb
blacklight-spotlight-2.10.0 spec/features/javascript/locale_selector_spec.rb
blacklight-spotlight-2.9.0 spec/features/javascript/locale_selector_spec.rb
blacklight-spotlight-2.8.0 spec/features/javascript/locale_selector_spec.rb
blacklight-spotlight-2.7.2 spec/features/javascript/locale_selector_spec.rb