summaryrefslogtreecommitdiffstats
path: root/comm/calendar/test/unit/test_extract_parser_service.js
blob: 2118fad16b71ec5b700fe988882a922cc3208de7 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* 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 http://mozilla.org/MPL/2.0/. */

/**
 * Tests for the CalExtractParserService. These are modified versions of the
 * text_extract.js tests, for now.
 */

// This test works with code that is not timezone-aware.
/* eslint-disable no-restricted-syntax */

var { CalExtractParserService } = ChromeUtils.import(
  "resource:///modules/calendar/extract/CalExtractParserService.jsm"
);

let service = new CalExtractParserService();

/**
 * Test the extraction of a start and end time using HOUR am/pm. Note: The
 * service currently only selects event information from one sentence so the
 * event title is not included here for now.
 */
add_task(function test_event_start_end() {
  let now = new Date(2012, 9, 1, 9, 0);
  let content = "We'll meet at 2 pm and discuss until 3 pm.";
  let result = service.extract(content, {
    now,
  });

  info(`Comparing extracted result for string "${content}"...`);
  compareExtractResults(
    result,
    {
      type: "event-guess",
      startTime: {
        type: "meridiem-time",
        year: 2012,
        month: 10,
        day: 1,
        hour: 14,
        minute: 0,
        meridiem: "pm",
      },
      endTime: {
        type: "meridiem-time",
        year: 2012,
        month: 10,
        day: 1,
        hour: 15,
        minute: 0,
        meridiem: "pm",
      },
      priority: 0,
    },
    "result"
  );
});

/**
 * Test the extraction of a start and end time using a meridiem time for start
 * and a duration for the end.
 */
add_task(function test_event_start_duration() {
  let now = new Date(2012, 9, 1, 9, 0);
  let content = "We'll meet at 2 pm and discuss for 30 minutes.";
  let result = service.extract(content, {
    now,
  });
  info(`Comparing extracted result for string "${content}"...`);
  compareExtractResults(
    result,
    {
      type: "event-guess",
      startTime: {
        type: "meridiem-time",
        year: 2012,
        month: 10,
        day: 1,
        hour: 14,
        minute: 0,
        meridiem: "pm",
      },
      endTime: {
        type: "date-time",
        year: 2012,
        month: 10,
        day: 1,
        hour: 14,
        minute: 30,
      },
      priority: 0,
    },
    "result"
  );
});