From 90f82ebbe71475c88f81bbd24f1525a20d05320a Mon Sep 17 00:00:00 2001 From: Lukas Eipert Date: Fri, 25 Jan 2019 13:15:42 +0100 Subject: status quo --- app/assets/javascripts/gfm_auto_complete.js | 13 ++++++++ spec/features/issues/gfm_autocomplete_spec.rb | 47 ++++++++++++++++++++------- vendor/assets/javascripts/jquery.atwho.js | 5 +++ 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/gfm_auto_complete.js b/app/assets/javascripts/gfm_auto_complete.js index 570d3b712e0..b232494cd73 100644 --- a/app/assets/javascripts/gfm_auto_complete.js +++ b/app/assets/javascripts/gfm_auto_complete.js @@ -325,6 +325,7 @@ class GfmAutoComplete { searchKey: 'search', data: GfmAutoComplete.defaultLoadingData, displayTpl(value) { + console.warn('Display template called') let tmpl = GfmAutoComplete.Labels.templateFunction(value.color, value.title); if (GfmAutoComplete.isLoading(value)) { tmpl = GfmAutoComplete.Loading.template; @@ -336,6 +337,7 @@ class GfmAutoComplete { callbacks: { ...this.getDefaultCallbacks(), beforeSave(merges) { + console.warn('beforeSave') if (GfmAutoComplete.isLoading(merges)) return merges; return $.map(merges, m => ({ title: sanitize(m.title), @@ -358,6 +360,7 @@ class GfmAutoComplete { node === LABEL_COMMAND.RELABEL || node === LABEL_COMMAND.UNLABEL ) { + console.warn('yay') return node; } return null; @@ -375,6 +378,8 @@ class GfmAutoComplete { return $.fn.atwho.default.callbacks.filter(query, data, searchKey); } + console.warn('yay2',command) + // The `LABEL_COMMAND.RELABEL` is intentionally skipped // because we want to return all the labels (unfiltered) for that command. if (command === LABEL_COMMAND.LABEL) { @@ -444,6 +449,7 @@ class GfmAutoComplete { return $.fn.atwho.default.callbacks.filter(query, data, searchKey); }, beforeInsert(value) { + console.warn('veforeInsert') let withoutAt = value.substring(1); const at = value.charAt(); @@ -474,14 +480,18 @@ class GfmAutoComplete { } fetchData($input, at) { + console.warn('fetchData 1') if (this.isLoadingData[at]) return; this.isLoadingData[at] = true; const dataSource = this.dataSources[GfmAutoComplete.atTypeMap[at]]; if (this.cachedData[at]) { + console.warn('fetchData 2') this.loadData($input, at, this.cachedData[at]); + this.isLoadingData[at] = false; } else if (GfmAutoComplete.atTypeMap[at] === 'emojis') { + console.warn('fetchData 3') import(/* webpackChunkName: 'emoji' */ './emoji') .then(({ validEmojiNames, glEmojiTag }) => { this.loadData($input, at, validEmojiNames); @@ -491,6 +501,7 @@ class GfmAutoComplete { this.isLoadingData[at] = false; }); } else if (dataSource) { + console.warn('fetchData 4') AjaxCache.retrieve(dataSource, true) .then(data => { this.loadData($input, at, data); @@ -499,12 +510,14 @@ class GfmAutoComplete { this.isLoadingData[at] = false; }); } else { + console.warn('fetchData 5') this.isLoadingData[at] = false; } } loadData($input, at, data) { this.isLoadingData[at] = false; + console.warn(at, data.length, JSON.stringify(data)) this.cachedData[at] = data; $input.atwho('load', at, data); // This trigger at.js again diff --git a/spec/features/issues/gfm_autocomplete_spec.rb b/spec/features/issues/gfm_autocomplete_spec.rb index 3b7a17ef355..6928eb87ca9 100644 --- a/spec/features/issues/gfm_autocomplete_spec.rb +++ b/spec/features/issues/gfm_autocomplete_spec.rb @@ -3,14 +3,14 @@ require 'rails_helper' describe 'GFM autocomplete', :js do let(:issue_xss_title) { 'This will execute alert true do it 'shows labels' do note = find('#note-body') @@ -309,20 +309,32 @@ describe 'GFM autocomplete', :js do expect_labels(shown: [backend, bug, feature_proposal]) # It should show all the labels on "/label ~". - type(note, '/label ~') + type(note, '/label') + wait_for_requests + sleep 1 + note.native.send_keys :space, '~' + sleep 1 expect_labels(shown: [backend, bug, feature_proposal]) # It should show all the labels on "/relabel ~". - type(note, '/relabel ~') + type(note, '/relabel') + wait_for_requests + sleep 1 + note.native.send_keys :space, '~' + sleep 1 expect_labels(shown: [backend, bug, feature_proposal]) # It should show no labels on "/unlabel ~". - type(note, '/unlabel ~') + type(note, '/unlabel') + wait_for_requests + sleep 1 + note.native.send_keys :space, '~' + sleep 1 expect_labels(not_shown: [backend, bug, feature_proposal]) end end - context 'when some labels are assigned' do + context 'when some labels are assigned', :focus => true do before do issue.labels << [backend] end @@ -337,19 +349,22 @@ describe 'GFM autocomplete', :js do # It should show only unset labels on "/label ~". type(note, '/label ~') + wait_for_requests expect_labels(shown: [bug, feature_proposal], not_shown: [backend]) # It should show all the labels on "/relabel ~". type(note, '/relabel ~') + wait_for_requests expect_labels(shown: [backend, bug, feature_proposal]) # It should show only set labels on "/unlabel ~". type(note, '/unlabel ~') + wait_for_requests expect_labels(shown: [backend], not_shown: [bug, feature_proposal]) end end - context 'when all labels are assigned' do + context 'when all labels are assigned', :focus => true do before do issue.labels << [backend, bug, feature_proposal] end @@ -364,14 +379,17 @@ describe 'GFM autocomplete', :js do # It should show no labels on "/label ~". type(note, '/label ~') + wait_for_requests expect_labels(not_shown: [backend, bug, feature_proposal]) # It should show all the labels on "/relabel ~". type(note, '/relabel ~') + wait_for_requests expect_labels(shown: [backend, bug, feature_proposal]) # It should show all the labels on "/unlabel ~". type(note, '/unlabel ~') + wait_for_requests expect_labels(shown: [backend, bug, feature_proposal]) end end @@ -444,7 +462,12 @@ describe 'GFM autocomplete', :js do end def expect_labels(shown: nil, not_shown: nil) - page.within('.atwho-container') do + + if shown + find('#at-view-labels') + end + + page.within('.atwho-container ') do if shown expect(page).to have_selector('.atwho-view li', count: shown.size) shown.each { |label| expect(page).to have_content(label.title) } diff --git a/vendor/assets/javascripts/jquery.atwho.js b/vendor/assets/javascripts/jquery.atwho.js index e058e13303a..ffa9ba9315c 100644 --- a/vendor/assets/javascripts/jquery.atwho.js +++ b/vendor/assets/javascripts/jquery.atwho.js @@ -881,6 +881,7 @@ Model = (function() { }; Model.prototype.load = function(data) { + console.warn('LOAD') if (!(this.saved() || !data)) { return this._load(data); } @@ -891,6 +892,7 @@ Model = (function() { }; Model.prototype._load = function(data) { + console.warn('2') if (typeof data === "string") { return $.ajax(data, { dataType: "json" @@ -1047,12 +1049,14 @@ View = (function() { }; View.prototype.show = function() { + console.warn('SHOW') var rect; if (this.stopShowing) { this.stopShowing = false; return; } if (!this.visible()) { + console.warn('showing') this.$el.show(); this.$el.scrollTop(0); this.context.trigger('shown'); @@ -1115,6 +1119,7 @@ var Api; Api = { load: function(at, data) { var c; + console.warn('LOAD', at, this.controller(at)) if (c = this.controller(at)) { return c.model.load(data); } -- cgit v1.2.3