From 1231c5a188574c998bddf836cb60ae13ebc8fbc4 Mon Sep 17 00:00:00 2001 From: Chris Huynh Date: Wed, 4 Dec 2024 08:51:45 -0600 Subject: [PATCH] cleanup, add tests --- .../controllers/token_controller.js | 2 - config/locales/en.yml | 2 +- config/locales/fr.yml | 2 +- test/system/groups/bots_test.rb | 73 ++++++++++++++++++ test/system/projects/bots_test.rb | 74 ++++++++++++++++++- 5 files changed, 147 insertions(+), 6 deletions(-) diff --git a/app/javascript/controllers/token_controller.js b/app/javascript/controllers/token_controller.js index da897fc14f..9db6b63ba7 100644 --- a/app/javascript/controllers/token_controller.js +++ b/app/javascript/controllers/token_controller.js @@ -38,9 +38,7 @@ export default class extends Controller { removeTokenPanel() { let panel = document.getElementById("access-token-section"); - console.log(panel); if (panel) { - console.log("hi"); panel.remove(); } } diff --git a/config/locales/en.yml b/config/locales/en.yml index 6b30956118..71f59e8fcf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -340,7 +340,7 @@ en: username: Username never: Never new_destroy: - description: Are you sure you want to delete bot %{bot_name}? + description: This action will permanently delete the bot account and will remove any existing memberships for the bot account. Are you sure you want to permanently delete bot account %{bot_name}? submit_button: Confirm title: Delete Bot components: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 3b8d7b5001..e19c8651b2 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -340,7 +340,7 @@ fr: username: Username never: Never new_destroy: - description: Are you sure you want to delete bot %{bot_name}? + description: This action will permanently delete the bot account and will remove any existing memberships for the bot account. Are you sure you want to permanently delete bot account %{bot_name}? submit_button: Confirm title: Delete Bot components: diff --git a/test/system/groups/bots_test.rb b/test/system/groups/bots_test.rb index 842fc54d51..6aac706c58 100644 --- a/test/system/groups/bots_test.rb +++ b/test/system/groups/bots_test.rb @@ -266,5 +266,78 @@ def setup end end end + + test 'PAT panel removed after personal access token revoke' do + namespace_bot = namespace_bots(:group1_bot0) + active_personal_tokens = namespace_bot.user.personal_access_tokens.active + token = nil + + visit group_bots_path(@namespace) + + assert_no_selector '#access-token-section div' + + click_link I18n.t(:'projects.bots.index.add_new_bot') + + within('dialog') do + fill_in 'Token Name', with: 'Uploader' + find('#bot_access_level').find('option', + text: I18n.t('activerecord.models.member.access_level.analyst')).select_option + + all('input[type=checkbox]').each(&:click) + + click_button I18n.t(:'projects.bots.index.bot_listing.new_bot_modal.submit') + end + + assert_selector '#access-token-section div' + + within "tr[id='#{namespace_bot.id}']" do + click_link active_personal_tokens.count.to_s + end + + within('dialog table') do + assert_selector 'tr', count: 2 + token = active_personal_tokens.first + + within "tr[id='#{token.id}']" do + click_link 'Revoke' + end + end + + within('dialog') do + click_button 'Confirm' + end + + assert_no_selector '#access-token-section div' + end + + test 'PAT panel removed after bot destroy' do + visit group_bots_path(@namespace) + + assert_no_selector '#access-token-section div' + + click_link I18n.t(:'groups.bots.index.add_new_bot') + + within('dialog') do + fill_in 'Token Name', with: 'Uploader' + find('#bot_access_level').find('option', + text: I18n.t('activerecord.models.member.access_level.analyst')).select_option + + all('input[type=checkbox]').each(&:click) + + click_button I18n.t(:'groups.bots.index.bot_listing.new_bot_modal.submit') + end + + assert_selector '#access-token-section div' + + within('table tbody tr:first-child td:last-child') do + click_link I18n.t(:'bots.index.table.actions.remove') + end + + within('#dialog') do + click_button 'Confirm' + end + + assert_no_selector '#access-token-section div' + end end end diff --git a/test/system/projects/bots_test.rb b/test/system/projects/bots_test.rb index ed3d121b43..b4c797b6b0 100644 --- a/test/system/projects/bots_test.rb +++ b/test/system/projects/bots_test.rb @@ -263,13 +263,83 @@ def setup within('dialog') do click_button 'Confirm' + within('#personal-access-token-alert') do + assert_text I18n.t('concerns.bot_personal_access_token_actions.revoke.success', pat_name: token.name) + end end + end + + test 'PAT panel removed after personal access token revoke' do + namespace_bot = namespace_bots(:project1_bot0) + active_personal_tokens = namespace_bot.user.personal_access_tokens.active + token = nil + + visit namespace_project_bots_path(@namespace, @project) + + assert_no_selector '#access-token-section div' + + click_link I18n.t(:'projects.bots.index.add_new_bot') within('dialog') do - within('#personal-access-token-alert') do - assert_text I18n.t('concerns.bot_personal_access_token_actions.revoke.success', pat_name: token.name) + fill_in 'Token Name', with: 'Uploader' + find('#bot_access_level').find('option', + text: I18n.t('activerecord.models.member.access_level.analyst')).select_option + + all('input[type=checkbox]').each(&:click) + + click_button I18n.t(:'projects.bots.index.bot_listing.new_bot_modal.submit') + end + + assert_selector '#access-token-section div' + + within "tr[id='#{namespace_bot.id}']" do + click_link active_personal_tokens.count.to_s + end + + within('dialog table') do + assert_selector 'tr', count: 2 + token = active_personal_tokens.first + + within "tr[id='#{token.id}']" do + click_link 'Revoke' end end + + within('dialog') do + click_button 'Confirm' + end + + assert_no_selector '#access-token-section div' + end + + test 'PAT panel removed after bot destroy' do + visit namespace_project_bots_path(@namespace, @project) + + assert_no_selector '#access-token-section div' + + click_link I18n.t(:'projects.bots.index.add_new_bot') + + within('dialog') do + fill_in 'Token Name', with: 'Uploader' + find('#bot_access_level').find('option', + text: I18n.t('activerecord.models.member.access_level.analyst')).select_option + + all('input[type=checkbox]').each(&:click) + + click_button I18n.t(:'projects.bots.index.bot_listing.new_bot_modal.submit') + end + + assert_selector '#access-token-section div' + + within('table tbody tr:first-child td:last-child') do + click_link I18n.t(:'bots.index.table.actions.remove') + end + + within('#dialog') do + click_button 'Confirm' + end + + assert_no_selector '#access-token-section div' end end end