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
This commit is contained in:
Shaoquan Chen 2015-08-24 20:50:41 -07:00
parent 9ee1106472
commit e337aa660f
5 changed files with 84 additions and 27 deletions

View File

@ -16,6 +16,24 @@
(function () { (function () {
'use strict'; '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);
}
})(); })();

View File

@ -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/');
}])
);
});
})();

View File

@ -0,0 +1,7 @@
<form>
<p id="help_text">Some help text.</p>
<fieldset hz-login-finder>
<div class="form-group"><input id="id_username"></div>
<div class="form-group"><input id="id_password"></div>
</fieldset>
</form>

View File

@ -19,37 +19,19 @@
describe('hzLoginFinder', function() { describe('hzLoginFinder', function() {
var $compile, $rootScope, $timeout; var $compile, $rootScope, $timeout, webssoMarkup, regularMarkup;
var webssoMarkup =
'<form>' +
'<p id="help_text">Some help text.</p>' +
'<fieldset hz-login-finder>' +
'<div>' +
'<select id="id_auth_type">' +
'<option value="credentials">Credentials</option>' +
'<option value="oidc">OpenID Connect</option>' +
'</select>' +
'</div>' +
'<div class="form-group"><input id="id_username"></div>' +
'<div class="form-group"><input id="id_password"></div>' +
'</fieldset>' +
'</form>';
var regularMarkup =
'<form>' +
'<p id="help_text">Some help text.</p>' +
'<fieldset hz-login-finder>' +
'<div class="form-group"><input id="id_username"></div>' +
'<div class="form-group"><input id="id_password"></div>' +
'</fieldset>' +
'</form>';
beforeEach(module('templates'));
beforeEach(module('horizon.auth.login')); beforeEach(module('horizon.auth.login'));
beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_) { beforeEach(inject(function(_$compile_, _$rootScope_, _$timeout_, $injector) {
$compile = _$compile_; $compile = _$compile_;
$rootScope = _$rootScope_; $rootScope = _$rootScope_;
$timeout = _$timeout_; $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({ jasmine.addMatchers({
// jquery show is not consistent across different browsers // jquery show is not consistent across different browsers

View File

@ -0,0 +1,13 @@
<form>
<p id="help_text">Some help text.</p>
<fieldset hz-login-finder>
<div>
<select id="id_auth_type">
<option value="credentials">Credentials</option>
<option value="oidc">OpenID Connect</option>
</select>
</div>
<div class="form-group"><input id="id_username"></div>
<div class="form-group"><input id="id_password"></div>
</fieldset>
</form>