Browse Source

Fixed issue #249 - New users won't get initial user group.

Martin Edenhofer 8 years ago
parent
commit
f635a34a94

+ 8 - 0
app/assets/javascripts/app/controllers/_ui_element/user_permission.coffee

@@ -102,12 +102,20 @@ class App.UiElement.user_permission
       if !checked
         if rolesWithGroupPlugin[role_id] is 'group'
           item.find('.js-groupList').addClass('hidden')
+
+          # select groups if only one is available
+          if hideGroups
+            item.find('.js-groupList [name=group_ids]').prop('checked', false)
         return
 
       # if role with groups plugin is selected, show group selection
       if rolesWithGroupPlugin[role_id] is 'group'
         item.find('.js-groupList:not(.js-groupListHide)').removeClass('hidden')
 
+        # select groups if only one is available
+        if hideGroups
+          item.find('.js-groupList [name=group_ids]').prop('checked', true)
+
       for trigger in triggers
         trigger.trigger('change')
     )

+ 64 - 1
test/browser/abb_one_group_test.rb

@@ -57,9 +57,72 @@ class AgentTicketActionLevel0Test < TestCase
       css: '.modal [name="email"]',
       value: "#{agent}@example.com",
     )
+    exists(
+      displayed: false,
+      css: '.modal [name="group_ids"]',
+    )
+    exists(
+      css: '.modal [name="group_ids"]:checked',
+    )
+    click(
+      css: '.modal button.btn.btn--primary',
+      fast: true,
+    )
+    watch_for(
+      css:   'body div.modal',
+      value: 'Sending',
+    )
+    watch_for_disappear(
+      css:   'body div.modal',
+      value: 'Sending',
+    )
+
+    click(css: '#navigation a[href="#dashboard"]')
+    click(css: '.active.content .tab[data-area="first-steps-widgets"]')
+    watch_for(
+      css:   '.active.content',
+      value: 'Configuration',
+    )
+    click(css: '.active.content .js-inviteAgent')
+    modal_ready()
+    set(
+      css: '.modal [name="firstname"]',
+      value: 'Bob2',
+    )
+    set(
+      css: '.modal [name="lastname"]',
+      value: 'Smith2',
+    )
+    set(
+      css: '.modal [name="email"]',
+      value: "#{agent}2@example.com",
+    )
+
+    # disable agent role
+    uncheck(
+      css: '.modal [name="role_ids"][value=2]',
+    )
+
+    exists(
+      displayed: false,
+      css: '.modal [name="group_ids"]',
+    )
     exists_not(
-      css: '.modal select[name="group_ids"]',
+      css: '.modal [name="group_ids"]:checked',
+    )
+
+    # enable agent role
+    check(
+      css: '.modal [name="role_ids"][value=2]',
+    )
+
+    exists(
+      css: '.modal [name="group_ids"]',
     )
+    exists(
+      css: '.modal [name="group_ids"]:checked',
+    )
+
     click(
       css: '.modal button.btn.btn--primary',
       fast: true,

+ 16 - 0
test/browser_test_helper.rb

@@ -547,6 +547,12 @@ class TestCase < Test::Unit::TestCase
     css: '.some_class',
   )
 
+  exists(
+    displayed: false, # true|false
+    browser: browser1,
+    css: '.some_class',
+  )
+
 =end
 
   def exists(params)
@@ -558,6 +564,16 @@ class TestCase < Test::Unit::TestCase
       screenshot(browser: instance, comment: 'exists_failed')
       raise "#{params[:css]} dosn't exist, but should"
     end
+
+    if params.key?(:displayed)
+      if params[:displayed] == true && !instance.find_elements(css: params[:css])[0].displayed?
+        raise "#{params[:css]} is not displayed, but should"
+      end
+      if params[:displayed] == false && instance.find_elements(css: params[:css])[0].displayed?
+        raise "#{params[:css]} is displayed, but should not"
+      end
+    end
+
     true
   end