debian-mirror-gitlab/spec/javascripts/issuable_spec.js

81 lines
2.3 KiB
JavaScript
Raw Normal View History

2017-09-10 17:25:29 +05:30
/* global IssuableIndex */
2017-08-17 22:00:37 +05:30
2017-09-10 17:25:29 +05:30
import '~/lib/utils/url_utility';
import '~/issuable_index';
2017-08-17 22:00:37 +05:30
(() => {
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', () => {
preloadFixtures('static/issuable_filter.html.raw');
beforeEach(() => {
loadFixtures('static/issuable_filter.html.raw');
2017-09-10 17:25:29 +05:30
IssuableIndex.init();
2017-08-17 22:00:37 +05:30
});
it('should be defined', () => {
2017-09-10 17:25:29 +05:30
expect(window.IssuableIndex).toBeDefined();
2017-08-17 22:00:37 +05:30
});
describe('filtering', () => {
let $filtersForm;
beforeEach(() => {
$filtersForm = $('.js-filter-form');
loadFixtures('static/issuable_filter.html.raw');
resetForm($filtersForm);
});
it('should contain only the default parameters', () => {
spyOn(gl.utils, 'visitUrl');
2017-09-10 17:25:29 +05:30
IssuableIndex.filterResults($filtersForm);
2017-08-17 22:00:37 +05:30
expect(gl.utils.visitUrl).toHaveBeenCalledWith(BASE_URL + DEFAULT_PARAMS);
});
it('should filter for the phrase "broken"', () => {
spyOn(gl.utils, 'visitUrl');
updateForm({ search: 'broken' }, $filtersForm);
2017-09-10 17:25:29 +05:30
IssuableIndex.filterResults($filtersForm);
2017-08-17 22:00:37 +05:30
const params = `${DEFAULT_PARAMS}&search=broken`;
expect(gl.utils.visitUrl).toHaveBeenCalledWith(BASE_URL + params);
});
it('should keep query parameters after modifying filter', () => {
spyOn(gl.utils, 'visitUrl');
// initial filter
updateForm({ milestone_title: 'v1.0' }, $filtersForm);
2017-09-10 17:25:29 +05:30
IssuableIndex.filterResults($filtersForm);
2017-08-17 22:00:37 +05:30
let params = `${DEFAULT_PARAMS}&milestone_title=v1.0`;
expect(gl.utils.visitUrl).toHaveBeenCalledWith(BASE_URL + params);
// update filter
updateForm({ label_name: 'Frontend' }, $filtersForm);
2017-09-10 17:25:29 +05:30
IssuableIndex.filterResults($filtersForm);
2017-08-17 22:00:37 +05:30
params = `${DEFAULT_PARAMS}&milestone_title=v1.0&label_name=Frontend`;
expect(gl.utils.visitUrl).toHaveBeenCalledWith(BASE_URL + params);
});
});
});
})();