aboutsummaryrefslogtreecommitdiffstats
path: root/docs/component-spec/versionJumpSpec.js
diff options
context:
space:
mode:
authorMatias Niemelä2013-06-13 22:37:13 -0400
committerMisko Hevery2013-06-17 22:17:44 -0700
commit46dfb92afd185c93f60ca90a72653f33d7cb18e8 (patch)
tree51862e5793866ffbb34c16e5053376af5932e2c6 /docs/component-spec/versionJumpSpec.js
parentef22968810d555f78d3bbf7b5428757690c8cc70 (diff)
downloadangular.js-46dfb92afd185c93f60ca90a72653f33d7cb18e8.tar.bz2
feat(ngdocs): provide support for user to jump between different versions of the angularjs documentation
Diffstat (limited to 'docs/component-spec/versionJumpSpec.js')
-rw-r--r--docs/component-spec/versionJumpSpec.js125
1 files changed, 125 insertions, 0 deletions
diff --git a/docs/component-spec/versionJumpSpec.js b/docs/component-spec/versionJumpSpec.js
new file mode 100644
index 00000000..d5a54975
--- /dev/null
+++ b/docs/component-spec/versionJumpSpec.js
@@ -0,0 +1,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 = angular.mock.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');
+ });
+
+ });
+ });
+
+});