Skip to content

Commit

Permalink
fix register function bug and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jannikac committed Jun 18, 2024
1 parent bf9d027 commit e40d894
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/ical/timezone_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const TimezoneService = {

if (component && component instanceof Component) {
if (component.name === 'vtimezone') {
timezone = new Timezone(name);
timezone = new Timezone(component);
name = timezone.tzid;
}
}
Expand Down
6 changes: 3 additions & 3 deletions test/design_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ suite('design', function() {
let vtimezone = vcalendar.getFirstSubcomponent('vtimezone');

timezone = new ICAL.Timezone(vtimezone);
ICAL.TimezoneService.register('test', timezone);
ICAL.TimezoneService.register({ name: 'test', timezone });
});

suiteTeardown(function() {
Expand Down Expand Up @@ -245,8 +245,8 @@ suite('design', function() {
assert.equal(prop.getParameter('tzid'), 'test');

ICAL.TimezoneService.register(
'America/Los_Angeles',
ICAL.Timezone.utcTimezone
{ name: 'America/Los_Angeles',
timezone: ICAL.Timezone.utcTimezone }
);

let undecorated = '2012-09-01T13:05:11';
Expand Down
2 changes: 1 addition & 1 deletion test/event_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ suite('ICAL.Event', function() {
);

let events = root.getAllSubcomponents('vevent');
ICAL.TimezoneService.register(root.getFirstSubcomponent('vtimezone'));
ICAL.TimezoneService.register({ component: root.getFirstSubcomponent('vtimezone') });

events.forEach(function(event) {
if (!event.hasProperty('recurrence-id')) {
Expand Down
2 changes: 1 addition & 1 deletion test/helper_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ suite('ICAL.helpers', function() {

data = await testSupport.loadSample('timezones/America/Atikokan.ics');
ICAL.TimezoneService.register(
(new ICAL.Component(ICAL.parse(data))).getFirstSubcomponent("vtimezone")
{ component: (new ICAL.Component(ICAL.parse(data))).getFirstSubcomponent("vtimezone") }
);
});

Expand Down
2 changes: 1 addition & 1 deletion test/support/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ testSupport.registerTimezone = async function(zoneName) {
let calendar = new ICAL.Component(parsed);
let vtimezone = calendar.getFirstSubcomponent('vtimezone');

ICAL.TimezoneService.register(vtimezone);
ICAL.TimezoneService.register({ component: vtimezone });
}

if (!this._timezones) {
Expand Down
2 changes: 1 addition & 1 deletion test/time_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ suite('icaltime', function() {
let vtimezone = vcalendar.getFirstSubcomponent('vtimezone');
let tzid = vtimezone.getFirstPropertyValue('tzid');

ICAL.TimezoneService.register(vtimezone);
ICAL.TimezoneService.register({ component: vtimezone });

// utc -5
let time = new ICAL.Time({
Expand Down
12 changes: 6 additions & 6 deletions test/timezone_service_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ suite('timezone_service', function() {

test('#reset', function() {
let name = 'ZFOO';
subject.register(name, ICAL.Timezone.utcTimezone);
subject.register({ name, timezone: ICAL.Timezone.utcTimezone });
assert.isTrue(subject.has(name), 'should have set ' + name);

subject.reset();
Expand All @@ -58,7 +58,7 @@ suite('timezone_service', function() {
assert.isFalse(subject.has(name));

assert.equal(subject.count, 3);
subject.register(name, ICAL.Timezone.localTimezone);
subject.register({ name, timezone: ICAL.Timezone.localTimezone });
assert.equal(subject.count, 4);
assert.isTrue(subject.has(name), 'is present after set');
assert.equal(
Expand All @@ -72,21 +72,21 @@ suite('timezone_service', function() {

test('with invalid type', function() {
assert.throws(function() {
subject.register('zzz', 'fff');
subject.register({ name: 'zzz', component: 'fff' });
}, "timezone must be ICAL.Timezone");
});
test('with only invalid component', function() {
assert.throws(function() {
let comp = new ICAL.Component('vtoaster');
subject.register(comp);
subject.register({ component: comp });
}, "timezone must be ICAL.Timezone");
});

test('override', function() {
// don't do this but you can if you want to shoot
// yourself in the foot.
assert.equal(subject.count, 3);
subject.register('Z', ICAL.Timezone.localTimezone);
subject.register({ name: 'Z', timezone: ICAL.Timezone.localTimezone });

assert.equal(
subject.get('Z'),
Expand All @@ -102,7 +102,7 @@ suite('timezone_service', function() {
let tzid = vtimezone.getFirstPropertyValue('tzid');

assert.equal(subject.count, 3);
subject.register(vtimezone);
subject.register({ component: vtimezone });
assert.equal(subject.count, 4);

assert.isTrue(subject.has(tzid), 'successfully registed with component');
Expand Down

0 comments on commit e40d894

Please sign in to comment.