mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 01:17:37 -02:30
First pass at unit tests for the filters in shared/filters
This commit is contained in:
@@ -1,10 +1,15 @@
|
|||||||
export default function() {
|
export default function() {
|
||||||
return function(string, append) {
|
return function(string, append) {
|
||||||
if (string) {
|
if (string) {
|
||||||
return string + append;
|
if (append) {
|
||||||
|
return string + append;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,11 +10,3 @@
|
|||||||
return input;
|
return input;
|
||||||
};
|
};
|
||||||
}];
|
}];
|
||||||
|
|
||||||
// export default
|
|
||||||
// angular.module('capitalizeFilter', []).filter('capitalize', function() {
|
|
||||||
// return function(input) {
|
|
||||||
// input = input.charAt(0).toUpperCase() + input.substr(1).toLowerCase();
|
|
||||||
// return input;
|
|
||||||
// };
|
|
||||||
// });
|
|
||||||
|
|||||||
@@ -12,5 +12,3 @@ export default
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
export default ['moment', function(moment) {
|
export default ['moment', function(moment) {
|
||||||
return function(input) {
|
return function(input) {
|
||||||
var date;
|
var date;
|
||||||
if(input === null){
|
if(input === null || input === undefined){
|
||||||
return "";
|
return "";
|
||||||
}else {
|
}else {
|
||||||
date = moment(input);
|
date = moment(input);
|
||||||
@@ -15,23 +15,3 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
|
||||||
// function longDateFilter(moment, input) {
|
|
||||||
// var date;
|
|
||||||
// if(input === null){
|
|
||||||
// return "";
|
|
||||||
// }else {
|
|
||||||
// date = moment(input);
|
|
||||||
// return date.format('l LTS');
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// export default
|
|
||||||
// angular.module('longDateFilter', [])
|
|
||||||
// .filter('longDate',
|
|
||||||
// [ 'moment',
|
|
||||||
// function(moment) {
|
|
||||||
// return _.partial(longDateFilter, moment);
|
|
||||||
// }
|
|
||||||
// ]);
|
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
export default function() {
|
export default function() {
|
||||||
return function(string, prepend) {
|
return function(string, prepend) {
|
||||||
if (string) {
|
if (string) {
|
||||||
return prepend + string;
|
if(prepend) {
|
||||||
|
return prepend + string;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,11 +10,3 @@
|
|||||||
return input;
|
return input;
|
||||||
};
|
};
|
||||||
}];
|
}];
|
||||||
|
|
||||||
// export default
|
|
||||||
// angular.module('sanitizeFilter', []).filter('sanitize', function() {
|
|
||||||
// return function(input) {
|
|
||||||
// input = $("<span>").text(input)[0].innerHTML;
|
|
||||||
// return input;
|
|
||||||
// };
|
|
||||||
// });
|
|
||||||
|
|||||||
25
awx/ui/tests/spec/shared/filters/append.filter-test.js
Normal file
25
awx/ui/tests/spec/shared/filters/append.filter-test.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
describe('Filter: append', () => {
|
||||||
|
var filter;
|
||||||
|
|
||||||
|
beforeEach(angular.mock.module('Tower'));
|
||||||
|
|
||||||
|
beforeEach(function(){
|
||||||
|
inject(function($injector){
|
||||||
|
filter = $injector.get('$filter')('append');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should append the two parameters passed', function(){
|
||||||
|
expect(filter("foo", "bar")).toBe("foobar");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return string if no append param passed', function(){
|
||||||
|
expect(filter("foo")).toBe("foo");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return empty string if no params passed', function(){
|
||||||
|
expect(filter()).toBe("");
|
||||||
|
});
|
||||||
|
});
|
||||||
20
awx/ui/tests/spec/shared/filters/capitalize.filter-test.js
Normal file
20
awx/ui/tests/spec/shared/filters/capitalize.filter-test.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
describe('Filter: capitalize', () => {
|
||||||
|
var filter;
|
||||||
|
|
||||||
|
beforeEach(angular.mock.module('Tower'));
|
||||||
|
|
||||||
|
beforeEach(function(){
|
||||||
|
inject(function($injector){
|
||||||
|
filter = $injector.get('$filter')('capitalize');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should capitalize the first letter', function(){
|
||||||
|
expect(filter("foo")).toBe("Foo");
|
||||||
|
expect(filter("Foo")).toBe("Foo");
|
||||||
|
expect(filter("FOO")).toBe("Foo");
|
||||||
|
expect(filter("FoO")).toBe("Foo");
|
||||||
|
});
|
||||||
|
});
|
||||||
18
awx/ui/tests/spec/shared/filters/format-epoch.filter-test.js
Normal file
18
awx/ui/tests/spec/shared/filters/format-epoch.filter-test.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
describe('Filter: formatEpoch', () => {
|
||||||
|
var filter;
|
||||||
|
|
||||||
|
beforeEach(angular.mock.module('Tower'));
|
||||||
|
|
||||||
|
beforeEach(function(){
|
||||||
|
inject(function($injector){
|
||||||
|
filter = $injector.get('$filter')('formatEpoch');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should convert epoch to datetime string', function(){
|
||||||
|
expect(filter(11111)).toBe("Dec 31, 1969 10:05 PM");
|
||||||
|
expect(filter(610430400)).toBe("May 6, 1989 12:00 AM");
|
||||||
|
});
|
||||||
|
});
|
||||||
18
awx/ui/tests/spec/shared/filters/is-empty.filter-test.js
Normal file
18
awx/ui/tests/spec/shared/filters/is-empty.filter-test.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
describe('Filter: isEmpty', () => {
|
||||||
|
var filter;
|
||||||
|
|
||||||
|
beforeEach(angular.mock.module('Tower'));
|
||||||
|
|
||||||
|
beforeEach(function(){
|
||||||
|
inject(function($injector){
|
||||||
|
filter = $injector.get('$filter')('isEmpty');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('check if an object is empty', function(){
|
||||||
|
expect(filter({})).toBe(true);
|
||||||
|
expect(filter({foo: 'bar'})).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
20
awx/ui/tests/spec/shared/filters/long-date.filter-test.js
Normal file
20
awx/ui/tests/spec/shared/filters/long-date.filter-test.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
describe('Filter: longDate', () => {
|
||||||
|
var filter;
|
||||||
|
|
||||||
|
beforeEach(angular.mock.module('Tower'));
|
||||||
|
|
||||||
|
beforeEach(function(){
|
||||||
|
inject(function($injector){
|
||||||
|
filter = $injector.get('$filter')('longDate');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should convert the timestamp to a UI friendly date and time', function(){
|
||||||
|
expect(filter("2017-02-13T22:00:14.106Z")).toBe("2/13/2017 5:00:14 PM");
|
||||||
|
});
|
||||||
|
it('should return an empty string if no timestamp is passed', function(){
|
||||||
|
expect(filter()).toBe("");
|
||||||
|
});
|
||||||
|
});
|
||||||
25
awx/ui/tests/spec/shared/filters/prepend.filter-test.js
Normal file
25
awx/ui/tests/spec/shared/filters/prepend.filter-test.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
describe('Filter: prepend', () => {
|
||||||
|
var filter;
|
||||||
|
|
||||||
|
beforeEach(angular.mock.module('Tower'));
|
||||||
|
|
||||||
|
beforeEach(function(){
|
||||||
|
inject(function($injector){
|
||||||
|
filter = $injector.get('$filter')('prepend');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should prepend the second param to the first', function(){
|
||||||
|
expect(filter("foo", "bar")).toBe("barfoo");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return string if no prepend param passed', function(){
|
||||||
|
expect(filter("foo")).toBe("foo");
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return empty string if no params passed', function(){
|
||||||
|
expect(filter()).toBe("");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
describe('Filter: sanitize', () => {
|
||||||
|
var filter;
|
||||||
|
|
||||||
|
beforeEach(angular.mock.module('Tower'));
|
||||||
|
|
||||||
|
beforeEach(function(){
|
||||||
|
inject(function($injector){
|
||||||
|
filter = $injector.get('$filter')('sanitize');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should sanitize xss-vulnerable strings', function(){
|
||||||
|
expect(filter("<div>foobar</div>")).toBe("<div>foobar</div>");
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user