Skip to content

Commit

Permalink
cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisHuynh333 committed Dec 19, 2024
1 parent 2bae412 commit 4e3bf47
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 33 deletions.
47 changes: 33 additions & 14 deletions test/system/groups/bots_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,76 +268,95 @@ def setup
end

test 'PAT panel removed after personal access token revoke' do
### SETUP START ###
namespace_bot = namespace_bots(:group1_bot0)
active_personal_tokens = namespace_bot.user.personal_access_tokens.active
token = nil

visit group_bots_path(@namespace)

# PAT panel is not present
assert_no_selector '#access-token-section div'

click_link I18n.t(:'projects.bots.index.add_new_bot')
# create new bot to render PAT panel
click_link I18n.t(:'groups.bots.index.add_new_bot')

within('dialog') do
fill_in 'Token Name', with: 'Uploader'
fill_in I18n.t('groups.bots.index.bot_listing.new_bot_modal.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')
click_button I18n.t(:'groups.bots.index.bot_listing.new_bot_modal.submit')
end

# PAT panel now present
assert_selector '#access-token-section div'
### SETUP END ###

### ACTIONS START ###
within "tr[id='#{namespace_bot.id}']" do
# click active tokens number
click_link active_personal_tokens.count.to_s
end

within('dialog table') do
# bot's current PATs dialog
within('#dialog table') do
assert_selector 'tr', count: 2
token = active_personal_tokens.first

within "tr[id='#{token.id}']" do
click_link 'Revoke'
# revoke a PAT
click_link I18n.t('personal_access_tokens.table.revoke')
end
end

within('dialog') do
click_button 'Confirm'
click_button I18n.t('personal_access_tokens.new_revoke.submit_button')
end
### ACTIONS END ###

### VERIFY START ###
# PAT panel no longer present
assert_no_selector '#access-token-section div'
### VERIFY END ###
end

test 'PAT panel removed after bot destroy' do
### SETUP START ###
visit group_bots_path(@namespace)

# PAT panel is not present
assert_no_selector '#access-token-section div'

# create new bot to render PAT panel
click_link I18n.t(:'groups.bots.index.add_new_bot')

within('dialog') do
fill_in 'Token Name', with: 'Uploader'
fill_in I18n.t('groups.bots.index.bot_listing.new_bot_modal.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

# PAT panel now present
assert_selector '#access-token-section div'
### SETUP END ###

### ACTIONS START ###
within('table tbody tr:first-child td:last-child') do
# destroy bot
click_link I18n.t(:'bots.index.table.actions.destroy')
end

within('#dialog') do
click_button 'Confirm'
# confirm destroy bot
click_button I18n.t('bots.new_destroy.submit_button')
end
### ACTIONS END ###

### VERIFY START ###
# PAT panel no longer present
assert_no_selector '#access-token-section div'
### VERIFY END ###
end
end
end
47 changes: 28 additions & 19 deletions test/system/projects/bots_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,76 +270,85 @@ def setup
end

test 'PAT panel removed after personal access token revoke' do
### SETUP START ###
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)

# PAT panel is not present
assert_no_selector '#access-token-section div'

# create new bot to render PAT panel
click_link I18n.t(:'projects.bots.index.add_new_bot')

within('dialog') do
fill_in 'Token Name', with: 'Uploader'
fill_in I18n.t('projects.bots.index.bot_listing.new_bot_modal.token_name'), with: 'Uploader'
find('#bot_access_level').find('option',
text: I18n.t('activerecord.models.member.access_level.analyst')).select_option
text: I18n.t('activerecord.models.member.access_level.analyst')).select_option

Check warning on line 286 in test/system/projects/bots_test.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Align the arguments of a method call if they span more than one line. Raw Output: test/system/projects/bots_test.rb:286:41: C: Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.

all('input[type=checkbox]').each(&:click)

click_button I18n.t(:'projects.bots.index.bot_listing.new_bot_modal.submit')
end

# PAT panel now present
assert_selector '#access-token-section div'
### SETUP END ###

### ACTIONS START ###
within "tr[id='#{namespace_bot.id}']" do
# click active tokens number
click_link active_personal_tokens.count.to_s
end

within('dialog table') do
# bot's current PATs dialog
within('#dialog table') do
assert_selector 'tr', count: 2
token = active_personal_tokens.first

within "tr[id='#{token.id}']" do
click_link 'Revoke'
# revoke a PAT
click_link I18n.t('personal_access_tokens.table.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
### SETUP START ###
visit namespace_project_bots_path(@namespace, @project)

# PAT panel is not present
assert_no_selector '#access-token-section div'

# create new bot to render PAT panel
click_link I18n.t(:'projects.bots.index.add_new_bot')

within('dialog') do
fill_in 'Token Name', with: 'Uploader'
fill_in I18n.t('projects.bots.index.bot_listing.new_bot_modal.token_name'), with: 'Uploader'
find('#bot_access_level').find('option',
text: I18n.t('activerecord.models.member.access_level.analyst')).select_option
text: I18n.t('activerecord.models.member.access_level.analyst')).select_option

Check warning on line 326 in test/system/projects/bots_test.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Align the arguments of a method call if they span more than one line. Raw Output: test/system/projects/bots_test.rb:326:41: C: Layout/ArgumentAlignment: Align the arguments of a method call if they span more than one line.

all('input[type=checkbox]').each(&:click)

click_button I18n.t(:'projects.bots.index.bot_listing.new_bot_modal.submit')
end

# PAT panel now present
assert_selector '#access-token-section div'
### SETUP END ###

### ACTIONS START ###
within('table tbody tr:first-child td:last-child') do
# destroy bot
click_link I18n.t(:'bots.index.table.actions.destroy')
end

within('#dialog') do
click_button 'Confirm'
# confirm destroy bot
click_button I18n.t('bots.new_destroy.submit_button')
end
### ACTIONS END ###

### VERIFY START ###
# PAT panel no longer present
assert_no_selector '#access-token-section div'
### VERIFY END ###
end
end
end

0 comments on commit 4e3bf47

Please sign in to comment.