From f635a34a94a8a10f9086c320af4f0f602d1715ea Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 14 Dec 2016 15:48:41 +0100 Subject: [PATCH] Fixed issue #249 - New users won't get initial user group. --- .../_ui_element/user_permission.coffee | 8 +++ test/browser/abb_one_group_test.rb | 67 ++++++++++++++++++- test/browser_test_helper.rb | 16 +++++ 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/app/controllers/_ui_element/user_permission.coffee b/app/assets/javascripts/app/controllers/_ui_element/user_permission.coffee index 0756069e4..936d6885a 100644 --- a/app/assets/javascripts/app/controllers/_ui_element/user_permission.coffee +++ b/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') ) diff --git a/test/browser/abb_one_group_test.rb b/test/browser/abb_one_group_test.rb index 2c58e2aff..e42349985 100644 --- a/test/browser/abb_one_group_test.rb +++ b/test/browser/abb_one_group_test.rb @@ -57,9 +57,72 @@ class AgentTicketActionLevel0Test < TestCase css: '.modal [name="email"]', value: "#{agent}@example.com", ) - exists_not( - css: '.modal select[name="group_ids"]', + 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 [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, diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index 974094733..520937c2d 100644 --- a/test/browser_test_helper.rb +++ b/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