2016-12-15 10:07:41 -05:00
|
|
|
/* global Issuable */
|
|
|
|
|
2017-02-03 14:17:03 -05:00
|
|
|
require('~/lib/utils/url_utility');
|
2017-01-09 18:23:54 -05:00
|
|
|
require('~/issuable');
|
2016-12-15 10:07:41 -05:00
|
|
|
|
|
|
|
(() => {
|
|
|
|
const BASE_URL = '/user/project/issues?scope=all&state=closed';
|
|
|
|
const DEFAULT_PARAMS = '&utf8=%E2%9C%93';
|
|
|
|
|
|
|
|
function updateForm(formValues, form) {
|
|
|
|
$.each(formValues, (id, value) => {
|
|
|
|
$(`#${id}`, form).val(value);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetForm(form) {
|
|
|
|
$('input[name!="utf8"]', form).each((index, input) => {
|
|
|
|
input.setAttribute('value', '');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Issuable', () => {
|
2016-12-30 19:14:33 -05:00
|
|
|
preloadFixtures('static/issuable_filter.html.raw');
|
2016-12-15 10:07:41 -05:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2016-12-30 19:14:33 -05:00
|
|
|
loadFixtures('static/issuable_filter.html.raw');
|
2016-12-15 10:07:41 -05:00
|
|
|
Issuable.init();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be defined', () => {
|
|
|
|
expect(window.Issuable).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('filtering', () => {
|
|
|
|
let $filtersForm;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
$filtersForm = $('.js-filter-form');
|
2016-12-30 19:14:33 -05:00
|
|
|
loadFixtures('static/issuable_filter.html.raw');
|
2016-12-15 10:07:41 -05:00
|
|
|
resetForm($filtersForm);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should contain only the default parameters', () => {
|
2017-01-13 16:54:16 -05:00
|
|
|
spyOn(gl.utils, 'visitUrl');
|
2016-12-15 10:07:41 -05:00
|
|
|
|
|
|
|
Issuable.filterResults($filtersForm);
|
|
|
|
|
2017-01-13 16:54:16 -05:00
|
|
|
expect(gl.utils.visitUrl).toHaveBeenCalledWith(BASE_URL + DEFAULT_PARAMS);
|
2016-12-15 10:07:41 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should filter for the phrase "broken"', () => {
|
2017-01-13 16:54:16 -05:00
|
|
|
spyOn(gl.utils, 'visitUrl');
|
2016-12-15 10:07:41 -05:00
|
|
|
|
|
|
|
updateForm({ search: 'broken' }, $filtersForm);
|
|
|
|
Issuable.filterResults($filtersForm);
|
|
|
|
const params = `${DEFAULT_PARAMS}&search=broken`;
|
|
|
|
|
2017-01-13 16:54:16 -05:00
|
|
|
expect(gl.utils.visitUrl).toHaveBeenCalledWith(BASE_URL + params);
|
2016-12-15 10:07:41 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should keep query parameters after modifying filter', () => {
|
2017-01-13 16:54:16 -05:00
|
|
|
spyOn(gl.utils, 'visitUrl');
|
2016-12-15 10:07:41 -05:00
|
|
|
|
|
|
|
// initial filter
|
|
|
|
updateForm({ milestone_title: 'v1.0' }, $filtersForm);
|
|
|
|
|
|
|
|
Issuable.filterResults($filtersForm);
|
|
|
|
let params = `${DEFAULT_PARAMS}&milestone_title=v1.0`;
|
2017-01-13 16:54:16 -05:00
|
|
|
expect(gl.utils.visitUrl).toHaveBeenCalledWith(BASE_URL + params);
|
2016-12-15 10:07:41 -05:00
|
|
|
|
|
|
|
// update filter
|
|
|
|
updateForm({ label_name: 'Frontend' }, $filtersForm);
|
|
|
|
|
|
|
|
Issuable.filterResults($filtersForm);
|
|
|
|
params = `${DEFAULT_PARAMS}&milestone_title=v1.0&label_name=Frontend`;
|
2017-01-13 16:54:16 -05:00
|
|
|
expect(gl.utils.visitUrl).toHaveBeenCalledWith(BASE_URL + params);
|
2016-12-15 10:07:41 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})();
|