diff --git a/app/assets/javascripts/app/controllers/_profile/token_access.coffee b/app/assets/javascripts/app/controllers/_profile/token_access.coffee index 966d864b9..490df90fd 100644 --- a/app/assets/javascripts/app/controllers/_profile/token_access.coffee +++ b/app/assets/javascripts/app/controllers/_profile/token_access.coffee @@ -97,7 +97,10 @@ class Create extends App.ControllerModal # check if min one permission exists if _.isEmpty(params['permission']) - alert('Min. one permission is needed!') + @notify( + type: 'error' + msg: App.i18n.translateContent('Minimum of one permission is needed!') + ) return if !_.isArray(params['permission']) diff --git a/script/build/test_slice_tests.sh b/script/build/test_slice_tests.sh index 86fe9c48f..7ba0280de 100755 --- a/script/build/test_slice_tests.sh +++ b/script/build/test_slice_tests.sh @@ -64,7 +64,6 @@ if [ "$LEVEL" == '1' ]; then rm test/browser/integration_sipgate_test.rb rm test/browser/integration_cti_test.rb rm test/browser/preferences_language_test.rb - rm test/browser/preferences_token_access_test.rb # test/browser/swich_to_user_test.rb # test/browser/taskbar_session_test.rb # test/browser/taskbar_task_test.rb @@ -131,7 +130,6 @@ elif [ "$LEVEL" == '2' ]; then rm test/browser/integration_sipgate_test.rb rm test/browser/integration_cti_test.rb rm test/browser/preferences_language_test.rb - rm test/browser/preferences_token_access_test.rb rm test/browser/switch_to_user_test.rb rm test/browser/taskbar_session_test.rb rm test/browser/taskbar_task_test.rb @@ -198,7 +196,6 @@ elif [ "$LEVEL" == '3' ]; then rm test/browser/integration_sipgate_test.rb rm test/browser/integration_cti_test.rb rm test/browser/preferences_language_test.rb - rm test/browser/preferences_token_access_test.rb rm test/browser/switch_to_user_test.rb rm test/browser/taskbar_session_test.rb rm test/browser/taskbar_task_test.rb @@ -265,7 +262,6 @@ elif [ "$LEVEL" == '4' ]; then rm test/browser/integration_sipgate_test.rb rm test/browser/integration_cti_test.rb rm test/browser/preferences_language_test.rb - rm test/browser/preferences_token_access_test.rb rm test/browser/switch_to_user_test.rb rm test/browser/taskbar_session_test.rb rm test/browser/taskbar_task_test.rb @@ -331,7 +327,6 @@ elif [ "$LEVEL" == '5' ]; then rm test/browser/integration_sipgate_test.rb rm test/browser/integration_cti_test.rb rm test/browser/preferences_language_test.rb - rm test/browser/preferences_token_access_test.rb rm test/browser/switch_to_user_test.rb rm test/browser/taskbar_session_test.rb rm test/browser/taskbar_task_test.rb @@ -400,7 +395,6 @@ elif [ "$LEVEL" == '6' ]; then # rm test/browser/integration_sipgate_test.rb # rm test/browser/integration_cti_test.rb # test/browser/preferences_language_test.rb - # test/browser/preferences_token_access_test.rb rm test/browser/switch_to_user_test.rb rm test/browser/taskbar_session_test.rb rm test/browser/taskbar_task_test.rb diff --git a/spec/system/profile/preferences_token_access_spec.rb b/spec/system/profile/preferences_token_access_spec.rb new file mode 100644 index 000000000..1efc5c5d9 --- /dev/null +++ b/spec/system/profile/preferences_token_access_spec.rb @@ -0,0 +1,138 @@ +# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ + +require 'rails_helper' + +RSpec.describe 'Profile > Token Access', type: :system do + let(:label) { 'Some App Token' } + let(:checkbox_input) { 'input[value="ticket.agent"]' } + let(:expiry_date) { '05/15/2024' } + let(:token_list) { find('.js-tokenList') } + + shared_examples 'having an error notification message' do + it 'has error notification message' do + within '#notify' do + noty_message = find('.noty_message', visible: :all) + expect(noty_message).to have_text(error_message) + end + end + end + + context 'with valid fields' do + before do + visit 'profile/token_access' + + within :active_content do + find('.content.active .js-create').click + + within '.modal' do + fill_in 'label', with: label + checkbox = find(checkbox_input, visible: :all) + checkbox.check allow_label_click: true + find('.js-datepicker').fill_in with: expiry_date + send_keys(:tab) + click_button + end + end + end + + context 'with expire date' do + it 'generates a new personal token' do + expect(page).to have_selector('.form-control.input.js-select') + .and have_text('Your New Personal Access Token') + end + + it 'shows active report profile' do + within :active_content do + click_button + + expect(token_list).to have_text(label) + .and have_text(expiry_date) + end + end + end + + context 'without expire date' do + let(:expiry_date) { nil } + + it 'generates a new personal token' do + expect(page).to have_selector('.form-control.input.js-select') + .and have_text('Your New Personal Access Token') + end + + it 'shows active report profile' do + within :active_content do + click_button + + expect(token_list).to have_text(label) + end + end + end + end + + context 'with invalid fields' do + before do + visit 'profile/token_access' + + within :active_content do + find('.content.active .js-create').click + + within '.modal' do + fill_in 'label', with: label + send_keys(:tab) + end + end + end + + context 'without label' do + let(:label) { nil } + let(:error_message) { 'Need label!' } + + before do + checkbox = find(checkbox_input, visible: :all) + checkbox.check allow_label_click: true + click_button + end + + it_behaves_like 'having an error notification message' + end + + context 'without permission' do + let(:label) { nil } + let(:error_message) { 'Minimum of one permission is needed!' } + + before { click_button } + + it_behaves_like 'having an error notification message' + end + end + + context 'with already created token', authenticated_as: -> { admin_user } do + let(:admin_user) { create(:admin) } + let(:create_token) do + create(:api_token, + user: admin_user, + label: label, + preferences: { permission: %w[admin ticket.agent] }) + end + + before do + create_token + visit 'profile/token_access' + end + + it 'shows the created token' do + expect(token_list).to have_text(label) + end + + it 'deletes created token' do + token_delete_button = find('.js-tokenList tr .js-delete') + token_delete_button.click + + within '.modal' do + click_button + end + + expect(token_list).to have_no_text(label) + end + end +end diff --git a/test/browser/preferences_token_access_test.rb b/test/browser/preferences_token_access_test.rb deleted file mode 100644 index ca0ccb1b4..000000000 --- a/test/browser/preferences_token_access_test.rb +++ /dev/null @@ -1,88 +0,0 @@ -# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ - -require 'browser_test_helper' - -class PreferencesTokenAccessTest < TestCase - - def test_token_access - @browser = browser_instance - login( - username: 'agent1@example.com', - password: 'test', - url: browser_url, - ) - tasks_close_all - click(css: 'a[href="#current_user"]') - click(css: 'a[href="#profile"]') - click(css: 'a[href="#profile/token_access"]') - - click(css: '.content.active .js-create') - - modal_ready - set( - css: '.content.active .modal .js-input', - value: 'Some App#1', - ) - set( - css: '.content.active .modal .js-datepicker', - value: '05/15/2022', - ) - sendkey(value: :tab) - click(css: '.content.active .modal input[value="ticket.agent"] ~ .label-text') - click(css: '.content.active .modal .js-submit') - watch_for( - css: '.modal .modal-title', - value: 'Your New Personal Access Token' - ) - click(css: '.modal .js-submit') - modal_disappear - - watch_for( - css: '.content.active .js-tokenList', - value: 'Some App#1' - ) - watch_for( - css: '.content.active .js-tokenList', - value: '05/15/2022' - ) - - click(css: '.content.active .js-create') - - modal_ready - set( - css: '.content.active .modal .js-input', - value: 'Some App#2', - ) - click(css: '.content.active .modal input[value="ticket.agent"] ~ .label-text') - click(css: '.content.active .modal .js-submit') - - watch_for( - css: '.modal .modal-title', - value: 'Your New Personal Access Token' - ) - click(css: '.modal .js-submit') - modal_disappear - - watch_for( - css: '.content.active .js-tokenList', - value: 'Some App#2' - ) - - click(css: '.content.active .js-tokenList .js-delete') - - modal_ready - watch_for( - css: '.content.active .modal .modal-header', - value: 'confirm', - ) - click( - css: '.content.active .modal .js-submit', - ) - modal_disappear - watch_for_disappear( - css: '.content.active .js-tokenList', - value: 'Some App#2' - ) - - end -end