From e337aa660fe9a2564440ca8899531b6a93e89bed Mon Sep 17 00:00:00 2001 From: Shaoquan Chen Date: Mon, 24 Aug 2015 20:50:41 -0700 Subject: [PATCH] Moving inline html code out of login.spec.js Currently there are some html code for test hard-coded inside of spec.js file. It would be much better to move them out to separate html file for better readability, cleaner spec code. This will also enable the sharing html mock code between specs. This is possible due to the new auto-file- colleting mechanism. This patch moves inline html code out of login.spec.js. Change-Id: Idf72de61c44e4b4c8ddbb8ed995beddf6f1c6419 Closes-Bug: #1485134 --- horizon/static/auth/login/login.module.js | 20 +++++++++- .../static/auth/login/login.module.spec.js | 37 +++++++++++++++++++ .../static/auth/login/login.regular.mock.html | 7 ++++ horizon/static/auth/login/login.spec.js | 34 ++++------------- .../static/auth/login/login.websso.mock.html | 13 +++++++ 5 files changed, 84 insertions(+), 27 deletions(-) create mode 100644 horizon/static/auth/login/login.module.spec.js create mode 100644 horizon/static/auth/login/login.regular.mock.html create mode 100644 horizon/static/auth/login/login.websso.mock.html diff --git a/horizon/static/auth/login/login.module.js b/horizon/static/auth/login/login.module.js index f205df02f8..eb38419a58 100644 --- a/horizon/static/auth/login/login.module.js +++ b/horizon/static/auth/login/login.module.js @@ -16,6 +16,24 @@ (function () { 'use strict'; - angular.module('horizon.auth.login', []); + angular + .module('horizon.auth.login', [], config); + + config.$inject = [ + '$provide', + '$windowProvider' + ]; + + /** + * @description + * + * In the config function: + * - define constant `horizon.auth.login.basePath` as the + * base path for auth login code. + */ + function config($provide, $windowProvider) { + var path = $windowProvider.$get().STATIC_URL + 'auth/login/'; + $provide.constant('horizon.auth.login.basePath', path); + } })(); diff --git a/horizon/static/auth/login/login.module.spec.js b/horizon/static/auth/login/login.module.spec.js new file mode 100644 index 0000000000..c237bdac59 --- /dev/null +++ b/horizon/static/auth/login/login.module.spec.js @@ -0,0 +1,37 @@ +/* + * (c) Copyright 2015 Hewlett-Packard Development Company, L.P. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +(function () { + 'use strict'; + + describe('horizon.auth.login module', function () { + it('should be defined', function () { + expect(angular.module('horizon.auth.login')).toBeDefined(); + }); + }); + + describe('horizon.auth.login.basePath', function () { + beforeEach(module('horizon.auth.login')); + + it('should be defined and set correctly', inject([ + 'horizon.auth.login.basePath', '$window', + function (basePath, $window) { + expect(basePath).toBeDefined(); + expect(basePath).toBe($window.STATIC_URL + 'auth/login/'); + }]) + ); + }); + +})(); diff --git a/horizon/static/auth/login/login.regular.mock.html b/horizon/static/auth/login/login.regular.mock.html new file mode 100644 index 0000000000..3ab996e4e8 --- /dev/null +++ b/horizon/static/auth/login/login.regular.mock.html @@ -0,0 +1,7 @@ +
+

Some help text.

+
+
+
+
+
diff --git a/horizon/static/auth/login/login.spec.js b/horizon/static/auth/login/login.spec.js index f20825fb4b..763808ffe7 100644 --- a/horizon/static/auth/login/login.spec.js +++ b/horizon/static/auth/login/login.spec.js @@ -19,37 +19,19 @@ describe('hzLoginFinder', function() { - var $compile, $rootScope, $timeout; - - var webssoMarkup = - '
' + - '

Some help text.

' + - '
' + - '
' + - '' + - '
' + - '
' + - '
' + - '
' + - '
'; - - var regularMarkup = - '
' + - '

Some help text.

' + - '
' + - '
' + - '
' + - '
' + - '
'; + var $compile, $rootScope, $timeout, webssoMarkup, regularMarkup; + beforeEach(module('templates')); beforeEach(module('horizon.auth.login')); - beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_) { + beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_, $injector) { $compile = _$compile_; $rootScope = _$rootScope_; $timeout = _$timeout_; + var $templateCache = $injector.get('$templateCache'); + var basePath = $injector.get('horizon.auth.login.basePath'); + + webssoMarkup = $templateCache.get(basePath + 'login.websso.mock.html'); + regularMarkup = $templateCache.get(basePath + 'login.regular.mock.html'); jasmine.addMatchers({ // jquery show is not consistent across different browsers diff --git a/horizon/static/auth/login/login.websso.mock.html b/horizon/static/auth/login/login.websso.mock.html new file mode 100644 index 0000000000..277474d930 --- /dev/null +++ b/horizon/static/auth/login/login.websso.mock.html @@ -0,0 +1,13 @@ +
+

Some help text.

+
+
+ +
+
+
+
+