kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
288 lines
7.6 KiB
288 lines
7.6 KiB
11 years ago
|
//-- copyright
|
||
|
// OpenProject is a project management system.
|
||
8 years ago
|
// Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
|
||
11 years ago
|
//
|
||
|
// This program is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU General Public License version 3.
|
||
|
//
|
||
|
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
8 years ago
|
// Copyright (C) 2006-2017 Jean-Philippe Lang
|
||
11 years ago
|
// Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
//
|
||
|
// This program is free software; you can redistribute it and/or
|
||
|
// modify it under the terms of the GNU General Public License
|
||
|
// as published by the Free Software Foundation; either version 2
|
||
|
// of the License, or (at your option) any later version.
|
||
|
//
|
||
|
// This program is distributed in the hope that it will be useful,
|
||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
// GNU General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU General Public License
|
||
|
// along with this program; if not, write to the Free Software
|
||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
//
|
||
|
// See doc/COPYRIGHT.rdoc for more details.
|
||
|
//++
|
||
|
|
||
|
/*jshint expr: true*/
|
||
|
|
||
|
describe('UrlParamsHelper', function() {
|
||
8 years ago
|
let UrlParamsHelper:any, PathHelper:any;
|
||
11 years ago
|
|
||
9 years ago
|
beforeEach(angular.mock.module('openproject.helpers', 'openproject.models'));
|
||
8 years ago
|
beforeEach(inject(function(_UrlParamsHelper_:any, _PathHelper_:any) {
|
||
11 years ago
|
UrlParamsHelper = _UrlParamsHelper_;
|
||
10 years ago
|
PathHelper = _PathHelper_;
|
||
11 years ago
|
}));
|
||
|
|
||
|
describe('buildQueryString', function() {
|
||
8 years ago
|
const params = {
|
||
11 years ago
|
ids: [1, 2, 3],
|
||
|
str: '@#$%'
|
||
|
};
|
||
8 years ago
|
let queryString:string;
|
||
11 years ago
|
|
||
|
beforeEach(function() {
|
||
|
queryString = UrlParamsHelper.buildQueryString(params);
|
||
|
});
|
||
|
|
||
|
it('concatenates propertys with \'&\'', function() {
|
||
|
expect(queryString.split('&')).to.have.length(4);
|
||
|
});
|
||
|
|
||
|
it('escapes special characters', function() {
|
||
|
expect(queryString).not.to.include('@');
|
||
|
});
|
||
|
});
|
||
10 years ago
|
|
||
10 years ago
|
describe('encodeQueryJsonParams', function(){
|
||
8 years ago
|
let query:any;
|
||
|
let additional:any;
|
||
10 years ago
|
|
||
|
beforeEach(function() {
|
||
8 years ago
|
let filter1 = {
|
||
8 years ago
|
id: 'soße',
|
||
10 years ago
|
name: 'soße_id',
|
||
10 years ago
|
type: 'list_model',
|
||
8 years ago
|
operator: {
|
||
8 years ago
|
id: '='
|
||
8 years ago
|
},
|
||
|
filter: {
|
||
|
$href: '/api/filter/soße'
|
||
|
},
|
||
10 years ago
|
values: ['knoblauch']
|
||
|
};
|
||
8 years ago
|
let filter2 = {
|
||
8 years ago
|
id: 'created_at',
|
||
8 years ago
|
type: 'datetime_past',
|
||
8 years ago
|
operator: {
|
||
8 years ago
|
id: '<t-'
|
||
8 years ago
|
},
|
||
|
filter: {
|
||
|
$href: '/api/filter/created_at'
|
||
|
},
|
||
|
values: ['5']
|
||
10 years ago
|
};
|
||
8 years ago
|
query = {
|
||
10 years ago
|
id: 1,
|
||
10 years ago
|
name: 'knoblauch soße',
|
||
8 years ago
|
sums: true,
|
||
8 years ago
|
timelineVisible: true,
|
||
8 years ago
|
timelineZoomLevel: 'days',
|
||
8 years ago
|
showHierarchies: true,
|
||
8 years ago
|
columns: [{ id: 'type' }, { id: 'status' }, { id: 'soße' }],
|
||
|
groupBy: {
|
||
|
id: 'status'
|
||
|
},
|
||
|
sortBy: [{
|
||
|
id: 'type-desc'
|
||
|
}],
|
||
10 years ago
|
filters: [filter1, filter2]
|
||
8 years ago
|
};
|
||
|
|
||
|
additional = {
|
||
|
page: 10,
|
||
|
perPage: 100
|
||
|
}
|
||
10 years ago
|
});
|
||
|
|
||
|
it('should encode query to params JSON', function() {
|
||
8 years ago
|
let encodedJSON = UrlParamsHelper.encodeQueryJsonParams(query, additional);
|
||
|
let expectedJSON = "{\"c\":[\"type\",\"status\",\"soße\"],\"s\":true,\"tv\":true,\"tzl\":\"days\",\"hi\":true,\"g\":\"status\",\"t\":\"type:desc\",\"f\":[{\"n\":\"soße\",\"o\":\"%3D\",\"v\":[\"knoblauch\"]},{\"n\":\"created_at\",\"o\":\"%3Ct-\",\"v\":[\"5\"]}],\"pa\":10,\"pp\":100}";
|
||
10 years ago
|
expect(encodedJSON).to.eq(expectedJSON);
|
||
10 years ago
|
});
|
||
10 years ago
|
});
|
||
|
|
||
8 years ago
|
describe('buildV3GetQueryFromJsonParams', function() {
|
||
8 years ago
|
let params:string;
|
||
10 years ago
|
|
||
|
beforeEach(function() {
|
||
8 years ago
|
params = "{\"c\":[\"type\",\"status\",\"soße\"],\"s\":true,\"tv\":true,\"tzl\":\"days\",\"hi\":true,\"g\":\"status\",\"t\":\"type:desc,status:asc\",\"f\":[{\"n\":\"soße\",\"o\":\"%3D\",\"v\":[\"knoblauch\"]},{\"n\":\"created_at\",\"o\":\"%3Ct-\",\"v\":[\"5\"]}],\"pa\":10,\"pp\":100}";
|
||
10 years ago
|
});
|
||
|
|
||
|
it('should decode query params to object', function() {
|
||
8 years ago
|
let decodedQueryParams = UrlParamsHelper.buildV3GetQueryFromJsonParams(params);
|
||
10 years ago
|
|
||
8 years ago
|
let expected = {
|
||
8 years ago
|
showSums: true,
|
||
8 years ago
|
timelineVisible: true,
|
||
8 years ago
|
showHierarchies: true,
|
||
8 years ago
|
timelineZoomLevel: 'days',
|
||
10 years ago
|
groupBy: 'status',
|
||
8 years ago
|
filters: JSON.stringify([
|
||
|
{
|
||
|
soße: {
|
||
|
operator: '=',
|
||
|
values: ['knoblauch']
|
||
|
}
|
||
|
},
|
||
|
{
|
||
|
created_at: {
|
||
|
operator: '<t-',
|
||
|
values: ['5']
|
||
|
}
|
||
|
}
|
||
|
]),
|
||
|
sortBy: JSON.stringify([['type', 'desc'], ['status', 'asc']]),
|
||
|
offset: 10,
|
||
|
pageSize: 100
|
||
10 years ago
|
};
|
||
10 years ago
|
|
||
|
expect(angular.equals(decodedQueryParams, expected)).to.be.true;
|
||
|
});
|
||
10 years ago
|
});
|
||
10 years ago
|
|
||
8 years ago
|
describe('buildV3GetQueryFromQueryResource', function() {
|
||
8 years ago
|
let query:any;
|
||
|
let additional:any;
|
||
10 years ago
|
|
||
8 years ago
|
it('decodes query params to object', function() {
|
||
8 years ago
|
let filter1 = {
|
||
8 years ago
|
id: 'soße',
|
||
|
name: 'soße_id',
|
||
|
type: 'list_model',
|
||
|
operator: {
|
||
8 years ago
|
id: '='
|
||
8 years ago
|
},
|
||
|
filter: {
|
||
|
$href: '/api/filter/soße'
|
||
|
},
|
||
|
values: ['knoblauch']
|
||
|
};
|
||
8 years ago
|
let filter2 = {
|
||
8 years ago
|
id: 'created_at',
|
||
|
type: 'datetime_past',
|
||
|
operator: {
|
||
8 years ago
|
id: '<t-'
|
||
8 years ago
|
},
|
||
|
filter: {
|
||
|
$href: '/api/filter/created_at'
|
||
|
},
|
||
|
values: ['5']
|
||
|
};
|
||
|
query = {
|
||
|
id: 1,
|
||
|
name: 'knoblauch soße',
|
||
|
sums: true,
|
||
|
columns: [{ id: 'type' }, { id: 'status' }, { id: 'soße' }],
|
||
|
groupBy: {
|
||
|
id: 'status'
|
||
|
},
|
||
|
sortBy: [
|
||
|
{
|
||
|
id: 'type-desc'
|
||
|
},
|
||
|
{
|
||
|
id: 'status-asc'
|
||
|
}
|
||
|
],
|
||
|
filters: [filter1, filter2]
|
||
|
};
|
||
10 years ago
|
|
||
8 years ago
|
additional = {
|
||
|
offset: 10,
|
||
|
pageSize: 100
|
||
8 years ago
|
};
|
||
10 years ago
|
|
||
8 years ago
|
let v3Params = UrlParamsHelper.buildV3GetQueryFromQueryResource(query, additional);
|
||
10 years ago
|
|
||
8 years ago
|
let expected = {
|
||
8 years ago
|
'columns[]': ['type', 'status', 'soße'],
|
||
|
showSums: true,
|
||
|
groupBy: 'status',
|
||
|
filters: JSON.stringify([
|
||
|
{
|
||
|
soße: {
|
||
|
operator: '=',
|
||
|
values: ['knoblauch']
|
||
|
}
|
||
|
},
|
||
|
{
|
||
|
created_at: {
|
||
|
operator: '<t-',
|
||
|
values: ['5']
|
||
|
}
|
||
|
}
|
||
|
]),
|
||
|
sortBy: JSON.stringify([['type', 'desc'], ['status', 'asc']]),
|
||
|
offset: 10,
|
||
|
pageSize: 100
|
||
|
};
|
||
10 years ago
|
|
||
8 years ago
|
expect(angular.equals(v3Params, expected)).to.be.true;
|
||
10 years ago
|
});
|
||
|
|
||
8 years ago
|
it('decodes string object filters', function() {
|
||
8 years ago
|
let filter1 = {
|
||
8 years ago
|
id: 'customField1',
|
||
|
operator: {
|
||
8 years ago
|
id: '='
|
||
8 years ago
|
},
|
||
|
filter: {
|
||
|
$href: '/api/filter/customField1'
|
||
|
},
|
||
|
values: [
|
||
|
{
|
||
|
_type: "StringObject",
|
||
|
value: "val2val",
|
||
|
$href: "/api/v3/string_objects/?value=val2val"
|
||
|
},
|
||
|
{
|
||
|
_type: "StringObject",
|
||
|
value: "7val7",
|
||
|
$href: "/api/v3/string_objects/?value=7val7"
|
||
|
}
|
||
|
]
|
||
|
};
|
||
|
query = {
|
||
|
filters: [filter1],
|
||
|
sortBy: [],
|
||
|
columns: [],
|
||
|
sums: false
|
||
|
};
|
||
|
|
||
|
additional = {}
|
||
10 years ago
|
|
||
8 years ago
|
let v3Params = UrlParamsHelper.buildV3GetQueryFromQueryResource(query, additional);
|
||
10 years ago
|
|
||
8 years ago
|
let expected = {
|
||
8 years ago
|
'columns[]': [],
|
||
|
filters: JSON.stringify([
|
||
|
{
|
||
|
customField1: {
|
||
|
operator: '=',
|
||
|
values: ['val2val', '7val7']
|
||
|
}
|
||
|
}
|
||
|
]),
|
||
|
showSums: false,
|
||
|
sortBy: '[]'
|
||
|
};
|
||
10 years ago
|
|
||
8 years ago
|
expect(angular.equals(v3Params, expected)).to.be.true;
|
||
10 years ago
|
});
|
||
|
});
|
||
11 years ago
|
});
|