Skip to content

Commit

Permalink
Emit warnings if we use shortDate or shortDateTime filters
Browse files Browse the repository at this point in the history
refs #1474
  • Loading branch information
davidmiller committed Nov 1, 2018
1 parent 39d55b4 commit 0617ec2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
13 changes: 8 additions & 5 deletions opal/static/js/opal/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ filters.filter('fromNow', function(toMomentFilter){
};
});

filters.filter('shortDate', function(toMomentFilter){
filters.filter('shortDate', function(toMomentFilter, $log){
return function(input){
$log.warn('shortDate will be removed in Opal 0.14.0')
if(!input){
return
}
Expand All @@ -83,9 +84,10 @@ filters.filter('shortDate', function(toMomentFilter){
}
});

filters.filter('shortDateTime', function(shortDateFilter, hhmmFilter){
filters.filter('shortDateTime', function(shortDateFilter, hhmmFilter, $log){
return function(input){
var datePart = shortDateFilter(input);
$log.warn('shortDateTime will be removed in Opal 0.14.0')
var datePart = shortDateFilter(input);
var timePart = hhmmFilter(input);

if(datePart && timePart){
Expand All @@ -95,9 +97,10 @@ filters.filter('shortDateTime', function(shortDateFilter, hhmmFilter){
});


filters.filter('shortTime', function(shortDateFilter, hhmmFilter){
filters.filter('shortTime', function(shortDateFilter, hhmmFilter, $log){
return function(input){
var toChange;
$log.warn('shortTime will be removed in Opal 0.14.0')
var toChange;
if(_.isDate(input)){
toChange = moment(input);
}
Expand Down
36 changes: 34 additions & 2 deletions opal/static/js/test/filters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,22 @@ describe('filters', function() {
});

describe('shortDate', function() {
var log;

beforeEach(function(){
inject(function($injector){
log = $injector.get('$log');
});

spyOn(log, 'warn');
});

it('should log a warning message', function() {
inject(function(shortDateFilter) {
shortDateFilter();
expect(log.warn).toHaveBeenCalledWith('shortDate will be removed in Opal 0.14.0');
});
});

it('should return undefined for no input',
inject(function(shortDateFilter) {
Expand All @@ -177,12 +193,20 @@ describe('filters', function() {
});

describe('shortTime', function(){
var shortTime;
var shortTime, log;

beforeEach(function(){
inject(function($injector){
shortTime = $injector.get('shortTimeFilter');
log = $injector.get('$log');
});

spyOn(log, 'warn');
});

it('should log a warning message', function() {
shortTime()
expect(log.warn).toHaveBeenCalledWith('shortTime will be removed in Opal 0.14.0')
});

it('should display the time as hh:mm from string', function(){
Expand Down Expand Up @@ -295,14 +319,22 @@ describe('filters', function() {
});

describe('shortDateTime', function(){
var shortDateTime;
var shortDateTime, log;

beforeEach(function(){
inject(function($injector){
shortDateTime = $injector.get('shortDateTimeFilter');
log = $injector.get('$log');
});
spyOn(log, 'warn');
});

it('should log a warning message', function() {
shortDateTime()
expect(log.warn).toHaveBeenCalledWith('shortDateTime will be removed in Opal 0.14.0')
});


it('should return undefined if no input', function(){
expect(shortDateTime(null)).toBe(undefined);
});
Expand Down

0 comments on commit 0617ec2

Please sign in to comment.