Commit 7e3ac732 authored by Stan Hu's avatar Stan Hu Committed by Rémy Coutable

Merge branch 'fix-spinach-compare-tests' into 'master'

Fix broken Spinach tests caused by changes in !6550

!6550 added dropdowns for the branch "from" and "to" fields, but these Spinach tests were not updated accordingly.

Partial fix to #23378

See merge request !6910
parent b777bd73
...@@ -9,7 +9,10 @@ ...@@ -9,7 +9,10 @@
var $dropdown, selected; var $dropdown, selected;
$dropdown = $(this); $dropdown = $(this);
selected = $dropdown.data('selected'); selected = $dropdown.data('selected');
return $dropdown.glDropdown({ const $dropdownContainer = $dropdown.closest('.dropdown');
const $fieldInput = $(`input[name="${$dropdown.data('field-name')}"]`, $dropdownContainer);
const $filterInput = $('input[type="search"]', $dropdownContainer);
$dropdown.glDropdown({
data: function(term, callback) { data: function(term, callback) {
return $.ajax({ return $.ajax({
url: $dropdown.data('refs-url'), url: $dropdown.data('refs-url'),
...@@ -42,6 +45,14 @@ ...@@ -42,6 +45,14 @@
return $el.text().trim(); return $el.text().trim();
} }
}); });
$filterInput.on('keyup', (e) => {
const keyCode = e.keyCode || e.which;
if (keyCode !== 13) return;
const text = $filterInput.val();
$fieldInput.val(text);
$('.dropdown-toggle-text', $dropdown).text(text);
$dropdownContainer.removeClass('open');
});
}); });
}; };
......
.dropdown-menu.dropdown-menu-selectable .dropdown-menu.dropdown-menu-selectable
= dropdown_title "Select branch/tag" = dropdown_title "Select Git revision"
= dropdown_filter "Filter by branch/tag" = dropdown_filter "Filter by Git revision"
= dropdown_content = dropdown_content
= dropdown_loading = dropdown_loading
...@@ -34,15 +34,16 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps ...@@ -34,15 +34,16 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps
end end
step 'I fill compare fields with branches' do step 'I fill compare fields with branches' do
fill_in 'from', with: 'feature' select_using_dropdown('from', 'feature')
fill_in 'to', with: 'master' select_using_dropdown('to', 'master')
click_button 'Compare' click_button 'Compare'
end end
step 'I fill compare fields with refs' do step 'I fill compare fields with refs' do
fill_in "from", with: sample_commit.parent_id select_using_dropdown('from', sample_commit.parent_id, true)
fill_in "to", with: sample_commit.id select_using_dropdown('to', sample_commit.id, true)
click_button "Compare" click_button "Compare"
end end
...@@ -89,8 +90,8 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps ...@@ -89,8 +90,8 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps
end end
step 'I fill compare fields with branches' do step 'I fill compare fields with branches' do
fill_in 'from', with: 'master' select_using_dropdown('from', 'master')
fill_in 'to', with: 'feature' select_using_dropdown('to', 'feature')
click_button 'Compare' click_button 'Compare'
end end
...@@ -174,4 +175,15 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps ...@@ -174,4 +175,15 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps
expect(page).to have_content "More submodules" expect(page).to have_content "More submodules"
expect(page).not_to have_content "Change some files" expect(page).not_to have_content "Change some files"
end end
def select_using_dropdown(dropdown_type, selection, is_commit = false)
dropdown = find(".js-compare-#{dropdown_type}-dropdown")
dropdown.find(".compare-dropdown-toggle").click
dropdown.fill_in("Filter by Git revision", with: selection)
if is_commit
dropdown.find('input[type="search"]').send_keys(:return)
else
find_link(selection, visible: true).click
end
end
end end
...@@ -45,6 +45,6 @@ describe "Compare", js: true do ...@@ -45,6 +45,6 @@ describe "Compare", js: true do
dropdown = find(".js-compare-#{dropdown_type}-dropdown") dropdown = find(".js-compare-#{dropdown_type}-dropdown")
dropdown.find(".compare-dropdown-toggle").click dropdown.find(".compare-dropdown-toggle").click
dropdown.fill_in("Filter by branch/tag", with: selection) dropdown.fill_in("Filter by branch/tag", with: selection)
click_link selection find_link(selection, visible: true).click
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