From ae1e6032f654a6e07c0517a2374a8359fe426d66 Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Thu, 13 Jul 2023 16:25:56 +0200 Subject: [PATCH 1/5] Enable 'Create Profile' button via callback in case of not returning promise --- .../registration/registration_form_controller.js.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/darkswarm/controllers/registration/registration_form_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/registration/registration_form_controller.js.coffee index c77fdc1fd6..59c2a1eb75 100644 --- a/app/assets/javascripts/darkswarm/controllers/registration/registration_form_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/registration/registration_form_controller.js.coffee @@ -9,7 +9,7 @@ angular.module('Darkswarm').controller "RegistrationFormCtrl", ($scope, Registra $scope.create = (form) -> if ($scope.valid(form)) $scope.disableButton() - EnterpriseRegistrationService.create().then(() -> + EnterpriseRegistrationService.create($scope.enableButton).then(() -> $scope.enableButton() ) end From 05d610e598f2edfa1a6dd286ca57c6005d7ecd27 Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Thu, 13 Jul 2023 16:28:10 +0200 Subject: [PATCH 2/5] Spec for (re)enabling 'Create Profile' button if not returning promise --- spec/system/consumer/registration_spec.rb | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/spec/system/consumer/registration_spec.rb b/spec/system/consumer/registration_spec.rb index 9e184e7cd3..a568f068fb 100644 --- a/spec/system/consumer/registration_spec.rb +++ b/spec/system/consumer/registration_spec.rb @@ -159,6 +159,43 @@ describe "Registration" do expect(page).to have_checked_field "enterprise_visible_only_through_links" end + context "Enterprise name is already taken" do + before do + address = Spree::Address.create!(firstname: 'John', lastname: 'Doe', + address1: '1400 Sesame street', zipcode: '3070', + city: 'Southcote', phone: '12 3456 7890', + country_id: 1, state_id: 1, company: 'unused') + owner = Spree::User.create!(email: "penny.profile@example.org", password: "cannotbeblank") + Enterprise.create(name: 'My Awesome Enterprise', address:, owner:) + end + + it "checks that button after failure is still enabled" do + visit registration_path + switch_to_login_tab + + fill_in "Email", with: user.email + fill_in "Password", with: user.password + click_button "Login" + click_button "Let's get started!" + + fill_in 'enterprise_name', with: "My Awesome Enterprise" + fill_in 'enterprise_address', with: '123 Abc Street' + fill_in 'enterprise_city', with: 'Northcote' + fill_in 'enterprise_zipcode', with: '3070' + select 'Vic', from: 'enterprise_state' + click_button "Continue" + + fill_in 'enterprise_contact', with: 'Saskia Munroe' + fill_in 'enterprise_phone', with: '12 3456 7890' + + click_button "Continue" + click_button "Create Profile" + click_link "producer-panel" + click_button "Create Profile" + expect(page).to have_button "Create Profile", disabled: false + end + end + context "when the user has no more remaining enterprises" do before do user.update(enterprise_limit: 0) From 057754305d361f004f85060878695868a3202d04 Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Mon, 17 Jul 2023 11:23:59 +0200 Subject: [PATCH 3/5] Useless 'end' at end of coffeescript block --- .../registration/registration_form_controller.js.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/app/assets/javascripts/darkswarm/controllers/registration/registration_form_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/registration/registration_form_controller.js.coffee index 59c2a1eb75..ec9a6553a2 100644 --- a/app/assets/javascripts/darkswarm/controllers/registration/registration_form_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/registration/registration_form_controller.js.coffee @@ -12,7 +12,6 @@ angular.module('Darkswarm').controller "RegistrationFormCtrl", ($scope, Registra EnterpriseRegistrationService.create($scope.enableButton).then(() -> $scope.enableButton() ) - end $scope.update = (nextStep, form) -> EnterpriseRegistrationService.update(nextStep) if $scope.valid(form) From d4c864a11831ec653693196e4c84eef08039c7c5 Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Mon, 17 Jul 2023 11:26:28 +0200 Subject: [PATCH 4/5] Add testing for modal warning that name is already in use --- spec/system/consumer/registration_spec.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/spec/system/consumer/registration_spec.rb b/spec/system/consumer/registration_spec.rb index a568f068fb..cd81ee00a6 100644 --- a/spec/system/consumer/registration_spec.rb +++ b/spec/system/consumer/registration_spec.rb @@ -160,12 +160,15 @@ describe "Registration" do end context "Enterprise name is already taken" do + let(:owner) do + Spree::User.create!(email: "penny.profile@example.org", password: "cannotbeblank") + end + before do address = Spree::Address.create!(firstname: 'John', lastname: 'Doe', address1: '1400 Sesame street', zipcode: '3070', city: 'Southcote', phone: '12 3456 7890', country_id: 1, state_id: 1, company: 'unused') - owner = Spree::User.create!(email: "penny.profile@example.org", password: "cannotbeblank") Enterprise.create(name: 'My Awesome Enterprise', address:, owner:) end @@ -191,7 +194,15 @@ describe "Registration" do click_button "Continue" click_button "Create Profile" click_link "producer-panel" - click_button "Create Profile" + alert_text = <<~TEXT.strip + Name has already been taken. If this is your enterprise and you would \ + like to claim ownership, or if you would like to trade with this \ + enterprise please contact the current manager of this profile at \ + #{owner.email}. + TEXT + accept_alert(alert_text) do + click_button "Create Profile" + end expect(page).to have_button "Create Profile", disabled: false end end From bebdaace4b1ef7bf28c59932a97720c127cc22fd Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 20 Jul 2023 09:06:55 +1000 Subject: [PATCH 5/5] Prefer plain text in spec expectations --- spec/system/consumer/registration_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/system/consumer/registration_spec.rb b/spec/system/consumer/registration_spec.rb index cd81ee00a6..f2081bbb14 100644 --- a/spec/system/consumer/registration_spec.rb +++ b/spec/system/consumer/registration_spec.rb @@ -198,7 +198,7 @@ describe "Registration" do Name has already been taken. If this is your enterprise and you would \ like to claim ownership, or if you would like to trade with this \ enterprise please contact the current manager of this profile at \ - #{owner.email}. + penny.profile@example.org. TEXT accept_alert(alert_text) do click_button "Create Profile"