summaryrefslogtreecommitdiffstats
path: root/js/build/tests/services/businesslayer/businesslayerSpec.js
blob: 8a5a9c1b275214913a4f15e9779a4895e52aa122 (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
// Generated by CoffeeScript 1.6.3
/*

ownCloud - News

@author Bernhard Posselt
@copyright 2012 Bernhard Posselt dev@bernhard-posselt.com

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
License as published by the Free Software Foundation; either
version 3 of the License, or any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU AFFERO GENERAL PUBLIC LICENSE for more details.

You should have received a copy of the GNU Affero General Public
License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*/


(function() {
  var __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  describe('BusinessLayer', function() {
    var _this = this;
    beforeEach(module('News'));
    beforeEach(inject(function(_BusinessLayer, ActiveFeed, FeedType, ItemModel) {
      var TestBusinessLayer, type;
      _this._BusinessLayer = _BusinessLayer;
      _this.ActiveFeed = ActiveFeed;
      _this.FeedType = FeedType;
      _this.ItemModel = ItemModel;
      type = _this.FeedType.Starred;
      _this.getItemsSpy = jasmine.createSpy('getItems');
      _this.persistence = {
        getItems: _this.getItemsSpy
      };
      TestBusinessLayer = (function(_super) {
        __extends(TestBusinessLayer, _super);

        function TestBusinessLayer(activeFeed, persistence, itemModel) {
          TestBusinessLayer.__super__.constructor.call(this, activeFeed, persistence, itemModel, type);
        }

        return TestBusinessLayer;

      })(_this._BusinessLayer);
      return _this.BusinessLayer = new TestBusinessLayer(_this.ActiveFeed, _this.persistence, _this.ItemModel);
    }));
    it('should reset the item cache when a different feed is being loaded', function() {
      _this.ItemModel.clear = jasmine.createSpy('clear');
      _this.ActiveFeed.handle({
        id: 0,
        type: _this.FeedType.Starred
      });
      _this.BusinessLayer.load(2);
      expect(_this.ItemModel.clear).toHaveBeenCalled();
      _this.ActiveFeed.handle({
        id: 2,
        type: _this.FeedType.Feed
      });
      _this.BusinessLayer.load(2);
      return expect(_this.ItemModel.clear).toHaveBeenCalled();
    });
    it('should send a get all items query when feed changed', function() {
      _this.persistence.getItems = jasmine.createSpy('latest');
      _this.ActiveFeed.handle({
        id: 3,
        type: _this.FeedType.Feed
      });
      _this.BusinessLayer.load(3);
      return expect(_this.persistence.getItems).toHaveBeenCalledWith(_this.FeedType.Starred, 3, 0);
    });
    return it('should be active when its selected', function() {
      expect(_this.BusinessLayer.isActive(0)).toBe(false);
      _this.ActiveFeed.handle({
        type: _this.FeedType.Starred,
        id: 0
      });
      return expect(_this.BusinessLayer.isActive(0)).toBe(true);
    });
  });

}).call(this);