From e42169c28e14f4dbc6e4d35ae189b73d90278c42 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 23 Feb 2017 17:48:44 +0000 Subject: [PATCH] Updates SSH key title after pasting key Previously it was listening for focusout, it now listens for blur & paste events Closes #28436 --- app/assets/javascripts/profile/profile.js.es6 | 7 ++++--- changelogs/unreleased/ssh-key-paste.yml | 4 ++++ spec/features/profiles/keys_spec.rb | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 changelogs/unreleased/ssh-key-paste.yml diff --git a/app/assets/javascripts/profile/profile.js.es6 b/app/assets/javascripts/profile/profile.js.es6 index 81374296522..4ccea0624ee 100644 --- a/app/assets/javascripts/profile/profile.js.es6 +++ b/app/assets/javascripts/profile/profile.js.es6 @@ -84,13 +84,14 @@ } $(function() { - $(document).on('focusout.ssh_key', '#key_key', function() { + $(document).on('input.ssh_key', '#key_key', function() { const $title = $('#key_title'); const comment = $(this).val().match(/^\S+ \S+ (.+)\n?$/); - if (comment && comment.length > 1 && $title.val() === '') { + + // Extract the SSH Key title from its comment + if (comment && comment.length > 1) { return $title.val(comment[1]).change(); } - // Extract the SSH Key title from its comment }); if (global.utils.getPagePath() === 'profiles') { return new Profile(); diff --git a/changelogs/unreleased/ssh-key-paste.yml b/changelogs/unreleased/ssh-key-paste.yml new file mode 100644 index 00000000000..1e34ef60f6e --- /dev/null +++ b/changelogs/unreleased/ssh-key-paste.yml @@ -0,0 +1,4 @@ +--- +title: SSH key field updates title after pasting key +merge_request: +author: diff --git a/spec/features/profiles/keys_spec.rb b/spec/features/profiles/keys_spec.rb index eb1050d21c6..2f436f153aa 100644 --- a/spec/features/profiles/keys_spec.rb +++ b/spec/features/profiles/keys_spec.rb @@ -15,7 +15,7 @@ feature 'Profile > SSH Keys', feature: true do scenario 'auto-populates the title', js: true do fill_in('Key', with: attributes_for(:key).fetch(:key)) - expect(find_field('Title').value).to eq 'dummy@gitlab.com' + expect(page).to have_field("Title", with: "dummy@gitlab.com") end scenario 'saves the new key' do