aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/test/unit/recent-history.spec.js
blob: 5eff7a83d6678fd00c4f6a6833bec20bdcdb8f76 (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
define(function (require) {
  var bdd = require('intern!bdd');
  var assert = require('intern/chai!assert');

  var RecentHistory = require('../../build/js/libs/recent-history');

  bdd.describe('RecentHistory', function () {
    bdd.beforeEach(function () {
      RecentHistory.clear();
    });

    bdd.it('should clear history', function () {
      assert.equal(RecentHistory.getRecentHistory().length, 0);
      RecentHistory.add('project-key', 'Project Name', 'trk');
      assert.equal(RecentHistory.getRecentHistory().length, 1);
      RecentHistory.clear();
      assert.equal(RecentHistory.getRecentHistory().length, 0);
    });

    bdd.it('should add a new item', function () {
      RecentHistory.add('project-key', 'Project Name', 'trk');
      assert.deepEqual(RecentHistory.getRecentHistory(), [{ key: 'project-key', name: 'Project Name', icon: 'trk' }]);
    });

    bdd.it('should replace existing item', function () {
      RecentHistory.add('project-key', 'Project Name', 'trk');
      assert.deepEqual(RecentHistory.getRecentHistory(), [{ key: 'project-key', name: 'Project Name', icon: 'trk' }]);
      RecentHistory.add('project-key', 'Another', 'brc');
      assert.deepEqual(RecentHistory.getRecentHistory(), [{ key: 'project-key', name: 'Another', icon: 'brc' }]);
    });

    bdd.it('should limit the number of items', function () {
      assert.equal(RecentHistory.getRecentHistory().length, 0);
      for (var i = 0; i < 10; i++) {
        RecentHistory.add('key-' + i, 'Project ' + i, 'trk');
      }
      assert.equal(RecentHistory.getRecentHistory().length, 10);
      RecentHistory.add('project-key', 'Project Name', 'trk');
      assert.equal(RecentHistory.getRecentHistory().length, 10);
      assert.deepEqual(RecentHistory.getRecentHistory()[0], { key: 'project-key', name: 'Project Name', icon: 'trk' });
    });
  });
});