mirror of
https://github.com/ZwareBear/awx.git
synced 2026-05-15 07:48:38 -05:00
First pass at unit tests for the filters in shared/filters
This commit is contained in:
@@ -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("");
|
||||
});
|
||||
});
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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("");
|
||||
});
|
||||
});
|
||||
@@ -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