diff --git a/app/views/admin/enterprises/form/_users.html.haml b/app/views/admin/enterprises/form/_users.html.haml index 89696d112b..a62c132592 100644 --- a/app/views/admin/enterprises/form/_users.html.haml +++ b/app/views/admin/enterprises/form/_users.html.haml @@ -14,20 +14,21 @@ - else = owner_email -.row - .three.columns.alpha - =f.label :user_ids, t('.notifications') - - if full_permissions - %span.required * - %div{'ofn-with-tip' => t('.contact_tip')} - %a= t('admin.whats_this') - .eight.columns.omega - - if full_permissions - %select.select2.fullwidth{id: 'receives_notifications_dropdown', name: 'receives_notifications', ng: {model: 'receivesNotifications', init: "receivesNotifications = '#{@enterprise.contact.id}'"}} - %option{ng: {repeat: 'user in Enterprise.users', selected: "user.id == #{@enterprise.contact.id}", hide: '!user.confirmed'}, value: '{{user.id}}'} - {{user.email}} - - else - = @enterprise.contact.email +- if @enterprise.is_distributor + .row + .three.columns.alpha + =f.label :user_ids, t('.notifications') + - if full_permissions + %span.required * + %div{'ofn-with-tip' => t('.contact_tip')} + %a= t('admin.whats_this') + .eight.columns.omega + - if full_permissions + %select.select2.fullwidth{id: 'receives_notifications_dropdown', name: 'receives_notifications', ng: {model: 'receivesNotifications', init: "receivesNotifications = '#{@enterprise.contact.id}'"}} + %option{ng: {repeat: 'user in Enterprise.users', selected: "user.id == #{@enterprise.contact.id}", hide: '!user.confirmed'}, value: '{{user.id}}'} + {{user.email}} + - else + = @enterprise.contact.email .row .three.columns.alpha diff --git a/spec/views/admin/enterprises/form/_users.html.haml_spec.rb b/spec/views/admin/enterprises/form/_users.html.haml_spec.rb new file mode 100644 index 0000000000..f6576f64a6 --- /dev/null +++ b/spec/views/admin/enterprises/form/_users.html.haml_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe "admin/enterprises/form/_users.html.haml" do + let(:enterprise) { build(:enterprise) } + + before do + assign(:enterprise, enterprise) + admin_user = build(:admin_user) + allow(admin_user).to receive(:admin?) { true } + allow(view).to receive_messages( + f: enterprise_form, + spree_current_user: admin_user, + ) + end + + describe "notifications setting" do + it "is visible when an enterprise is a distributor" do + enterprise.sells = "any" + + render + + expect(rendered).to have_selector("select[name='receives_notifications']") + end + + it "is not visible when an enterprise is a only a profile" do + enterprise.sells = "none" + + render + + expect(rendered).not_to have_selector("select[name='receives_notifications']") + end + end + + private + + def enterprise_form + form_for(enterprise) { |f| @enterprise_form = f } + @enterprise_form + end +end