Repository: liveshowy/webauthn_components (elixir)

Issue:
[BUG] - `disabled` assign not respected in `RegistrationComponent` 

Pull request description:
Ensure `disabled` attr actually disables the button
Resolves #70 



Patch:
diff --git a/lib/webauthn_components/base_components.ex b/lib/webauthn_components/base_components.ex
index 4d311a0..bbfee54 100644
--- a/lib/webauthn_components/base_components.ex
+++ b/lib/webauthn_components/base_components.ex
@@ -13,7 +13,7 @@ defmodule WebauthnComponents.BaseComponents do
   @doc false
   def button(assigns) do
     ~H"""
-    <button id={@id} type={@type} {@rest}>
+    <button id={@id} type={@type} disabled={@disabled} {@rest}>
       <%= render_slot(@inner_block) %>
     </button>
     """
diff --git a/templates/live_views/authentication_live.html.heex b/templates/live_views/authentication_live.html.heex
index 57931da..72bab18 100644
--- a/templates/live_views/authentication_live.html.heex
+++ b/templates/live_views/authentication_live.html.heex
@@ -39,7 +39,7 @@
       <p>Sign into an existing account:</p>
 
       <.live_component
-        disabled={@form.source.valid? == false}
+        disabled={false}
         module={AuthenticationComponent}
         id="authentication-component"
         class={[


Test patch:
diff --git a/test/webauthn_components/registration_component_test.exs b/test/webauthn_components/registration_component_test.exs
index 5440bb4..fb21a45 100644
--- a/test/webauthn_components/registration_component_test.exs
+++ b/test/webauthn_components/registration_component_test.exs
@@ -11,7 +11,7 @@ defmodule WebauthnComponents.RegistrationComponentTest do
     {:ok, view, _html} = live_isolated_component(RegistrationComponent, assigns)
     live_assign(view, app: assigns.app, id: assigns.id)
     element = element(view, "##{assigns.id}")
-    %{view: view, element: element}
+    %{view: view, element: element, default_assigns: assigns}
   end
 
   describe "render/1" do
@@ -20,6 +20,22 @@ defmodule WebauthnComponents.RegistrationComponentTest do
     end
   end
 
+  describe "update/2" do
+    test "updates `disabled` assign", setup_attrs do
+      %{default_assigns: default_assigns} = setup_attrs
+      assigns = Map.merge(default_assigns, %{disabled: true})
+      {:ok, view, _html} = live_isolated_component(RegistrationComponent, assigns)
+      assert has_element?(view, "##{assigns.id}[disabled]")
+    end
+
+    test "is not `disabled` by default", setup_attrs do
+      %{default_assigns: assigns} = setup_attrs
+      {:ok, view, _html} = live_isolated_component(RegistrationComponent, assigns)
+      assert has_element?(view, "##{assigns.id}")
+      refute has_element?(view, "##{assigns.id}[disabled]")
+    end
+  end
+
   describe "handle_event/3 - register" do
     test "sends registration challenge to client", %{element: element, view: view} do
       webauthn_user = %WebauthnUser{