Skip to content

Commit

Permalink
sub module test.
Browse files Browse the repository at this point in the history
  • Loading branch information
huang-xiao-jian committed Jan 21, 2016
1 parent 76af9bf commit 11fa5a3
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ node_modules
.node_repl_history

# Webstorm
.idea
.idea
.DS_Store
6 changes: 4 additions & 2 deletions base/injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ exports.injectAngularApp = injectAngularApp;
* @returns {boolean|string}
*/
function injectManifest(htmlTag, manifest) {
return manifest && manifestRegExp.test(htmlTag) ? htmlTag : htmlTag.replace('>', ' manifest="' + manifest + '">');
if (!manifest) return htmlTag;
return manifestRegExp.test(htmlTag) ? htmlTag : htmlTag.replace('>', ' manifest="' + manifest + '">');
}

/**
Expand Down Expand Up @@ -68,5 +69,6 @@ function injectCordovaClass(bodyTag, platform) {
* @returns {boolean|string}
*/
function injectAngularApp(bodyTag, application) {
return application && applicationRegExp.test(bodyTag) ? bodyTag : bodyTag.replace('>', ' ng-app="' + application + '">');
if (!application) return bodyTag;
return applicationRegExp.test(bodyTag) ? bodyTag : bodyTag.replace('>', ' ng-app="' + application + '">');
}
2 changes: 0 additions & 2 deletions base/sonar.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ function seekClassAttr(bodyTag) {
* @returns {boolean|string}
*/
function seekCordovaClass(platform) {
if (!platform) return 'platform-h5';

const platformClass = 'platform-' + platform;
const cordovaClass = 'platform-cordova platform-webview';

Expand Down
2 changes: 1 addition & 1 deletion package.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"should": "^8.1.1"
},
"scripts": {
"test": "./node_modules/.bin/_mocha --report html",
"test": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report html",
"test-travis": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly"
},
"repository": {
Expand Down
47 changes: 47 additions & 0 deletions test/injector.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"use strict";

const should = require('should');
const injector = require('../base/injector.js');

const baseHtmlTag = '<html lang="zh-CN">';
const extendHtmlTag = '<html lang="zh-CN" manifest="manifest/test.manifest">';
const baseBodyTag = '<body class="container">';
const extendBodyTag = '<body class="container" ng-app="Cloud">';

describe('injector sub module', function () {
it('should inject nothing when platform not specific', function () {
injector.injectCordovaClass(baseBodyTag).should.equal(baseBodyTag);
});

it('should inject platform specific class into body tag with create', function () {
injector.injectCordovaClass('<body>', 'ios').should.equal('<body class="platform-ios platform-cordova platform-webview">')
});

it('should inject platform specific class into body tag with concat', function () {
injector.injectCordovaClass(baseBodyTag, 'ios').should.equal('<body class="container platform-ios platform-cordova platform-webview">')
});

it('should inject manifest into html when manifest valid', function () {
injector.injectManifest(baseHtmlTag, 'manifest/mocha.manifest').should.equal('<html lang="zh-CN" manifest="manifest/mocha.manifest">')
});

it('should inject nothing into html when manifest invalid', function () {
injector.injectManifest(baseHtmlTag).should.equal(baseHtmlTag);
});

it('should inject nothing into html when already exist and manifest valid', function () {
injector.injectManifest(extendHtmlTag, 'manifest/mocha.manifest').should.equal('<html lang="zh-CN" manifest="manifest/test.manifest">')
});

it('should inject application into body when application valid', function () {
injector.injectAngularApp(baseBodyTag, 'Mocha').should.equal('<body class="container" ng-app="Mocha">')
});

it('should inject nothing into body when already exist and application valid', function () {
injector.injectAngularApp(extendBodyTag, 'Mocha').should.equal('<body class="container" ng-app="Cloud">')
});

it('should inject nothing into body when application invalid', function () {
injector.injectAngularApp(baseBodyTag).should.equal(baseBodyTag);
});
});
4 changes: 0 additions & 4 deletions test/sonar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ describe('sonar sub module', function () {
sonar.seekClassAttr('<body class="text-info">').trim().should.equal('class="text-info"')
});

it('should generate h5 class when zero argument', function () {
sonar.seekCordovaClass().trim().should.equal('platform-h5');
});

it('should generate related cordova class', function () {
sonar.seekCordovaClass('ios').trim().should.equal('platform-ios platform-cordova platform-webview');
sonar.seekCordovaClass('android').trim().should.equal('platform-android platform-cordova platform-webview');
Expand Down

0 comments on commit 11fa5a3

Please sign in to comment.