Commit 3e95bd97 authored by Phil Hughes's avatar Phil Hughes

Fixed eslint errors

Updated modal filter spec
parent 09f7b9dc
/* global Vue */ /* global Vue */
import FilteredSearchBoards from '../../filtered_search_boards'; import FilteredSearchBoards from '../../filtered_search_boards';
import { FilteredSearchContainer } from '../../../filtered_search/container'; import FilteredSearchContainer from '../../../filtered_search/container';
export default { export default {
name: 'modal-filters', name: 'modal-filters',
props: {
store: {
type: Object,
required: true,
},
},
mounted() { mounted() {
FilteredSearchContainer.container = this.$el; FilteredSearchContainer.container = this.$el;
this.filteredSearch = new FilteredSearchBoards({path: ''}, false); this.filteredSearch = new FilteredSearchBoards(this.store, false);
}, },
destroyed() { destroyed() {
FilteredSearchContainer.container = document; FilteredSearchContainer.container = document;
gl.issueBoards.ModalStore.setDefaultFilter(); this.store.path = '';
}, },
template: '#js-board-modal-filter', template: '#js-board-modal-filter',
}; };
/* global Vue */ /* global Vue */
require('./tabs');
import modalFilters from './filters'; import modalFilters from './filters';
require('./tabs');
(() => { (() => {
const ModalStore = gl.issueBoards.ModalStore; const ModalStore = gl.issueBoards.ModalStore;
...@@ -66,7 +67,7 @@ import modalFilters from './filters'; ...@@ -66,7 +67,7 @@ import modalFilters from './filters';
<div <div
class="add-issues-search append-bottom-10" class="add-issues-search append-bottom-10"
v-if="showSearch"> v-if="showSearch">
<modal-filters /> <modal-filters :store="filter" />
<button <button
type="button" type="button"
class="btn btn-success btn-inverted prepend-left-10" class="btn btn-success btn-inverted prepend-left-10"
......
...@@ -47,9 +47,6 @@ require('./empty_state'); ...@@ -47,9 +47,6 @@ require('./empty_state');
page() { page() {
this.loadIssues(); this.loadIssues();
}, },
searchTerm() {
this.searchOperation();
},
showAddIssuesModal() { showAddIssuesModal() {
if (this.showAddIssuesModal && !this.issues.length) { if (this.showAddIssuesModal && !this.issues.length) {
this.loading = true; this.loading = true;
...@@ -72,17 +69,30 @@ require('./empty_state'); ...@@ -72,17 +69,30 @@ require('./empty_state');
}, },
}, },
methods: { methods: {
searchOperation: _.debounce(function searchOperationDebounce() {
this.loadIssues(true);
}, 500),
loadIssues(clearIssues = false) { loadIssues(clearIssues = false) {
if (!this.showAddIssuesModal) return false; if (!this.showAddIssuesModal) return false;
const queryData = Object.assign({}, this.filter, { const queryData = this.filter.path.split('&').reduce((dataParam, filterParam) => {
search: this.searchTerm, if (filterParam === '') return dataParam;
page: this.page,
per: this.perPage, const data = dataParam;
}); const paramSplit = filterParam.split('=');
const paramKeyNormalized = paramSplit[0].replace('[]', '');
const isArray = paramSplit[0].indexOf('[]');
const value = decodeURIComponent(paramSplit[1]).replace(/\+/g, ' ');
if (isArray !== -1) {
if (!data[paramKeyNormalized]) {
data[paramKeyNormalized] = [];
}
data[paramKeyNormalized].push(value);
} else {
data[paramKeyNormalized] = value;
}
return data;
}, { page: this.page, per: this.perPage });
return gl.boardService.getBacklog(queryData).then((res) => { return gl.boardService.getBacklog(queryData).then((res) => {
const data = res.json(); const data = res.json();
......
...@@ -17,17 +17,9 @@ ...@@ -17,17 +17,9 @@
loadingNewPage: false, loadingNewPage: false,
page: 1, page: 1,
perPage: 50, perPage: 50,
}; filter: {
path: '',
this.setDefaultFilter(); },
}
setDefaultFilter() {
this.store.filter = {
author_id: '',
assignee_id: '',
milestone_title: '',
label_name: [],
}; };
} }
......
let _container = document; /* eslint-disable class-methods-use-this */
let container = document;
class FilteredSearchContainerClass { class FilteredSearchContainerClass {
set container(container) { set container(containerParam) {
_container = container; container = containerParam;
} }
get container() { get container() {
return _container; return container;
} }
} }
export let FilteredSearchContainer = new FilteredSearchContainerClass(); export default new FilteredSearchContainerClass();
...@@ -56,8 +56,6 @@ require('./filtered_search_dropdown'); ...@@ -56,8 +56,6 @@ require('./filtered_search_dropdown');
} }
init() { init() {
console.log(this.input);
console.log(this.dropdown);
this.droplab.addHook(this.input, this.dropdown, [droplabAjaxFilter], this.config).init(); this.droplab.addHook(this.input, this.dropdown, [droplabAjaxFilter], this.config).init();
} }
} }
......
import { FilteredSearchContainer } from './container'; import FilteredSearchContainer from './container';
(() => { (() => {
class DropdownUtils { class DropdownUtils {
......
/* global DropLab */ /* global DropLab */
import { FilteredSearchContainer } from './container'; import FilteredSearchContainer from './container';
(() => { (() => {
class FilteredSearchDropdownManager { class FilteredSearchDropdownManager {
......
import { FilteredSearchContainer } from './container'; import FilteredSearchContainer from './container';
(() => { (() => {
class FilteredSearchManager { class FilteredSearchManager {
......
import { FilteredSearchContainer } from './container'; import FilteredSearchContainer from './container';
class FilteredSearchVisualTokens { class FilteredSearchVisualTokens {
static getLastVisualTokenBeforeInput() { static getLastVisualTokenBeforeInput() {
......
require 'rails_helper' require 'rails_helper'
describe 'Issue Boards add issue modal filtering', :feature, :js do describe 'Issue Boards add issue modal filtering', :feature, :js do
include WaitForAjax
include WaitForVueResource include WaitForVueResource
let(:project) { create(:empty_project, :public) } let(:project) { create(:empty_project, :public) }
...@@ -23,6 +22,7 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do ...@@ -23,6 +22,7 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do
page.within('.add-issues-modal') do page.within('.add-issues-modal') do
find('.form-control').native.send_keys('testing empty state') find('.form-control').native.send_keys('testing empty state')
find('.form-control').native.send_keys(:enter)
wait_for_vue_resource wait_for_vue_resource
...@@ -33,13 +33,11 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do ...@@ -33,13 +33,11 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do
it 'restores filters when closing' do it 'restores filters when closing' do
visit_board visit_board
page.within('.add-issues-modal') do set_filter('milestone')
click_button 'Milestone' click_filter_link('Upcoming')
submit_filter
wait_for_ajax
click_link 'Upcoming'
page.within('.add-issues-modal') do
wait_for_vue_resource wait_for_vue_resource
expect(page).to have_selector('.card', count: 0) expect(page).to have_selector('.card', count: 0)
...@@ -56,37 +54,41 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do ...@@ -56,37 +54,41 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do
end end
end end
context 'author' do it 'resotres filters after clicking clear button' do
let!(:issue) { create(:issue, project: project, author: user2) }
before do
project.team << [user2, :developer]
visit_board visit_board
end
it 'filters by any author' do set_filter('milestone')
click_filter_link('Upcoming')
submit_filter
page.within('.add-issues-modal') do page.within('.add-issues-modal') do
click_button 'Author' wait_for_vue_resource
wait_for_ajax expect(page).to have_selector('.card', count: 0)
click_link 'Any Author' find('.clear-search').click
wait_for_vue_resource wait_for_vue_resource
expect(page).to have_selector('.card', count: 2) expect(page).to have_selector('.card', count: 1)
end end
end end
it 'filters by selected user' do context 'author' do
page.within('.add-issues-modal') do let!(:issue) { create(:issue, project: project, author: user2) }
click_button 'Author'
wait_for_ajax before do
project.team << [user2, :developer]
click_link user2.name visit_board
end
it 'filters by selected user' do
set_filter('author')
click_filter_link(user2.name)
submit_filter
page.within('.add-issues-modal') do
wait_for_vue_resource wait_for_vue_resource
expect(page).to have_selector('.card', count: 1) expect(page).to have_selector('.card', count: 1)
...@@ -103,28 +105,12 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do ...@@ -103,28 +105,12 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do
visit_board visit_board
end end
it 'filters by any assignee' do
page.within('.add-issues-modal') do
click_button 'Assignee'
wait_for_ajax
click_link 'Any Assignee'
wait_for_vue_resource
expect(page).to have_selector('.card', count: 2)
end
end
it 'filters by unassigned' do it 'filters by unassigned' do
page.within('.add-issues-modal') do set_filter('assignee')
click_button 'Assignee' click_filter_link('No Assignee')
submit_filter
wait_for_ajax
click_link 'Unassigned'
page.within('.add-issues-modal') do
wait_for_vue_resource wait_for_vue_resource
expect(page).to have_selector('.card', count: 1) expect(page).to have_selector('.card', count: 1)
...@@ -132,15 +118,11 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do ...@@ -132,15 +118,11 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do
end end
it 'filters by selected user' do it 'filters by selected user' do
page.within('.add-issues-modal') do set_filter('assignee')
click_button 'Assignee' click_filter_link(user2.name)
submit_filter
wait_for_ajax
page.within '.dropdown-menu-user' do
click_link user2.name
end
page.within('.add-issues-modal') do
wait_for_vue_resource wait_for_vue_resource
expect(page).to have_selector('.card', count: 1) expect(page).to have_selector('.card', count: 1)
...@@ -156,28 +138,12 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do ...@@ -156,28 +138,12 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do
visit_board visit_board
end end
it 'filters by any milestone' do
page.within('.add-issues-modal') do
click_button 'Milestone'
wait_for_ajax
click_link 'Any Milestone'
wait_for_vue_resource
expect(page).to have_selector('.card', count: 2)
end
end
it 'filters by upcoming milestone' do it 'filters by upcoming milestone' do
page.within('.add-issues-modal') do set_filter('milestone')
click_button 'Milestone' click_filter_link('Upcoming')
submit_filter
wait_for_ajax
click_link 'Upcoming'
page.within('.add-issues-modal') do
wait_for_vue_resource wait_for_vue_resource
expect(page).to have_selector('.card', count: 0) expect(page).to have_selector('.card', count: 0)
...@@ -185,13 +151,11 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do ...@@ -185,13 +151,11 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do
end end
it 'filters by selected milestone' do it 'filters by selected milestone' do
page.within('.add-issues-modal') do set_filter('milestone')
click_button 'Milestone' click_filter_link(milestone.name)
submit_filter
wait_for_ajax
click_link milestone.name
page.within('.add-issues-modal') do
wait_for_vue_resource wait_for_vue_resource
expect(page).to have_selector('.card', count: 1) expect(page).to have_selector('.card', count: 1)
...@@ -207,28 +171,12 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do ...@@ -207,28 +171,12 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do
visit_board visit_board
end end
it 'filters by any label' do
page.within('.add-issues-modal') do
click_button 'Label'
wait_for_ajax
click_link 'Any Label'
wait_for_vue_resource
expect(page).to have_selector('.card', count: 2)
end
end
it 'filters by no label' do it 'filters by no label' do
page.within('.add-issues-modal') do set_filter('label')
click_button 'Label' click_filter_link('No Label')
submit_filter
wait_for_ajax
click_link 'No Label'
page.within('.add-issues-modal') do
wait_for_vue_resource wait_for_vue_resource
expect(page).to have_selector('.card', count: 1) expect(page).to have_selector('.card', count: 1)
...@@ -236,13 +184,11 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do ...@@ -236,13 +184,11 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do
end end
it 'filters by label' do it 'filters by label' do
page.within('.add-issues-modal') do set_filter('label')
click_button 'Label' click_filter_link('No Label')
submit_filter
wait_for_ajax
click_link label.title
page.within('.add-issues-modal') do
wait_for_vue_resource wait_for_vue_resource
expect(page).to have_selector('.card', count: 1) expect(page).to have_selector('.card', count: 1)
...@@ -256,4 +202,20 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do ...@@ -256,4 +202,20 @@ describe 'Issue Boards add issue modal filtering', :feature, :js do
click_button('Add issues') click_button('Add issues')
end end
def set_filter(type, text = '')
find('.add-issues-modal .filtered-search').native.send_keys("#{type}:#{text}")
end
def submit_filter
find('.add-issues-modal .filtered-search').native.send_keys(:enter)
end
def click_filter_link(link_text)
page.within('.add-issues-modal .filtered-search-input-container') do
expect(page).to have_button(link_text)
click_button(link_text)
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