Filter groups and projects dropdowns of search page on backend

This commit is contained in:
Winnie Hellmann 2018-01-17 23:32:42 +00:00 committed by Clement Ho
parent 5392568e1e
commit be8c4af83a
4 changed files with 65 additions and 0 deletions

View file

@ -15,6 +15,7 @@ export default class Search {
$groupDropdown.glDropdown({
selectable: true,
filterable: true,
filterRemote: true,
fieldName: 'group_id',
search: {
fields: ['full_name'],
@ -43,6 +44,7 @@ export default class Search {
$projectDropdown.glDropdown({
selectable: true,
filterable: true,
filterRemote: true,
fieldName: 'project_id',
search: {
fields: ['name'],

View file

@ -0,0 +1,5 @@
---
title: Filter groups and projects dropdowns of search page on backend
merge_request: 16336
author:
type: fixed

View file

@ -0,0 +1,18 @@
require 'spec_helper'
describe SearchController, '(JavaScript fixtures)', type: :controller do
include JavaScriptFixturesHelpers
render_views
before(:all) do
clean_frontend_fixtures('search/')
end
it 'search/show.html.raw' do |example|
get :show
expect(response).to be_success
store_frontend_fixture(response, example.description)
end
end

View file

@ -0,0 +1,40 @@
import Api from '~/api';
import Search from '~/pages/search/show/search';
describe('Search', () => {
const fixturePath = 'search/show.html.raw';
const searchTerm = 'some search';
const fillDropdownInput = (dropdownSelector) => {
const dropdownElement = document.querySelector(dropdownSelector).parentNode;
const inputElement = dropdownElement.querySelector('.dropdown-input-field');
inputElement.value = searchTerm;
return inputElement;
};
preloadFixtures(fixturePath);
beforeEach(() => {
loadFixtures(fixturePath);
new Search(); // eslint-disable-line no-new
});
it('requests groups from backend when filtering', (done) => {
spyOn(Api, 'groups').and.callFake((term) => {
expect(term).toBe(searchTerm);
done();
});
const inputElement = fillDropdownInput('.js-search-group-dropdown');
$(inputElement).trigger('input');
});
it('requests projects from backend when filtering', (done) => {
spyOn(Api, 'projects').and.callFake((term) => {
expect(term).toBe(searchTerm);
done();
});
const inputElement = fillDropdownInput('.js-search-project-dropdown');
$(inputElement).trigger('input');
});
});