aboutsummaryrefslogtreecommitdiffstats
path: root/test/caldav/resources/calendar_test.js
blob: d7689c0af247b3d1d9c91892a2b916f550e4f71d (plain) (blame)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
requireRequest();

testSupport.lib('request/calendar_query');

testSupport.lib('resources/calendar'),
testSupport.lib('xhr');
testSupport.lib('connection');

suite('caldav/resources/calendar', function() {

  var Calendar;
  var Connection;
  var CalendarQuery;
  var con;
  var url = 'foobar.com';
  var subject;

  suiteSetup(function() {
    Calendar = Caldav.require('resources/calendar');
    Connection = Caldav.require('connection');
    CalendarQuery = Caldav.require('request/calendar_query');
  });

  setup(function() {
    con = new Connection();
    subject = new Calendar(con, {
      url: url
    });
  });

  suite('initialization', function() {

    test('without calendar data', function() {
      assert.equal(subject.url, url);
      assert.equal(subject.connection, con);
    });

    test('with calendar data', function() {
      return;
      var calledWith, data = { value: 'wow'};
      subject.updateFromServer = function() {
        calledWith = arguments;
      }

      subject.constructor.call(this, con, data);

      assert.equal(calledWith[0], data);
    });

  });

  suite('#createQuery', function() {

    var result;

    setup(function() {
      result = subject.createQuery();
    });

    test('result', function() {
      assert.instanceOf(result, CalendarQuery);
      assert.equal(result.url, url);
    });
  });

  suite('#updateFromServer', function() {

    function status(value, status) {
      if (typeof(status) === 'undefined') {
        status = '200';
      }

      return { status: status, value: value };
    }

    var input = {
      displayname: status('name'),
      'calendar-color': status('#FFF'),
      'calendar-description': status('desc'),
      'getctag': status('17'),
      'resourcetype': status(['calendar']),
      'current-user-privilege-set': status(null, 404)
    };

    var expected = {
      name: 'name',
      color: '#FFF',
      description: 'desc',
      ctag: '17',
      resourcetype: ['calendar'],
      privilegeSet: []
    };

    test('full set', function() {
      var key;
      subject.updateFromServer(input);

      for (key in expected) {
        if (expected.hasOwnProperty(key)) {
          assert.deepEqual(
            subject[key], expected[key],
            key + ' was not set'
          );
        }
      }
    });

    test('partial update', function() {
      subject.updateFromServer(input);
      subject.updateFromServer({
        'calendar-description': status('baz')
      });

      assert.equal(subject.color, '#FFF', 'should not clear old values');
      assert.equal(subject.description, 'baz');
    });

  });



});