Adam Shaw 7 лет назад
Родитель
Сommit
cd2bf28a5a
2 измененных файлов с 25 добавлено и 64 удалено
  1. 8 7
      tests/automated/globals.js
  2. 17 57
      tests/automated/lib/moment.js

+ 8 - 7
tests/automated/globals.js

@@ -120,13 +120,6 @@ window.describeValues = function(hash, callback) {
 // ---------------------------------------------------------------------------------------------------------------------
 
 const timezoneScenarios = {
-  none: {
-    description: 'when no timezone',
-    value: null,
-    moment: function(str) {
-      return FullCalendar.moment.parseZone(str)
-    }
-  },
   local: {
     description: 'when local timezone',
     value: 'local',
@@ -209,3 +202,11 @@ window.spyCall = function(func) {
   spyOn(obj, 'func').and.callThrough()
   return obj.func
 }
+
+
+// Defaults that apply to all tests
+// ---------------------------------------------------------------------------------------------------------------------
+
+window.pushOptions({
+  timezone: 'UTC'
+})

+ 17 - 57
tests/automated/lib/moment.js

@@ -1,6 +1,7 @@
 
 beforeEach(function() {
   jasmine.addMatchers({
+
     toEqualDate() {
       return {
         compare: function(actual, expected) {
@@ -29,71 +30,30 @@ beforeEach(function() {
             result = { pass: true }
           }
 
-          return result
-        }
-      }
-    }
-  })
-})
-
-// kill all this...
-
-function serializeDuration(duration) {
-  return Math.floor(duration.asDays()) + '.' +
-    pad(duration.hours(), 2) + ':' +
-    pad(duration.minutes(), 2) + ':' +
-    pad(duration.seconds(), 2) + '.' +
-    pad(duration.milliseconds(), 3)
-}
-
-function pad(n, width) {
-  n = n + ''
-  return n.length >= width ? n : new Array(width - n.length + 1).join('0') + n
-}
-
-beforeEach(function() {
-  jasmine.addMatchers({
-
-    toEqualMoment() {
-      return {
-        compare: function(actual, expected) {
-          var actualStr = FullCalendar.moment.parseZone(actual).format()
-          var expectedStr = FullCalendar.moment.parseZone(expected).format()
-          var result = {
-            pass: actualStr === expectedStr
-          }
-          if (!result.pass) {
-            result.message = 'Moment ' + actualStr + ' does not equal ' + expectedStr
-          }
           return result
         }
       }
     },
+
     toEqualNow() {
       return {
         compare: function(actual) {
-          var actualMoment = FullCalendar.moment.parseZone(actual)
-          var result = {
-            pass: Math.abs(actualMoment - new Date()) < 1000 // within a second of current datetime
-          }
-          if (!result.pass) {
-            result.message = 'Moment ' + actualMoment.format() + ' is not close enough to now'
-          }
-          return result
-        }
-      }
-    },
-    toEqualDuration() {
-      return {
-        compare: function(actual, expected) {
-          var actualStr = serializeDuration(moment.duration(actual))
-          var expectedStr = serializeDuration(moment.duration(expected))
-          var result = {
-            pass: actualStr === expectedStr
-          }
-          if (!result.pass) {
-            result.message = 'Duration ' + actualStr + ' does not equal ' + expectedStr
+          var result
+
+          if (!(actual instanceof Date)) {
+            result = {
+              pass: false,
+              message: 'Actual value ' + actual + ' needs to be an instance of a Date'
+            }
+          } else if (Math.abs(actual.valueOf() - new Date().valueOf()) > 1000) {
+            result = {
+              pass: false,
+              message: 'Date ' + actual.toUTCString() + ' is not close enough to now'
+            }
+          } else {
+            result = { pass: true }
           }
+
           return result
         }
       }