From 7e1dac778249edc7efbbf64f7e57f27bd7e5cda1 Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Fri, 13 Jun 2014 12:59:40 -0700 Subject: [PATCH] tests for displayEventEnd, as well as affected dnd/resize tests --- tests/automated/displayEventEnd.js | 142 +++++++++++++++++++++++++++++ tests/automated/event-dnd.js | 67 ++++++++++++++ tests/automated/event-resize.js | 86 +++++++++++++++++ 3 files changed, 295 insertions(+) create mode 100644 tests/automated/displayEventEnd.js diff --git a/tests/automated/displayEventEnd.js b/tests/automated/displayEventEnd.js new file mode 100644 index 0000000..35cef45 --- /dev/null +++ b/tests/automated/displayEventEnd.js @@ -0,0 +1,142 @@ +describe('displayEventEnd', function() { + + var options; + + beforeEach(function() { + affix('#cal'); + options = { + defaultDate: '2014-06-13', + timeFormat: 'H:mm' + }; + }); + + afterEach(function() { + $('#cal').fullCalendar('destroy'); + }); + + [ 'month', 'agendaWeek' ].forEach(function(viewName) { + describe('when in ' + viewName + ' view', function() { + beforeEach(function() { + options.defaultView = viewName; + }); + + describe('when off', function() { + beforeEach(function() { + options.displayEventEnd = false; + }); + + describe('with an all-day event', function() { + beforeEach(function() { + options.events = [ { + title: 'timed event', + start: '2014-06-13', + end: '2014-06-13', + allDay: true + } ]; + }); + it('displays no time text', function(done) { + options.eventAfterAllRender = function() { + expect($('.fc-event-time').length).toBe(0); + done(); + }; + $('#cal').fullCalendar(options); + }); + }); + + describe('with a timed event with no end time', function(done) { + beforeEach(function() { + options.events = [ { + title: 'timed event', + start: '2014-06-13T01:00:00', + allDay: false + } ]; + }); + it('displays only the start time text', function(done) { + options.eventAfterAllRender = function() { + expect($('.fc-event-time')).toHaveText('1:00'); + done(); + }; + $('#cal').fullCalendar(options); + }); + }); + + describe('with a timed event with an end time', function() { + beforeEach(function() { + options.events = [ { + title: 'timed event', + start: '2014-06-13T01:00:00', + end: '2014-06-13T02:00:00', + allDay: false + } ]; + }); + it('displays only the start time text', function(done) { + options.eventAfterAllRender = function() { + expect($('.fc-event-time')).toHaveText('1:00'); + done(); + }; + $('#cal').fullCalendar(options); + }); + }); + }); + + describe('when on', function() { + beforeEach(function() { + options.displayEventEnd = true; + }); + + describe('with an all-day event', function() { + beforeEach(function() { + options.events = [ { + title: 'timed event', + start: '2014-06-13', + end: '2014-06-13', + allDay: true + } ]; + }); + it('displays no time text', function(done) { + options.eventAfterAllRender = function() { + expect($('.fc-event-time').length).toBe(0); + done(); + }; + $('#cal').fullCalendar(options); + }); + }); + + describe('with a timed event with no end time', function(done) { + beforeEach(function() { + options.events = [ { + title: 'timed event', + start: '2014-06-13T01:00:00', + allDay: false + } ]; + }); + it('displays only the start time text', function(done) { + options.eventAfterAllRender = function() { + expect($('.fc-event-time')).toHaveText('1:00'); + done(); + }; + $('#cal').fullCalendar(options); + }); + }); + + describe('with a timed event with an end time', function() { + beforeEach(function() { + options.events = [ { + title: 'timed event', + start: '2014-06-13T01:00:00', + end: '2014-06-13T02:00:00', + allDay: false + } ]; + }); + it('displays both the start and end time text', function(done) { + options.eventAfterAllRender = function() { + expect($('.fc-event-time')).toHaveText('1:00 - 2:00'); + done(); + }; + $('#cal').fullCalendar(options); + }); + }); + }); + }); + }); +}); \ No newline at end of file diff --git a/tests/automated/event-dnd.js b/tests/automated/event-dnd.js index 78778cc..f888081 100644 --- a/tests/automated/event-dnd.js +++ b/tests/automated/event-dnd.js @@ -262,6 +262,73 @@ describe('eventDrop', function() { ); }); }); + + describe('when dragging a timed event with no end time', function() { + it('should continue to only show the updated start time', function(done) { + var dragged = false; + var eventElm; + + options.scrollTime = '01:00:00'; + options.events = [ { + title: 'timed event', + start: '2014-06-11T01:00:00', + allDay: false + } ]; + + init( + function() { + eventElm = $('.fc-event') + .simulate('mouseover') // for our dumb optimization + .simulate('drag', { + dy: $('tr.fc-slot1').height() * 3, // 1.5 hours + callback: function() { + dragged = true; + expect(eventElm.find('.fc-event-time')).toHaveText('2:30'); + eventElm.simulate('drop'); + } + }); + }, + function() { + expect(dragged).toBe(true); + done(); + } + ); + }); + }); + + describe('when dragging a timed event with an end time', function() { + it('should continue to show the updated start and end time', function(done) { + var dragged = false; + var eventElm; + + options.scrollTime = '01:00:00'; + options.events = [ { + title: 'timed event', + start: '2014-06-11T01:00:00', + end: '2014-06-11T02:00:00', + allDay: false + } ]; + + init( + function() { + eventElm = $('.fc-event') + .simulate('mouseover') // for our dumb optimization + .simulate('drag', { + dy: $('tr.fc-slot1').height() * 3, // 1.5 hours + callback: function() { + dragged = true; + expect(eventElm.find('.fc-event-time')).toHaveText('2:30 - 3:30'); + eventElm.simulate('drop'); + } + }); + }, + function() { + expect(dragged).toBe(true); + done(); + } + ); + }); + }); }); // Initialize a calendar, run a drag, and do type-checking of all arguments for all handlers. diff --git a/tests/automated/event-resize.js b/tests/automated/event-resize.js index 6ccae95..e3a7043 100644 --- a/tests/automated/event-resize.js +++ b/tests/automated/event-resize.js @@ -146,6 +146,92 @@ describe('eventResize', function() { } ); }); + + it('should display the correct time text while resizing', function(done) { + var dy; + var handle; + + init( + function() { + dy = $('tr.fc-slot1').height() * 4.5; // 5 slots, so 2.5 hours + handle = $('.fc-event .ui-resizable-handle') + .simulate('mouseover') // for our dumb optimization + .simulate('drag', { + dy: dy, + callback: function() { + expect($('.fc-event-time')).toHaveText('5:00 - 9:30'); + handle.simulate('drag', { + // BUG with jquery-simulate-ext + // I guess the delta is still relative to the original position, so should be zero. + // But zero causes nothing to happen, so make it a tiny non-zero delta. + dy: -1, + + callback: function() { + expect($('.fc-event-time')).toHaveText('5:00 - 7:00'); + handle.simulate('drop', { + callback: function() { + done(); + } + }); + } + }); + } + }); + }, + function() { + // this wasn't firing for some reason. do it in the drop callback instead + //done(); + } + ); + }); + }); + + describe('when resizing a timed event without an end', function() { + beforeEach(function() { + options.events = [ { + title: 'timed event event', + start: '2014-06-11T05:00:00', + allDay: false + } ]; + }); + + it('should display the correct time text while resizing', function(done) { + var dy; + var handle; + + init( + function() { + dy = $('tr.fc-slot1').height() * 4.5; // 5 slots, so 2.5 hours + handle = $('.fc-event .ui-resizable-handle') + .simulate('mouseover') // for our dumb optimization + .simulate('drag', { + dy: dy, + callback: function() { + expect($('.fc-event-time')).toHaveText('5:00 - 9:30'); + handle.simulate('drag', { + // BUG with jquery-simulate-ext + // I guess the delta is still relative to the original position, so should be zero. + // But zero causes nothing to happen, so make it a tiny non-zero delta. + dy: -1, + + callback: function() { + expect($('.fc-event-time')).toHaveText('5:00'); + handle.simulate('drop', { + callback: function() { + done(); + } + }); + } + }); + } + }); + }, + function() { + // this wasn't firing for some reason. do it in the drop callback instead + //done(); + } + ); + }); }); });