| 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
123
124
125
 | describe('DocsApp', function() {
  beforeEach(module('docsApp'));
  describe('DocsVersionsCtrl', function() {
    var $scope, ctrl, window, version = '9.8.7';
    beforeEach(function() {
      module(function($provide) {
        $provide.value('NG_VERSIONS',[
          '1.0.0',
          '1.0.1',
          '1.0.2',
          '1.0.3',
          '1.0.4',
          '1.0.5',
          '1.0.6',
          '1.1.0',
          '1.1.1',
          '1.1.2',
          '1.1.3',
          '1.1.4',
          '2.1.3'
        ]);
        $provide.value('$window', window = createMockWindow());
      });
      inject(function($controller, $rootScope) {
        $scope = $rootScope.$new();
        $scope.version = version;
        ctrl = $controller('DocsVersionsCtrl',{
          $scope : $scope,
          $window : window
        });
      });
    });
    it('should have the correct version of angular', function() {
      expect(version).toBe($scope.version);
    });
    it('should order versions in decending order', function() {
      expect($scope.versions.length).toBeGreaterThan(0);
      var one = $scope.versions[0].version;
      var two = $scope.versions[1].version;
      expect(one).toBeGreaterThan(two);
    });
    it('should list unstable versions at the top of the list', function() {
      expect($scope.versions[0].stable).toBe(false);
    });
    it('should list all items below the last stable as stable regardless of version number', function() {
      var limit = $scope.versions.length - 1,
          lastUnstableIndex = 0;
      while(lastUnstableIndex <= limit) {
        if($scope.versions[lastUnstableIndex++].stable) break;
      }
      for(var i=lastUnstableIndex;i<=limit;i++) {
        expect($scope.versions[i].stable).toBe(true);
      }
    });
    describe('changing the URL', function() {
      it('should not support the old < 1.0 docs pages', function() {
        window.location = 'old';
        $scope.versions.unshift({
          stable : true,
          version : '0.9.10'
        });
        $scope.jumpToDocsVersion('0.9.10');
        expect(window.location).toBe('old');
        $scope.versions.unshift({
          stable : true,
          version : '0.10.1'
        });
        $scope.jumpToDocsVersion('0.10.1');
        expect(window.location).toBe('old');
        $scope.jumpToDocsVersion('2.1.3');
        expect(window.location).toBe('http://code.angularjs.org/2.1.3/docs');
      }); 
      it('should jump to the older versions of current docs for version >= 1.0.2', function() {
        $scope.jumpToDocsVersion('1.0.1');
        expect(window.location).toBe('http://code.angularjs.org/1.0.1/docs-1.0.1');
        $scope.jumpToDocsVersion('1.0.2');
        expect(window.location).toBe('http://code.angularjs.org/1.0.2/docs');
        $scope.jumpToDocsVersion('1.1.2');
        expect(window.location).toBe('http://code.angularjs.org/1.1.2/docs');
      });
      it('should use the current docs.angularjs.org page when the selected version is the last stable version', function() {
        $scope.versions = [{
          stable : true,
          title : 'test',
          version : '1.1.1'
        }];
        $scope.jumpToDocsVersion('1.1.1');
        expect(window.location).toBe('http://docs.angularjs.org');
        $scope.versions.unshift({
          stable : true,
          title : 'test2',
          version : '1.2.1'
        });
        $scope.jumpToDocsVersion('1.1.1');
        expect(window.location).toBe('http://code.angularjs.org/1.1.1/docs');
        $scope.jumpToDocsVersion('1.2.1');
        expect(window.location).toBe('http://docs.angularjs.org');
      });
    });
  });
});
 |