Commit f72c1bf1 authored by Clement Ho's avatar Clement Ho

Fix specs

parent e197f27f
...@@ -42,12 +42,17 @@ ...@@ -42,12 +42,17 @@
static filterHint(item, query) { static filterHint(item, query) {
const updatedItem = item; const updatedItem = item;
const { lastToken } = gl.FilteredSearchTokenizer.processTokens(query); let { lastToken } = gl.FilteredSearchTokenizer.processTokens(query);
lastToken = lastToken || '';
if (!lastToken) { if (!lastToken || query.split('').last() === ' ') {
updatedItem.droplab_hidden = false; updatedItem.droplab_hidden = false;
} else { } else if (lastToken) {
updatedItem.droplab_hidden = updatedItem.hint.indexOf(lastToken.toLowerCase()) === -1; const split = lastToken.split(':');
const tokenName = split[0].split(' ').last();
const match = updatedItem.hint.indexOf(tokenName.toLowerCase()) === -1;
updatedItem.droplab_hidden = tokenName ? match : false;
} }
return updatedItem; return updatedItem;
......
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
const value = input.value; const value = input.value;
const hasExistingValue = value.length !== 0; const hasExistingValue = value.length !== 0;
const { lastToken, searchToken } = gl.FilteredSearchTokenizer.processTokens(value); const { lastToken, searchToken } = gl.FilteredSearchTokenizer.processTokens(value);
const lastSearchToken = searchToken.split(' ').last();
// Find out what part of the token value the user has typed // Find out what part of the token value the user has typed
// and remove it from input before appending the selected token value // and remove it from input before appending the selected token value
...@@ -74,8 +75,8 @@ ...@@ -74,8 +75,8 @@
// Add 2 length to account for the length of the front and back quotes // Add 2 length to account for the length of the front and back quotes
const lengthToRemove = hasQuotes ? lastTokenString.length + 2 : lastTokenString.length; const lengthToRemove = hasQuotes ? lastTokenString.length + 2 : lastTokenString.length;
input.value = value.slice(0, -1 * (lengthToRemove)); input.value = value.slice(0, -1 * (lengthToRemove));
} else if (searchToken !== '' && word.indexOf(searchToken) !== -1) { } else if (searchToken !== '' && word.indexOf(lastSearchToken) !== -1) {
input.value = value.slice(0, -1 * searchToken.length); input.value = value.slice(0, -1 * lastSearchToken.length);
} }
input.value += hasExistingValue && addSpace ? ` ${word}` : word; input.value += hasExistingValue && addSpace ? ` ${word}` : word;
...@@ -150,11 +151,17 @@ ...@@ -150,11 +151,17 @@
const { lastToken, searchToken } = this.tokenizer const { lastToken, searchToken } = this.tokenizer
.processTokens(this.filteredSearchInput.value); .processTokens(this.filteredSearchInput.value);
if (lastToken === searchToken) { if (this.filteredSearchInput.value.split('').last() === ' ') {
this.updateCurrentDropdownOffset();
}
if (lastToken === searchToken && lastToken !== null) {
// Token is not fully initialized yet because it has no value // Token is not fully initialized yet because it has no value
// Eg. token = 'label:' // Eg. token = 'label:'
const split = lastToken.split(':'); const split = lastToken.split(':');
this.loadDropdown(split.length > 1 ? split[0] : ''); const dropdownName = split[0].split(' ').last();
this.loadDropdown(split.length > 1 ? dropdownName : '');
} else if (lastToken) { } else if (lastToken) {
// Token has been initialized into an object because it has a value // Token has been initialized into an object because it has a value
this.loadDropdown(lastToken.key); this.loadDropdown(lastToken.key);
......
...@@ -13,7 +13,7 @@ describe 'Dropdown assignee', js: true, feature: true do ...@@ -13,7 +13,7 @@ describe 'Dropdown assignee', js: true, feature: true do
def send_keys_to_filtered_search(input) def send_keys_to_filtered_search(input)
input.split("").each do |i| input.split("").each do |i|
filtered_search.send_keys(i) filtered_search.send_keys(i)
sleep 3 sleep 5
wait_for_ajax wait_for_ajax
end end
end end
...@@ -65,7 +65,7 @@ describe 'Dropdown assignee', js: true, feature: true do ...@@ -65,7 +65,7 @@ describe 'Dropdown assignee', js: true, feature: true do
describe 'filtering' do describe 'filtering' do
before do before do
filtered_search.set('assignee:') send_keys_to_filtered_search('assignee:')
end end
it 'filters by name' do it 'filters by name' do
...@@ -118,7 +118,7 @@ describe 'Dropdown assignee', js: true, feature: true do ...@@ -118,7 +118,7 @@ describe 'Dropdown assignee', js: true, feature: true do
end end
it 'selects `no assignee`' do it 'selects `no assignee`' do
click_assignee('No Assignee') find('#js-dropdown-assignee .filter-dropdown-item', text: 'No Assignee').click
expect(page).to have_css(js_dropdown_assignee, visible: false) expect(page).to have_css(js_dropdown_assignee, visible: false)
expect(filtered_search.value).to eq("assignee:none") expect(filtered_search.value).to eq("assignee:none")
end end
......
...@@ -13,7 +13,7 @@ describe 'Dropdown author', js: true, feature: true do ...@@ -13,7 +13,7 @@ describe 'Dropdown author', js: true, feature: true do
def send_keys_to_filtered_search(input) def send_keys_to_filtered_search(input)
input.split("").each do |i| input.split("").each do |i|
filtered_search.send_keys(i) filtered_search.send_keys(i)
sleep 3 sleep 5
wait_for_ajax wait_for_ajax
end end
end end
...@@ -65,7 +65,8 @@ describe 'Dropdown author', js: true, feature: true do ...@@ -65,7 +65,8 @@ describe 'Dropdown author', js: true, feature: true do
describe 'filtering' do describe 'filtering' do
before do before do
filtered_search.set('author:') filtered_search.set('author')
send_keys_to_filtered_search(':')
end end
it 'filters by name' do it 'filters by name' do
...@@ -101,7 +102,8 @@ describe 'Dropdown author', js: true, feature: true do ...@@ -101,7 +102,8 @@ describe 'Dropdown author', js: true, feature: true do
describe 'selecting from dropdown' do describe 'selecting from dropdown' do
before do before do
filtered_search.set('author:') filtered_search.set('author')
send_keys_to_filtered_search(':')
end end
it 'fills in the author username when the author has not been filtered' do it 'fills in the author username when the author has not been filtered' do
......
...@@ -176,7 +176,7 @@ describe 'Dropdown label', js: true, feature: true do ...@@ -176,7 +176,7 @@ describe 'Dropdown label', js: true, feature: true do
end end
it 'selects `no label`' do it 'selects `no label`' do
click_label('No Label') find('#js-dropdown-label .filter-dropdown-item', text: 'No Label').click
expect(page).to have_css(js_dropdown_label, visible: false) expect(page).to have_css(js_dropdown_label, visible: false)
expect(filtered_search.value).to eq("label:none") expect(filtered_search.value).to eq("label:none")
end end
......
...@@ -17,9 +17,9 @@ describe 'Filter issues', js: true, feature: true do ...@@ -17,9 +17,9 @@ describe 'Filter issues', js: true, feature: true do
let!(:multiple_words_label) { create(:label, project: project, title: "Two words") } let!(:multiple_words_label) { create(:label, project: project, title: "Two words") }
let!(:closed_issue) { create(:issue, title: 'bug that is closed', project: project, state: :closed) } let!(:closed_issue) { create(:issue, title: 'bug that is closed', project: project, state: :closed) }
let(:filtered_search) { find('.filtered-search') }
def input_filtered_search(search_term) def input_filtered_search(search_term)
filtered_search = find('.filtered-search')
filtered_search.set(search_term) filtered_search.set(search_term)
filtered_search.send_keys(:enter) filtered_search.send_keys(:enter)
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