Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'ics-fix' into trunk
  • 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
Expand Up @@ -173,13 +173,14 @@ addtocalendar
}

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

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

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

forEachAttr($attrs, function(key) {
Expand Down Expand Up @@ -250,7 +251,8 @@ addtocalendar
className: '@',
btnText: '@',
caret: '@',
hoverText: '@'
hoverText: '@',
format: '@'
},
controller: 'AddtocalendarCtrl',
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
Expand Up @@ -33,13 +33,14 @@ addtocalendar
}

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

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

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

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

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

it('should return the url to add event to a yahoo calendar', function() {
var $scope = sampleEventFixture;

$controller('AddtocalendarCtrl', {
$scope: $scope,
$attrs: {}
});

var regex = CalendarRegex.getUrlRegex('calendar.yahoo.com/', {
v: 60,
view: 'd',
type: 20,
TITLE: '(.*)',
ST: CalendarRegex.dateRegex,
DUR: CalendarRegex.militaryHoursRegex,
DESC: '(.*)',
in_loc: '(.*)'
Object.keys(eventFixtures).forEach(function (scope) {

/**
* Yahoo! Calendar
*/
describe('$scope.calendarUrl.yahoo ' + scope, function() {

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

$controller('AddtocalendarCtrl', {
$scope: $scope,
$attrs: {}
});

var regex = CalendarRegex.getUrlRegex('calendar.yahoo.com/', {
v: 60,
view: 'd',
type: 20,
TITLE: '(.*)',
ST: CalendarRegex.dateRegex,
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',
text: '(.*)',
dates: CalendarRegex.dateRegex + '\\/' + CalendarRegex.dateRegex,
details: '(.*)',
location: '(.*)'
/**
* Google Calendar
*/
describe('$scope.calendarUrl.google ' + scope, function() {
var $scope = eventFixtures[scope];

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
*/
describe('$scope.calendarUrl.microsoft', function() {
var $scope = sampleEventFixture;

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

it('should return the url to add event to a windows live calendar', function() {
$controller('AddtocalendarCtrl', {
$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];

/**
* iCalendar/Outlook
*/
describe('$scope.calendarUrl.icalendar', function() {
var $scope = sampleEventFixture;

it('should return the url and data of an icalendar file', function() {
$controller('AddtocalendarCtrl', {
$scope: $scope,
$attrs: {}
});
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();
sinon.spy();
var isValidICalendar = regex.test($scope.calendarUrl.icalendar);
$scope.calendarUrl.dlIcal();
sinon.spy();
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
Expand Up @@ -2,10 +2,21 @@
* angular-addtocalendar
* An AngularJS directive for adding an event to calendar apps.
*/
var sampleEventFixture = {
startDate: '20150704T190000',
endDate: '20150704T210000',
title: 'A sample event!',
description: 'Some interesting description here.',
location: '1 Futurama Pl, New New York'
};
var eventFixtures = {
sampleEventFixture: {
startDate: '20150704T190000',
endDate: '20150704T210000',
title: 'A sample event!',
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.