summaryrefslogtreecommitdiffstats
path: root/comm/calendar/test/unit/test_CalendarFileImporter.js
diff options
context:
space:
mode:
Diffstat (limited to 'comm/calendar/test/unit/test_CalendarFileImporter.js')
-rw-r--r--comm/calendar/test/unit/test_CalendarFileImporter.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/comm/calendar/test/unit/test_CalendarFileImporter.js b/comm/calendar/test/unit/test_CalendarFileImporter.js
new file mode 100644
index 0000000000..358a82942d
--- /dev/null
+++ b/comm/calendar/test/unit/test_CalendarFileImporter.js
@@ -0,0 +1,46 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+
+var { CalendarTestUtils } = ChromeUtils.import(
+ "resource://testing-common/calendar/CalendarTestUtils.jsm"
+);
+var { CalendarFileImporter } = ChromeUtils.import("resource:///modules/CalendarFileImporter.jsm");
+
+/**
+ * Test CalendarFileImporter can import ics file correctly.
+ */
+async function test_importIcsFile() {
+ let importer = new CalendarFileImporter();
+
+ // Parse items from ics file should work.
+ let items = await importer.parseIcsFile(do_get_file("data/import.ics"));
+ equal(items.length, 4);
+
+ // Create a temporary calendar.
+ let calendar = CalendarTestUtils.createCalendar();
+ registerCleanupFunction(() => {
+ CalendarTestUtils.removeCalendar(calendar);
+ });
+
+ // Put items to the temporary calendar should work.
+ await importer.startImport(items, calendar);
+ let result = await calendar.getItemsAsArray(
+ Ci.calICalendar.ITEM_FILTER_ALL_ITEMS,
+ 0,
+ cal.createDateTime("20190101T000000"),
+ cal.createDateTime("20190102T000000")
+ );
+ equal(result.length, 4);
+}
+
+function run_test() {
+ do_get_profile();
+
+ add_test(() => {
+ do_calendar_startup(async () => {
+ await test_importIcsFile();
+ run_next_test();
+ });
+ });
+}