From 11fba7935f4a1909d6e7c780094cfb3f92bb2a51 Mon Sep 17 00:00:00 2001
From: Priya Power <49959312+priyapower@users.noreply.github.com>
Date: Wed, 17 Jul 2024 15:41:54 -0500
Subject: [PATCH] [#5777] Add spec for step navigation component
---
.../form/step_navigation_component.html.erb | 12 ++++++++++--
.../form/step_navigation_component_spec.rb | 19 +++++++++++++++++++
2 files changed, 29 insertions(+), 2 deletions(-)
create mode 100644 spec/components/form/step_navigation_component_spec.rb
diff --git a/app/components/form/step_navigation_component.html.erb b/app/components/form/step_navigation_component.html.erb
index c8d729f8ae..35dc06aa90 100644
--- a/app/components/form/step_navigation_component.html.erb
+++ b/app/components/form/step_navigation_component.html.erb
@@ -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 %>
+
+ <% end %>
+ <% elsif %>
<% end %>
<% end %>
@@ -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 %>
+
+ <% end %>
+ <% elsif %>
<% end %>
<% end %>
diff --git a/spec/components/form/step_navigation_component_spec.rb b/spec/components/form/step_navigation_component_spec.rb
new file mode 100644
index 0000000000..37b9c8c10e
--- /dev/null
+++ b/spec/components/form/step_navigation_component_spec.rb
@@ -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