Add a system test for joining an account
Reworked the magic link stimulus controller, because the system test was causing double-submission of the form (because the event was bubbling up). I think that change simplifies the form and will still work well for iOS devices.
This commit is contained in:
@@ -4,12 +4,18 @@ import { onNextEventLoopTick } from "helpers/timing_helpers"
|
||||
export default class extends Controller {
|
||||
static targets = [ "input" ]
|
||||
|
||||
submitOnEnter(event) {
|
||||
event.preventDefault()
|
||||
this.submit()
|
||||
}
|
||||
|
||||
submitOnPaste() {
|
||||
onNextEventLoopTick(() => this.submit())
|
||||
}
|
||||
|
||||
submit() {
|
||||
onNextEventLoopTick(() => {
|
||||
if (!this.inputTarget.disabled) {
|
||||
this.element.submit()
|
||||
this.inputTarget.disabled = true
|
||||
}
|
||||
})
|
||||
if (this.inputTarget.disabled) return
|
||||
this.element.submit()
|
||||
this.inputTarget.disabled = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<%= form.text_field :code, required: true, class: "input center txt-align-enter txt-large",
|
||||
autofocus: true, autocorrect: "off", autocapitalize: "off", spellcheck: "false", "data-1p-ignore": true,
|
||||
autocomplete: "one-time-code", maxlength: "6", placeholder: "••••••", value: params[:code],
|
||||
data: { magic_link_target: "input", action: "keydown.enter->magic-link#submit paste->magic-link#submit" } %>
|
||||
data: { magic_link_target: "input", action: "keydown.enter->magic-link#submitOnEnter paste->magic-link#submitOnPaste" } %>
|
||||
<% end %>
|
||||
|
||||
<p class="txt-small">The code you receive will work for <%= distance_of_time_in_words(MagicLink::EXPIRATION_TIME) %>.</p>
|
||||
|
||||
@@ -1,6 +1,26 @@
|
||||
require "application_system_test_case"
|
||||
|
||||
class SmokeTest < ApplicationSystemTestCase
|
||||
test "joining an account" do
|
||||
account = accounts("37s")
|
||||
|
||||
visit join_url(code: account.join_code.code, script_name: account.slug)
|
||||
fill_in "Email address", with: "newbie@example.com"
|
||||
click_on "Continue"
|
||||
|
||||
assert_selector "h1", text: "Check your email"
|
||||
identity = Identity.find_by!(email_address: "newbie@example.com")
|
||||
code = identity.magic_links.active.first.code
|
||||
fill_in "code", with: code
|
||||
send_keys :enter
|
||||
|
||||
assert_selector "input[id=user_name]"
|
||||
fill_in "Full name", with: "New Bee"
|
||||
click_on "Continue"
|
||||
|
||||
assert_selector "h1", text: "Writebook"
|
||||
end
|
||||
|
||||
test "create a card" do
|
||||
sign_in_as(users(:david))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user