Skip to content

Commit

Permalink
[rubyforgood#5777] Add spec for step navigation component
Browse files Browse the repository at this point in the history
  • Loading branch information
priyapower committed Jul 17, 2024
1 parent 2308e72 commit 11fba79
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/components/form/step_navigation_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
title: "Back step",
aria: { label: "Back step" },
disabled: !@nav_back do %>
<%= link_to @nav_back, title: "Back step", aria: { label: "Back step" } do %>
<% if @nav_back.present? %>
<%= link_to @nav_back, title: "Back step", aria: { label: "Back step" } do %>
<i class="lni lni-chevron-left" alt="Chevron icon left"></i>
<% end %>
<% elsif %>
<i class="lni lni-chevron-left" alt="Chevron icon left"></i>
<% end %>
<% end %>
Expand All @@ -19,7 +23,11 @@
title: "Next step",
aria: { label: "Next step" },
disabled: !@nav_next do %>
<%= link_to @nav_next, title: "Next step", aria: { label: "Next step" } do %>
<% if @nav_next.present? %>
<%= link_to @nav_next, title: "Next step", aria: { label: "Next step" } do %>
<i class="lni lni-chevron-right" alt="Chevron icon right"></i>
<% end %>
<% elsif %>
<i class="lni lni-chevron-right" alt="Chevron icon right"></i>
<% end %>
<% end %>
Expand Down
19 changes: 19 additions & 0 deletions spec/components/form/step_navigation_component_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Form::StepNavigationComponent, type: :component do
context "can handle enabled button" do
it "enables button if value exists" do
render_inline(described_class.new(nav_back: '/details'))
expect(page).to have_selector(:link_or_button, 'Back step')
end
end

context "can handle disabled button" do
it "disables buttons if value is nil" do
render_inline(described_class.new())
expect(page).not_to have_selector(:link_or_button, 'Next step')
end
end
end

0 comments on commit 11fba79

Please sign in to comment.