From d78c667d581dca6b75895f70f0ae6ebdd0f5d815 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 14 Oct 2016 16:47:55 -0700 Subject: [PATCH 1/2] Fix broken Spinach tests caused by changes in !6550 Partial fix to #23378 --- features/steps/project/commits/commits.rb | 20 ++++++++++++++------ spec/features/compare_spec.rb | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/features/steps/project/commits/commits.rb b/features/steps/project/commits/commits.rb index b8264f97687..fd7b1debd68 100644 --- a/features/steps/project/commits/commits.rb +++ b/features/steps/project/commits/commits.rb @@ -42,15 +42,16 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps end step 'I fill compare fields with branches' do - fill_in 'from', with: 'feature' - fill_in 'to', with: 'master' + select_using_dropdown('from', 'feature') + select_using_dropdown('to', 'master') click_button 'Compare' end step 'I fill compare fields with refs' do - fill_in "from", with: sample_commit.parent_id - fill_in "to", with: sample_commit.id + select_using_dropdown('from', sample_commit.parent_id) + select_using_dropdown('to', sample_commit.id) + click_button "Compare" end @@ -97,8 +98,8 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps end step 'I fill compare fields with branches' do - fill_in 'from', with: 'master' - fill_in 'to', with: 'feature' + select_using_dropdown('from', 'master') + select_using_dropdown('to', 'feature') click_button 'Compare' end @@ -182,4 +183,11 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps expect(page).to have_content "More submodules" expect(page).not_to have_content "Change some files" end + + def select_using_dropdown(dropdown_type, selection) + dropdown = find(".js-compare-#{dropdown_type}-dropdown") + dropdown.find(".compare-dropdown-toggle").click + dropdown.fill_in("Filter by branch/tag", with: selection) + find_link(selection, visible: true).click + end end diff --git a/spec/features/compare_spec.rb b/spec/features/compare_spec.rb index 33dfd0d5b62..c22109d19b6 100644 --- a/spec/features/compare_spec.rb +++ b/spec/features/compare_spec.rb @@ -45,6 +45,6 @@ describe "Compare", js: true do dropdown = find(".js-compare-#{dropdown_type}-dropdown") dropdown.find(".compare-dropdown-toggle").click dropdown.fill_in("Filter by branch/tag", with: selection) - click_link selection + find_link(selection, visible: true).click end end From 93e464f454ec997743048e34db5c848b4146d452 Mon Sep 17 00:00:00 2001 From: Luke Bennett Date: Sun, 16 Oct 2016 03:30:31 +0100 Subject: [PATCH 2/2] Added logic to handle a revision input that does not exist in the menu --- ...autocomplete.js => compare_autocomplete.js.es6} | 13 ++++++++++++- app/views/projects/compare/_ref_dropdown.html.haml | 4 ++-- features/steps/project/commits/commits.rb | 14 +++++++++----- 3 files changed, 23 insertions(+), 8 deletions(-) rename app/assets/javascripts/{compare_autocomplete.js => compare_autocomplete.js.es6} (72%) diff --git a/app/assets/javascripts/compare_autocomplete.js b/app/assets/javascripts/compare_autocomplete.js.es6 similarity index 72% rename from app/assets/javascripts/compare_autocomplete.js rename to app/assets/javascripts/compare_autocomplete.js.es6 index 294d2c9052c..9a2082d97e0 100644 --- a/app/assets/javascripts/compare_autocomplete.js +++ b/app/assets/javascripts/compare_autocomplete.js.es6 @@ -9,7 +9,10 @@ var $dropdown, selected; $dropdown = $(this); 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) { return $.ajax({ url: $dropdown.data('refs-url'), @@ -42,6 +45,14 @@ 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'); + }); }); }; diff --git a/app/views/projects/compare/_ref_dropdown.html.haml b/app/views/projects/compare/_ref_dropdown.html.haml index 27d928c87a0..05fb37cdc0f 100644 --- a/app/views/projects/compare/_ref_dropdown.html.haml +++ b/app/views/projects/compare/_ref_dropdown.html.haml @@ -1,5 +1,5 @@ .dropdown-menu.dropdown-menu-selectable - = dropdown_title "Select branch/tag" - = dropdown_filter "Filter by branch/tag" + = dropdown_title "Select Git revision" + = dropdown_filter "Filter by Git revision" = dropdown_content = dropdown_loading diff --git a/features/steps/project/commits/commits.rb b/features/steps/project/commits/commits.rb index fd7b1debd68..b08912de25f 100644 --- a/features/steps/project/commits/commits.rb +++ b/features/steps/project/commits/commits.rb @@ -49,8 +49,8 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps end step 'I fill compare fields with refs' do - select_using_dropdown('from', sample_commit.parent_id) - select_using_dropdown('to', sample_commit.id) + select_using_dropdown('from', sample_commit.parent_id, true) + select_using_dropdown('to', sample_commit.id, true) click_button "Compare" end @@ -184,10 +184,14 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps expect(page).not_to have_content "Change some files" end - def select_using_dropdown(dropdown_type, selection) + 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 branch/tag", with: selection) - find_link(selection, visible: true).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