Skip to content

Commit

Permalink
fix for to being off by one
Browse files Browse the repository at this point in the history
  • Loading branch information
dnoneill committed Sep 25, 2024
1 parent 51405c3 commit 21499fa
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
experimental: [false]
additional_engine_cart_rails_options: [""]
additional_name: [""]
view_component_version: ["~> 3.12"]
include:
- ruby: "3.1"
rails_version: 6.1.7
Expand All @@ -35,6 +36,12 @@ jobs:
blacklight_version: "github"
experimental: true
additional_name: Blacklight main branch
- ruby: "3.2"
rails_version: "7.0.4"
blacklight_version: "~> 7.0"
experimental: false
view_component_version: "~> 2.83"
additional_name: "/ ViewComponent 2"
- ruby: "3.2"
rails_version: "7.0.4"
blacklight_version: "github"
Expand All @@ -44,6 +51,7 @@ jobs:
env:
RAILS_VERSION: ${{ matrix.rails_version }}
BLACKLIGHT_VERSION: ${{ matrix.blacklight_version }}
VIEW_COMPONENT_VERSION: ${{ matrix.view_component_version }}
ENGINE_CART_RAILS_OPTIONS: "--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test ${{ matrix.additional_engine_cart_rails_options }}"
steps:
- uses: actions/checkout@v4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class SlideshowPreviewComponent < Blacklight::DocumentComponent

def initialize(document:, document_counter: nil, **args)
super(document: document, document_counter: document_counter, **args)
@document_counter = document_counter || @counter

@slide_to = @counter - 1
end

def before_render
Expand Down Expand Up @@ -45,8 +46,8 @@ def data_attributes
{
'context-href': nil,
context_href: nil,
'slide-to': @document_counter,
'bs-slide-to': @document_counter,
'slide-to': @slide_to,
'bs-slide-to': @slide_to,
toggle: "modal",
'bs-toggle': "modal",
target: "#slideshow-modal",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@
expect(rendered).to have_selector '.thumbnail img[@src="http://example.com/image.jpg"]'
end

it 'renders the correct slide number' do
if ViewComponent::VERSION::MAJOR < 3
expect(rendered).to have_css '[data-slide-to=\"4\"][data-bs-slide-to=\"4\"]'
else
expect(rendered).to have_css '[data-slide-to=\"5\"][data-bs-slide-to=\"5\"]'
end
end

context 'when the presenter returns nothing' do
let(:document) { SolrDocument.new(id: 'abc') }

Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'rspec/its'
require 'rspec/rails'
require 'rspec/active_model/mocks'
require 'view_component_v2_test_helpers'

require 'selenium-webdriver'

Expand All @@ -19,4 +20,7 @@
RSpec.configure do |c|
c.infer_spec_type_from_file_location!
c.include ViewComponent::TestHelpers, type: :component
if ViewComponent::VERSION::MAJOR < 3
c.include ViewComponentV2TestHelpers, type: :component
end
end
4 changes: 4 additions & 0 deletions spec/test_app_templates/Gemfile.extra
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ if ENV['BLACKLIGHT_VERSION'] == 'github'
elsif ENV['BLACKLIGHT_VERSION'] && !ENV['BLACKLIGHT_VERSION'].empty?
gem 'blacklight', ENV['BLACKLIGHT_VERSION']
end

unless ENV['VIEW_COMPONENT_VERSION'].to_s == ""
gem 'view_component', ENV.fetch('VIEW_COMPONENT_VERSION')
end
20 changes: 20 additions & 0 deletions spec/view_component_v2_test_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module ViewComponentV2TestHelpers
def vc_test_controller
@vc_test_controller ||= __vc_test_helpers_build_controller(ViewComponent::Base.test_controller.constantize)
end

def __vc_test_helpers_build_controller(klass)
klass.new.tap { |c| c.request = vc_test_request }.extend(Rails.application.routes.url_helpers)
end

def vc_test_request
require "action_controller/test_case"

@vc_test_request ||=
begin
out = ActionDispatch::TestRequest.create
out.session = ActionController::TestSession.new
out
end
end
end

0 comments on commit 21499fa

Please sign in to comment.