Skip to content

Commit

Permalink
Merge branch 'ics-fix' into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
bignall committed Oct 12, 2016
2 parents 1cec616 + cebf106 commit 1222e62
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 107 deletions.
10 changes: 6 additions & 4 deletions addtocalendar.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -173,13 +173,14 @@ addtocalendar
} }


function buildUrl() { function buildUrl() {
var urlData = angular.extend(getSanitizedData(), dates); var urlData = angular.extend(getSanitizedData(), dates),
icsData = angular.extend({}, $scope, dates);


$scope.calendarUrl = { $scope.calendarUrl = {
microsoft: getMicrosoftCalendarUrl(urlData), microsoft: getMicrosoftCalendarUrl(urlData),
google: getGoogleCalendarUrl(urlData), google: getGoogleCalendarUrl(urlData),
yahoo: getYahooCalendarUrl(urlData), yahoo: getYahooCalendarUrl(urlData),
icalendar: getIcsCalendar($scope), icalendar: getIcsCalendar(icsData),
dlIcal: dlIcal dlIcal: dlIcal
}; };
} }
Expand All @@ -192,8 +193,8 @@ addtocalendar
} }


function init() { function init() {
buildUrl();
setTimesFromFormat(); setTimesFromFormat();
buildUrl();
} }


forEachAttr($attrs, function(key) { forEachAttr($attrs, function(key) {
Expand Down Expand Up @@ -250,7 +251,8 @@ addtocalendar
className: '@', className: '@',
btnText: '@', btnText: '@',
caret: '@', caret: '@',
hoverText: '@' hoverText: '@',
format: '@'
}, },
controller: 'AddtocalendarCtrl', controller: 'AddtocalendarCtrl',
template: resolveTemplate template: resolveTemplate
Expand Down
2 changes: 1 addition & 1 deletion addtocalendar.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions addtocalendar/controller.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ addtocalendar
} }


function buildUrl() { function buildUrl() {
var urlData = angular.extend(getSanitizedData(), dates); var urlData = angular.extend(getSanitizedData(), dates),
icsData = angular.extend({}, $scope, dates);


$scope.calendarUrl = { $scope.calendarUrl = {
microsoft: getMicrosoftCalendarUrl(urlData), microsoft: getMicrosoftCalendarUrl(urlData),
google: getGoogleCalendarUrl(urlData), google: getGoogleCalendarUrl(urlData),
yahoo: getYahooCalendarUrl(urlData), yahoo: getYahooCalendarUrl(urlData),
icalendar: getIcsCalendar($scope), icalendar: getIcsCalendar(icsData),
dlIcal: dlIcal dlIcal: dlIcal
}; };
} }
Expand All @@ -52,8 +53,8 @@ addtocalendar
} }


function init() { function init() {
buildUrl();
setTimesFromFormat(); setTimesFromFormat();
buildUrl();
} }


forEachAttr($attrs, function(key) { forEachAttr($attrs, function(key) {
Expand Down
3 changes: 2 additions & 1 deletion addtocalendar/directive.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ addtocalendar
className: '@', className: '@',
btnText: '@', btnText: '@',
caret: '@', caret: '@',
hoverText: '@' hoverText: '@',
format: '@'
}, },
controller: 'AddtocalendarCtrl', controller: 'AddtocalendarCtrl',
template: resolveTemplate template: resolveTemplate
Expand Down
187 changes: 96 additions & 91 deletions test/controller.spec.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,114 +17,119 @@ describe('AddtocalendarCtrl', function() {
FileSaver = _FileSaver_; FileSaver = _FileSaver_;
})); }));


/** Object.keys(eventFixtures).forEach(function (scope) {
* Yahoo! Calendar
*/ /**
describe('$scope.calendarUrl.yahoo', function() { * Yahoo! Calendar

*/
it('should return the url to add event to a yahoo calendar', function() { describe('$scope.calendarUrl.yahoo ' + scope, function() {
var $scope = sampleEventFixture;

it('should return the url to add event to a yahoo calendar', function() {
$controller('AddtocalendarCtrl', { var $scope = eventFixtures[scope];
$scope: $scope,
$attrs: {} $controller('AddtocalendarCtrl', {
}); $scope: $scope,

$attrs: {}
var regex = CalendarRegex.getUrlRegex('calendar.yahoo.com/', { });
v: 60,
view: 'd', var regex = CalendarRegex.getUrlRegex('calendar.yahoo.com/', {
type: 20, v: 60,
TITLE: '(.*)', view: 'd',
ST: CalendarRegex.dateRegex, type: 20,
DUR: CalendarRegex.militaryHoursRegex, TITLE: '(.*)',
DESC: '(.*)', ST: CalendarRegex.dateRegex,
in_loc: '(.*)' DUR: CalendarRegex.militaryHoursRegex,
DESC: '(.*)',
in_loc: '(.*)'
});

var isValidYahooCalendar = regex.test($scope.calendarUrl.yahoo);

expect(isValidYahooCalendar).toEqual(true);
}); });


var isValidYahooCalendar = regex.test($scope.calendarUrl.yahoo); });

expect(isValidYahooCalendar).toEqual(true);
});

});

/**
* Google Calendar
*/
describe('$scope.calendarUrl.google', function() {
var $scope = sampleEventFixture;

it('should return the url to add event to a google calendar', function() {
$controller('AddtocalendarCtrl', {
$scope: $scope,
$attrs: {}
});


var regex = CalendarRegex.getUrlRegex('www.google.com/calendar/render', { /**
action: 'TEMPLATE', * Google Calendar
text: '(.*)', */
dates: CalendarRegex.dateRegex + '\\/' + CalendarRegex.dateRegex, describe('$scope.calendarUrl.google ' + scope, function() {
details: '(.*)', var $scope = eventFixtures[scope];
location: '(.*)'
it('should return the url to add event to a google calendar', function() {
$controller('AddtocalendarCtrl', {
$scope: $scope,
$attrs: {}
});

var regex = CalendarRegex.getUrlRegex('www.google.com/calendar/render', {
action: 'TEMPLATE',
text: '(.*)',
dates: CalendarRegex.dateRegex + '\\/' + CalendarRegex.dateRegex,
details: '(.*)',
location: '(.*)'
});

var isValidGoogleCalendar = regex.test($scope.calendarUrl.google);

expect(isValidGoogleCalendar).toEqual(true);
}); });


var isValidGoogleCalendar = regex.test($scope.calendarUrl.google);

expect(isValidGoogleCalendar).toEqual(true);
}); });


}); /**

* Windows Live Calendar
/** */
* Windows Live Calendar describe('$scope.calendarUrl.microsoft ' + scope, function() {
*/ var $scope = eventFixtures[scope];
describe('$scope.calendarUrl.microsoft', function() {
var $scope = sampleEventFixture; it('should return the url to add event to a windows live calendar', function() {

$controller('AddtocalendarCtrl', {
it('should return the url to add event to a windows live calendar', function() { $scope: $scope,
$controller('AddtocalendarCtrl', { $attrs: {}
$scope: $scope, });
$attrs: {}
var regex = CalendarRegex.getUrlRegex('calendar.live.com/calendar/calendar.aspx', {
rru: 'addevent',
summary: '(.*)',
dtstart: CalendarRegex.dateRegex,
dtend: CalendarRegex.dateRegex,
description: '(.*)',
location: '(.*)'
});

var isValidMicrosoftCalendar = regex.test($scope.calendarUrl.microsoft);

expect(isValidMicrosoftCalendar).toEqual(true);
}); });


var regex = CalendarRegex.getUrlRegex('calendar.live.com/calendar/calendar.aspx', {
rru: 'addevent',
summary: '(.*)',
dtstart: CalendarRegex.dateRegex,
dtend: CalendarRegex.dateRegex,
description: '(.*)',
location: '(.*)'
});

var isValidMicrosoftCalendar = regex.test($scope.calendarUrl.microsoft);

expect(isValidMicrosoftCalendar).toEqual(true);
}); });


}); /**
* iCalendar/Outlook
*/
describe('$scope.calendarUrl.icalendar ' + scope, function() {
var $scope = eventFixtures[scope];


/** it('should return the url and data of an icalendar file', function() {
* iCalendar/Outlook $controller('AddtocalendarCtrl', {
*/ $scope: $scope,
describe('$scope.calendarUrl.icalendar', function() { $attrs: {}
var $scope = sampleEventFixture; });

it('should return the url and data of an icalendar file', function() {
$controller('AddtocalendarCtrl', {
$scope: $scope,
$attrs: {}
});


var regex = CalendarRegex.getIcsCalendarRegex(); var regex = CalendarRegex.getIcsCalendarRegex();


sinon.stub(FileSaver, 'saveAs'); sinon.stub(FileSaver, 'saveAs');


$scope.calendarUrl.dlIcal(); $scope.calendarUrl.dlIcal();
sinon.spy(); sinon.spy();
var isValidICalendar = regex.test($scope.calendarUrl.icalendar); var isValidICalendar = regex.test($scope.calendarUrl.icalendar);

expect(isValidICalendar).toEqual(true);
});


expect(isValidICalendar).toEqual(true);
}); });


}); });

}); });
25 changes: 18 additions & 7 deletions test/fixtures/sampleEvent.fixture.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@
* angular-addtocalendar * angular-addtocalendar
* An AngularJS directive for adding an event to calendar apps. * An AngularJS directive for adding an event to calendar apps.
*/ */
var sampleEventFixture = { var eventFixtures = {
startDate: '20150704T190000', sampleEventFixture: {
endDate: '20150704T210000', startDate: '20150704T190000',
title: 'A sample event!', endDate: '20150704T210000',
description: 'Some interesting description here.', title: 'A sample event!',
location: '1 Futurama Pl, New New York' description: 'Some interesting description here.',
}; location: '1 Futurama Pl, New New York'
},

alternateFormatFixture: {
startDate: '01/01/2016',
endDate: '01/01/2016',
format: 'MM/DD/YYYY',
title: 'An alternate format event',
description: 'something happening',
location: 'Somewhere out there'
}
};

0 comments on commit 1222e62

Please sign in to comment.