|
|
@@ -1,8 +1,9 @@
|
|
|
import { addDays } from '@fullcalendar/core'
|
|
|
import { parseUtcDate } from '../lib/date-parsing'
|
|
|
+import CalendarWrapper from '../lib/wrappers/CalendarWrapper'
|
|
|
|
|
|
describe('current date', function() {
|
|
|
- var TITLE_FORMAT = {
|
|
|
+ const TITLE_FORMAT = {
|
|
|
month: 'long',
|
|
|
day: 'numeric',
|
|
|
year: 'numeric',
|
|
|
@@ -20,38 +21,38 @@ describe('current date', function() {
|
|
|
describe('defaultDate & getDate', function() { // keep getDate
|
|
|
describeWhenInMonth(function() {
|
|
|
it('should initialize at the date', function() {
|
|
|
- var options = {}
|
|
|
- options.defaultDate = '2011-03-10'
|
|
|
- initCalendar(options)
|
|
|
- expectViewDates('2011-02-27', '2011-04-10', '2011-03-01', '2011-04-01')
|
|
|
- var currentDate = currentCalendar.getDate()
|
|
|
+ let calendar = initCalendar({
|
|
|
+ defaultDate: '2011-03-10'
|
|
|
+ })
|
|
|
+ expectViewDates(calendar, '2011-02-27', '2011-04-10', '2011-03-01', '2011-04-01')
|
|
|
+ let currentDate = calendar.getDate()
|
|
|
expect(currentDate instanceof Date).toEqual(true) // test the type, but only here
|
|
|
expect(currentDate).toEqualDate('2011-03-10')
|
|
|
})
|
|
|
})
|
|
|
describeWhenInWeek(function() {
|
|
|
it('should initialize at the date, given a date string', function() {
|
|
|
- var options = {}
|
|
|
- options.defaultDate = '2011-03-10'
|
|
|
- initCalendar(options)
|
|
|
- expectViewDates('2011-03-06', '2011-03-13')
|
|
|
- expect(currentCalendar.getDate()).toEqualDate('2011-03-10')
|
|
|
+ let calendar = initCalendar({
|
|
|
+ defaultDate: '2011-03-10'
|
|
|
+ })
|
|
|
+ expectViewDates(calendar, '2011-03-06', '2011-03-13')
|
|
|
+ expect(calendar.getDate()).toEqualDate('2011-03-10')
|
|
|
})
|
|
|
it('should initialize at the date, given a Date object', function() {
|
|
|
- var options = {}
|
|
|
- options.defaultDate = parseUtcDate('2011-03-10')
|
|
|
- initCalendar(options)
|
|
|
- expectViewDates('2011-03-06', '2011-03-13')
|
|
|
- expect(currentCalendar.getDate()).toEqualDate('2011-03-10')
|
|
|
+ let calendar = initCalendar({
|
|
|
+ defaultDate: parseUtcDate('2011-03-10')
|
|
|
+ })
|
|
|
+ expectViewDates(calendar, '2011-03-06', '2011-03-13')
|
|
|
+ expect(calendar.getDate()).toEqualDate('2011-03-10')
|
|
|
})
|
|
|
})
|
|
|
describeWhenInDay(function() {
|
|
|
it('should initialize at the date', function() {
|
|
|
- var options = {}
|
|
|
- options.defaultDate = '2011-03-10'
|
|
|
- initCalendar(options)
|
|
|
- expectViewDates('2011-03-10')
|
|
|
- expect(currentCalendar.getDate()).toEqualDate('2011-03-10')
|
|
|
+ let calendar = initCalendar({
|
|
|
+ defaultDate: '2011-03-10'
|
|
|
+ })
|
|
|
+ expectViewDates(calendar, '2011-03-10')
|
|
|
+ expect(calendar.getDate()).toEqualDate('2011-03-10')
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
@@ -59,33 +60,33 @@ describe('current date', function() {
|
|
|
describe('gotoDate', function() {
|
|
|
describeWhenInMonth(function() {
|
|
|
it('should go to a date when given a date string', function() {
|
|
|
- initCalendar()
|
|
|
- currentCalendar.gotoDate('2015-04-01')
|
|
|
- expectViewDates('2015-03-29', '2015-05-10', '2015-04-01', '2015-05-01')
|
|
|
+ let calendar = initCalendar()
|
|
|
+ calendar.gotoDate('2015-04-01')
|
|
|
+ expectViewDates(calendar, '2015-03-29', '2015-05-10', '2015-04-01', '2015-05-01')
|
|
|
})
|
|
|
})
|
|
|
describeWhenInWeek(function() {
|
|
|
it('should go to a date when given a date string', function() {
|
|
|
- initCalendar()
|
|
|
- currentCalendar.gotoDate('2015-04-01')
|
|
|
- expectViewDates('2015-03-29', '2015-04-05')
|
|
|
+ let calendar = initCalendar()
|
|
|
+ calendar.gotoDate('2015-04-01')
|
|
|
+ expectViewDates(calendar, '2015-03-29', '2015-04-05')
|
|
|
})
|
|
|
it('should go to a date when given a date string with a time', function() {
|
|
|
- initCalendar()
|
|
|
- currentCalendar.gotoDate('2015-04-01T12:00:00')
|
|
|
- expectViewDates('2015-03-29', '2015-04-05')
|
|
|
+ let calendar = initCalendar()
|
|
|
+ calendar.gotoDate('2015-04-01T12:00:00')
|
|
|
+ expectViewDates(calendar, '2015-03-29', '2015-04-05')
|
|
|
})
|
|
|
it('should go to a date when given a Date object', function() {
|
|
|
- initCalendar()
|
|
|
- currentCalendar.gotoDate(parseUtcDate('2015-04-01'))
|
|
|
- expectViewDates('2015-03-29', '2015-04-05')
|
|
|
+ let calendar = initCalendar()
|
|
|
+ calendar.gotoDate(parseUtcDate('2015-04-01'))
|
|
|
+ expectViewDates(calendar, '2015-03-29', '2015-04-05')
|
|
|
})
|
|
|
})
|
|
|
describeWhenInDay(function() {
|
|
|
it('should go to a date when given a date string', function() {
|
|
|
- initCalendar()
|
|
|
- currentCalendar.gotoDate('2015-04-01')
|
|
|
- expectViewDates('2015-04-01')
|
|
|
+ let calendar = initCalendar()
|
|
|
+ calendar.gotoDate('2015-04-01')
|
|
|
+ expectViewDates(calendar, '2015-04-01')
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
@@ -93,33 +94,33 @@ describe('current date', function() {
|
|
|
describe('incrementDate', function() {
|
|
|
describeWhenInMonth(function() {
|
|
|
it('should increment the date when given a Duration object', function() {
|
|
|
- initCalendar()
|
|
|
- currentCalendar.incrementDate({ months: -1 })
|
|
|
- expectViewDates('2014-04-27', '2014-06-08', '2014-05-01', '2014-06-01')
|
|
|
+ let calendar = initCalendar()
|
|
|
+ calendar.incrementDate({ months: -1 })
|
|
|
+ expectViewDates(calendar, '2014-04-27', '2014-06-08', '2014-05-01', '2014-06-01')
|
|
|
})
|
|
|
})
|
|
|
describeWhenInWeek(function() {
|
|
|
it('should increment the date when given a Duration object', function() {
|
|
|
- initCalendar()
|
|
|
- currentCalendar.incrementDate({ weeks: -2 })
|
|
|
- expectViewDates('2014-05-18', '2014-05-25')
|
|
|
+ let calendar = initCalendar()
|
|
|
+ calendar.incrementDate({ weeks: -2 })
|
|
|
+ expectViewDates(calendar, '2014-05-18', '2014-05-25')
|
|
|
})
|
|
|
})
|
|
|
describeWhenInDay(function() {
|
|
|
it('should increment the date when given a Duration object', function() {
|
|
|
- initCalendar()
|
|
|
- currentCalendar.incrementDate({ days: 2 })
|
|
|
- expectViewDates('2014-06-03')
|
|
|
+ let calendar = initCalendar()
|
|
|
+ calendar.incrementDate({ days: 2 })
|
|
|
+ expectViewDates(calendar, '2014-06-03')
|
|
|
})
|
|
|
it('should increment the date when given a Duration string', function() {
|
|
|
- initCalendar()
|
|
|
- currentCalendar.incrementDate('2.00:00:00')
|
|
|
- expectViewDates('2014-06-03')
|
|
|
+ let calendar = initCalendar()
|
|
|
+ calendar.incrementDate('2.00:00:00')
|
|
|
+ expectViewDates(calendar, '2014-06-03')
|
|
|
})
|
|
|
it('should increment the date when given a Duration string with a time', function() {
|
|
|
- initCalendar()
|
|
|
- currentCalendar.incrementDate('2.05:30:00')
|
|
|
- expectViewDates('2014-06-03')
|
|
|
+ let calendar = initCalendar()
|
|
|
+ calendar.incrementDate('2.05:30:00')
|
|
|
+ expectViewDates(calendar, '2014-06-03')
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
@@ -127,23 +128,23 @@ describe('current date', function() {
|
|
|
describe('prevYear', function() {
|
|
|
describeWhenInMonth(function() {
|
|
|
it('should move the calendar back a year', function() {
|
|
|
- initCalendar()
|
|
|
- currentCalendar.prevYear()
|
|
|
- expectViewDates('2013-05-26', '2013-07-07', '2013-06-01', '2013-07-01')
|
|
|
+ let calendar = initCalendar()
|
|
|
+ calendar.prevYear()
|
|
|
+ expectViewDates(calendar, '2013-05-26', '2013-07-07', '2013-06-01', '2013-07-01')
|
|
|
})
|
|
|
})
|
|
|
describeWhenInWeek(function() {
|
|
|
it('should move the calendar back a year', function() {
|
|
|
- initCalendar()
|
|
|
- currentCalendar.prevYear()
|
|
|
- expectViewDates('2013-05-26', '2013-06-02')
|
|
|
+ let calendar = initCalendar()
|
|
|
+ calendar.prevYear()
|
|
|
+ expectViewDates(calendar, '2013-05-26', '2013-06-02')
|
|
|
})
|
|
|
})
|
|
|
describeWhenInDay(function() {
|
|
|
it('should move the calendar back a year', function() {
|
|
|
- initCalendar()
|
|
|
- currentCalendar.prevYear()
|
|
|
- expectViewDates('2013-06-01')
|
|
|
+ let calendar = initCalendar()
|
|
|
+ calendar.prevYear()
|
|
|
+ expectViewDates(calendar, '2013-06-01')
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
@@ -151,23 +152,23 @@ describe('current date', function() {
|
|
|
describe('nextYear', function() {
|
|
|
describeWhenInMonth(function() {
|
|
|
it('should move the calendar forward a year', function() {
|
|
|
- initCalendar()
|
|
|
- currentCalendar.nextYear()
|
|
|
- expectViewDates('2015-05-31', '2015-07-12', '2015-06-01', '2015-07-01')
|
|
|
+ let calendar = initCalendar()
|
|
|
+ calendar.nextYear()
|
|
|
+ expectViewDates(calendar, '2015-05-31', '2015-07-12', '2015-06-01', '2015-07-01')
|
|
|
})
|
|
|
})
|
|
|
describeWhenInWeek(function() {
|
|
|
it('should move the calendar forward a year', function() {
|
|
|
- initCalendar()
|
|
|
- currentCalendar.nextYear()
|
|
|
- expectViewDates('2015-05-31', '2015-06-07')
|
|
|
+ let calendar = initCalendar()
|
|
|
+ calendar.nextYear()
|
|
|
+ expectViewDates(calendar, '2015-05-31', '2015-06-07')
|
|
|
})
|
|
|
})
|
|
|
describeWhenInDay(function() {
|
|
|
it('should move the calendar forward a year', function() {
|
|
|
- initCalendar()
|
|
|
- currentCalendar.nextYear()
|
|
|
- expectViewDates('2015-06-01')
|
|
|
+ let calendar = initCalendar()
|
|
|
+ calendar.nextYear()
|
|
|
+ expectViewDates(calendar, '2015-06-01')
|
|
|
})
|
|
|
})
|
|
|
})
|
|
|
@@ -175,22 +176,24 @@ describe('current date', function() {
|
|
|
describe('when current date is a hidden day', function() {
|
|
|
describeWhenInMonth(function() {
|
|
|
it('should display the current month even if first day of month', function() {
|
|
|
- var options = {}
|
|
|
- options.now = options.defaultDate = '2014-06-01' // a Sunday
|
|
|
- options.weekends = false
|
|
|
- initCalendar(options)
|
|
|
- var view = currentCalendar.view
|
|
|
+ let calendar = initCalendar({
|
|
|
+ now: '2014-06-01', // a Sunday
|
|
|
+ defaultDate: '2014-06-01', // a Sunday
|
|
|
+ weekends: false
|
|
|
+ })
|
|
|
+ let view = calendar.view
|
|
|
expect(view.activeStart).toEqualDate('2014-06-02')
|
|
|
expect(view.activeEnd).toEqualDate('2014-07-12')
|
|
|
expect(view.currentStart).toEqualDate('2014-06-01')
|
|
|
expect(view.currentEnd).toEqualDate('2014-07-01')
|
|
|
})
|
|
|
it('should display the current month', function() {
|
|
|
- var options = {}
|
|
|
- options.now = options.defaultDate = '2014-05-04' // a Sunday
|
|
|
- options.weekends = false
|
|
|
- initCalendar(options)
|
|
|
- var view = currentCalendar.view
|
|
|
+ let calendar = initCalendar({
|
|
|
+ now: '2014-05-04', // a Sunday
|
|
|
+ defaultDate: '2014-05-04', // a Sunday
|
|
|
+ weekends: false
|
|
|
+ })
|
|
|
+ let view = calendar.view
|
|
|
expect(view.activeStart).toEqualDate('2014-04-28')
|
|
|
expect(view.activeEnd).toEqualDate('2014-06-07')
|
|
|
expect(view.currentStart).toEqualDate('2014-05-01')
|
|
|
@@ -198,15 +201,15 @@ describe('current date', function() {
|
|
|
})
|
|
|
describe('when navigating back a month', function() {
|
|
|
it('should not skip months', function() {
|
|
|
- var options = {}
|
|
|
- options.defaultDate = '2014-07-07'
|
|
|
- options.weekends = false
|
|
|
- initCalendar(options)
|
|
|
- var view = currentCalendar.view
|
|
|
+ let calendar = initCalendar({
|
|
|
+ defaultDate: '2014-07-07',
|
|
|
+ weekends: false
|
|
|
+ })
|
|
|
+ let view = calendar.view
|
|
|
expect(view.currentStart).toEqualDate('2014-07-01')
|
|
|
expect(view.currentEnd).toEqualDate('2014-08-01')
|
|
|
- currentCalendar.prev() // will move to Jun 1, which is a Sunday
|
|
|
- view = currentCalendar.view
|
|
|
+ calendar.prev() // will move to Jun 1, which is a Sunday
|
|
|
+ view = calendar.view
|
|
|
expect(view.currentStart).toEqualDate('2014-06-01')
|
|
|
expect(view.currentEnd).toEqualDate('2014-07-01')
|
|
|
})
|
|
|
@@ -214,11 +217,12 @@ describe('current date', function() {
|
|
|
})
|
|
|
describeWhenInDay(function() {
|
|
|
it('should display the next visible day', function() {
|
|
|
- var options = {}
|
|
|
- options.now = options.defaultDate = '2014-06-01' // a Sunday
|
|
|
- options.weekends = false
|
|
|
- initCalendar(options)
|
|
|
- var view = currentCalendar.view
|
|
|
+ let calendar = initCalendar({
|
|
|
+ now: '2014-06-01', // a Sunday
|
|
|
+ defaultDate: '2014-06-01', // a Sunday
|
|
|
+ weekends: false
|
|
|
+ })
|
|
|
+ let view = calendar.view
|
|
|
expect(view.activeStart).toEqualDate('2014-06-02')
|
|
|
expect(view.activeEnd).toEqualDate('2014-06-03')
|
|
|
expect(view.currentStart).toEqualDate('2014-06-02')
|
|
|
@@ -252,10 +256,10 @@ describe('current date', function() {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- function expectViewDates(start, end, titleStart, titleEnd) {
|
|
|
- var view = currentCalendar.view
|
|
|
- var calculatedEnd
|
|
|
- var title
|
|
|
+ function expectViewDates(calendar, start, end, titleStart, titleEnd) {
|
|
|
+ let view = calendar.view
|
|
|
+ let calculatedEnd
|
|
|
+ let title
|
|
|
|
|
|
if (typeof start === 'string') {
|
|
|
start = new Date(start)
|
|
|
@@ -279,16 +283,17 @@ describe('current date', function() {
|
|
|
titleEnd = titleEnd || calculatedEnd
|
|
|
|
|
|
if (titleEnd) {
|
|
|
- title = currentCalendar.formatRange(
|
|
|
+ title = calendar.formatRange(
|
|
|
titleStart,
|
|
|
titleEnd,
|
|
|
TITLE_FORMAT
|
|
|
)
|
|
|
} else {
|
|
|
- title = currentCalendar.formatDate(titleStart, TITLE_FORMAT)
|
|
|
+ title = calendar.formatDate(titleStart, TITLE_FORMAT)
|
|
|
}
|
|
|
|
|
|
- expect($('.fc-toolbar h2')).toContainText(title)
|
|
|
+ let toolbarWrapper = new CalendarWrapper(calendar).toolbar
|
|
|
+ expect(toolbarWrapper.getTitleText()).toBe(title)
|
|
|
}
|
|
|
|
|
|
})
|