From e40d8948ae013cc60374af683a532609c209dc88 Mon Sep 17 00:00:00 2001 From: jannikac Date: Tue, 18 Jun 2024 14:41:51 +0200 Subject: [PATCH] fix register function bug and update tests --- lib/ical/timezone_service.js | 2 +- test/design_test.js | 6 +++--- test/event_test.js | 2 +- test/helper_test.js | 2 +- test/support/helper.js | 2 +- test/time_test.js | 2 +- test/timezone_service_test.js | 12 ++++++------ 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/ical/timezone_service.js b/lib/ical/timezone_service.js index 29ca3736..458dab52 100644 --- a/lib/ical/timezone_service.js +++ b/lib/ical/timezone_service.js @@ -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; } } diff --git a/test/design_test.js b/test/design_test.js index dbd411a3..4976fe77 100644 --- a/test/design_test.js +++ b/test/design_test.js @@ -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() { @@ -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'; diff --git a/test/event_test.js b/test/event_test.js index 39b3c755..8432868f 100644 --- a/test/event_test.js +++ b/test/event_test.js @@ -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')) { diff --git a/test/helper_test.js b/test/helper_test.js index 3a3413bf..4fc17976 100644 --- a/test/helper_test.js +++ b/test/helper_test.js @@ -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") } ); }); diff --git a/test/support/helper.js b/test/support/helper.js index 806ef334..bea82cb8 100644 --- a/test/support/helper.js +++ b/test/support/helper.js @@ -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) { diff --git a/test/time_test.js b/test/time_test.js index 3fb59eab..92e2754f 100644 --- a/test/time_test.js +++ b/test/time_test.js @@ -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({ diff --git a/test/timezone_service_test.js b/test/timezone_service_test.js index 8b2adc2c..fd361ae1 100644 --- a/test/timezone_service_test.js +++ b/test/timezone_service_test.js @@ -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(); @@ -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( @@ -72,13 +72,13 @@ 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"); }); @@ -86,7 +86,7 @@ suite('timezone_service', 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'), @@ -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');