Commit b26853f6 authored by Jose Vargas's avatar Jose Vargas

Encapsulate code and change matchers

This encapsulates commonly use code into a
`fill_variable` function, also changes the `not_to be_nil`
matchers to `to be_present`
parent a32d945f
---
name: new_variables_ui
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/25260
rollout_issue_url:
group: group::continuous integration
type: development
default_enabled: true
...@@ -10,10 +10,7 @@ RSpec.shared_examples 'variable list' do ...@@ -10,10 +10,7 @@ RSpec.shared_examples 'variable list' do
it 'adds a new CI variable' do it 'adds a new CI variable' do
click_button('Add Variable') click_button('Add Variable')
page.within('#add-ci-variable') do fill_variable('key', 'key_value') do
find('[data-qa-selector="ci_variable_key_field"] input').set('key')
find('#ci-variable-value').set('key_value')
click_button('Add variable') click_button('Add variable')
end end
...@@ -27,10 +24,7 @@ RSpec.shared_examples 'variable list' do ...@@ -27,10 +24,7 @@ RSpec.shared_examples 'variable list' do
it 'adds a new protected variable' do it 'adds a new protected variable' do
click_button('Add Variable') click_button('Add Variable')
page.within('#add-ci-variable') do fill_variable('key', 'key_value') do
find('[data-qa-selector="ci_variable_key_field"] input').set('key')
find('#ci-variable-value').set('key_value')
click_button('Add variable') click_button('Add variable')
end end
...@@ -38,17 +32,14 @@ RSpec.shared_examples 'variable list' do ...@@ -38,17 +32,14 @@ RSpec.shared_examples 'variable list' do
page.within('.ci-variable-table') do page.within('.ci-variable-table') do
expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Key"]').text).to eq('key') expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Key"]').text).to eq('key')
expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Protected"] svg[data-testid="mobile-issue-close-icon"]')).not_to be_nil expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Protected"] svg[data-testid="mobile-issue-close-icon"]')).to be_present
end end
end end
it 'defaults to unmasked' do it 'defaults to unmasked' do
click_button('Add Variable') click_button('Add Variable')
page.within('#add-ci-variable') do fill_variable('key', 'key_value') do
find('[data-qa-selector="ci_variable_key_field"] input').set('key')
find('#ci-variable-value').set('key_value')
click_button('Add variable') click_button('Add variable')
end end
...@@ -56,7 +47,7 @@ RSpec.shared_examples 'variable list' do ...@@ -56,7 +47,7 @@ RSpec.shared_examples 'variable list' do
page.within('.ci-variable-table') do page.within('.ci-variable-table') do
expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Key"]').text).to eq('key') expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Key"]').text).to eq('key')
expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Masked"] svg[data-testid="close-icon"]')).not_to be_nil expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Masked"] svg[data-testid="close-icon"]')).to be_present
end end
end end
...@@ -125,7 +116,7 @@ RSpec.shared_examples 'variable list' do ...@@ -125,7 +116,7 @@ RSpec.shared_examples 'variable list' do
wait_for_requests wait_for_requests
page.within('.ci-variable-table') do page.within('.ci-variable-table') do
expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Masked"] svg[data-testid="close-icon"]')).not_to be_nil expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Masked"] svg[data-testid="close-icon"]')).to be_present
end end
end end
...@@ -153,17 +144,14 @@ RSpec.shared_examples 'variable list' do ...@@ -153,17 +144,14 @@ RSpec.shared_examples 'variable list' do
end end
page.within('.ci-variable-table') do page.within('.ci-variable-table') do
expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Masked"] svg[data-testid="mobile-issue-close-icon"]')).not_to be_nil expect(find('.js-ci-variable-row:nth-child(1) td[data-label="Masked"] svg[data-testid="mobile-issue-close-icon"]')).to be_present
end end
end end
it 'shows a validation error box about duplicate keys' do it 'shows a validation error box about duplicate keys' do
click_button('Add Variable') click_button('Add Variable')
page.within('#add-ci-variable') do fill_variable('key', 'key_value') do
find('[data-qa-selector="ci_variable_key_field"] input').set('key')
find('#ci-variable-value').set('key_value')
click_button('Add variable') click_button('Add variable')
end end
...@@ -171,16 +159,13 @@ RSpec.shared_examples 'variable list' do ...@@ -171,16 +159,13 @@ RSpec.shared_examples 'variable list' do
click_button('Add Variable') click_button('Add Variable')
page.within('#add-ci-variable') do fill_variable('key', 'key_value') do
find('[data-qa-selector="ci_variable_key_field"] input').set('key')
find('#ci-variable-value').set('key_value')
click_button('Add variable') click_button('Add variable')
end end
wait_for_requests wait_for_requests
expect(find('.flash-container')).not_to be_nil expect(find('.flash-container')).to be_present
expect(find('.flash-text').text).to have_content('Variables key (key) has already been taken') expect(find('.flash-text').text).to have_content('Variables key (key) has already been taken')
end end
...@@ -192,21 +177,16 @@ RSpec.shared_examples 'variable list' do ...@@ -192,21 +177,16 @@ RSpec.shared_examples 'variable list' do
find('[data-testid="ci-variable-protected-checkbox"]').click find('[data-testid="ci-variable-protected-checkbox"]').click
find('[data-testid="ci-variable-masked-checkbox"]').click find('[data-testid="ci-variable-masked-checkbox"]').click
expect(find_button('Add variable', disabled: true)).not_to be_nil expect(find_button('Add variable', disabled: true)).to be_present
end end
end end
it 'shows validation error box about unmaskable values' do it 'shows validation error box about unmaskable values' do
click_button('Add Variable') click_button('Add Variable')
page.within('#add-ci-variable') do fill_variable('empty_mask_key', '???', protected: true, masked: true) do
find('[data-qa-selector="ci_variable_key_field"] input').set('empty_mask_key') expect(page).to have_content('This variable can not be masked')
find('#ci-variable-value').set('???') expect(find_button('Add variable', disabled: true)).to be_present
find('[data-testid="ci-variable-protected-checkbox"]').click
find('[data-testid="ci-variable-masked-checkbox"]').click
expect(find('div.invalid-feedback').text).to have_content('This variable can not be masked')
expect(find_button('Add variable', disabled: true)).not_to be_nil
end end
end end
...@@ -214,10 +194,7 @@ RSpec.shared_examples 'variable list' do ...@@ -214,10 +194,7 @@ RSpec.shared_examples 'variable list' do
# Create two variables # Create two variables
click_button('Add Variable') click_button('Add Variable')
page.within('#add-ci-variable') do fill_variable('akey', 'akeyvalue') do
find('[data-qa-selector="ci_variable_key_field"] input').set('akey')
find('#ci-variable-value').set('akeyvalue')
click_button('Add variable') click_button('Add variable')
end end
...@@ -225,10 +202,7 @@ RSpec.shared_examples 'variable list' do ...@@ -225,10 +202,7 @@ RSpec.shared_examples 'variable list' do
click_button('Add Variable') click_button('Add Variable')
page.within('#add-ci-variable') do fill_variable('zkey', 'zkeyvalue') do
find('[data-qa-selector="ci_variable_key_field"] input').set('zkey')
find('#ci-variable-value').set('zkeyvalue')
click_button('Add variable') click_button('Add variable')
end end
...@@ -252,16 +226,13 @@ RSpec.shared_examples 'variable list' do ...@@ -252,16 +226,13 @@ RSpec.shared_examples 'variable list' do
# Add another variable # Add another variable
click_button('Add Variable') click_button('Add Variable')
page.within('#add-ci-variable') do fill_variable('ckey', 'ckeyvalue') do
find('[data-qa-selector="ci_variable_key_field"] input').set('ckey')
find('#ci-variable-value').set('ckeyvalue')
click_button('Add variable') click_button('Add variable')
end end
wait_for_requests wait_for_requests
# expect to find 3 rows of variales in alphabetical order # expect to find 3 rows of variables in alphabetical order
expect(page).to have_selector('.js-ci-variable-row', count: 3) expect(page).to have_selector('.js-ci-variable-row', count: 3)
rows = all('.js-ci-variable-row') rows = all('.js-ci-variable-row')
expect(rows[0].find('td[data-label="Key"]').text).to eq('ckey') expect(rows[0].find('td[data-label="Key"]').text).to eq('ckey')
...@@ -281,7 +252,7 @@ RSpec.shared_examples 'variable list' do ...@@ -281,7 +252,7 @@ RSpec.shared_examples 'variable list' do
click_button('Add Variable') click_button('Add Variable')
page.within('#add-ci-variable') do page.within('#add-ci-variable') do
expect(find('[data-testid="ci-variable-protected-checkbox"]').checked?).to be(true) expect(find('[data-testid="ci-variable-protected-checkbox"]')).to be_checked
end end
end end
...@@ -301,7 +272,7 @@ RSpec.shared_examples 'variable list' do ...@@ -301,7 +272,7 @@ RSpec.shared_examples 'variable list' do
click_button('Add Variable') click_button('Add Variable')
page.within('#add-ci-variable') do page.within('#add-ci-variable') do
expect(find('[data-testid="ci-variable-protected-checkbox"]').checked?).to be(false) expect(find('[data-testid="ci-variable-protected-checkbox"]')).not_to be_checked
end end
end end
...@@ -310,4 +281,15 @@ RSpec.shared_examples 'variable list' do ...@@ -310,4 +281,15 @@ RSpec.shared_examples 'variable list' do
end end
end end
end end
def fill_variable(key, value, protected: false, masked: false)
page.within('#add-ci-variable') do
find('[data-qa-selector="ci_variable_key_field"] input').set(key)
find('[data-qa-selector="ci_variable_value_field"]').set(value) if value.present?
find('[data-testid="ci-variable-protected-checkbox"]').click if protected
find('[data-testid="ci-variable-masked-checkbox"]').click if masked
yield
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment