Skip to content

Commit

Permalink
cleanup, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisHuynh333 committed Dec 19, 2024
1 parent 102da82 commit 1231c5a
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 6 deletions.
2 changes: 0 additions & 2 deletions app/javascript/controllers/token_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
73 changes: 73 additions & 0 deletions test/system/groups/bots_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
74 changes: 72 additions & 2 deletions test/system/projects/bots_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1231c5a

Please sign in to comment.