summaryrefslogtreecommitdiffstats
path: root/comm/calendar/test/unit/test_CalendarFileImporter.js
blob: 358a82942d3927c0f3501b817784101003694d9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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();
    });
  });
}