diff --git a/.gitignore b/.gitignore index 32dac46..0a890ca 100644 --- a/.gitignore +++ b/.gitignore @@ -34,4 +34,5 @@ node_modules .node_repl_history # Webstorm -.idea \ No newline at end of file +.idea +.DS_Store \ No newline at end of file diff --git a/base/injector.js b/base/injector.js index a5309d5..c896896 100644 --- a/base/injector.js +++ b/base/injector.js @@ -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 + '">'); } /** @@ -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 + '">'); } \ No newline at end of file diff --git a/base/sonar.js b/base/sonar.js index 16ac490..6f71e72 100644 --- a/base/sonar.js +++ b/base/sonar.js @@ -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'; diff --git a/package.json b/package.json old mode 100644 new mode 100755 index cb02e5c..833dfa4 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/injector.spec.js b/test/injector.spec.js new file mode 100644 index 0000000..2592804 --- /dev/null +++ b/test/injector.spec.js @@ -0,0 +1,47 @@ +"use strict"; + +const should = require('should'); +const injector = require('../base/injector.js'); + +const baseHtmlTag = ''; +const extendHtmlTag = ''; +const baseBodyTag = ''; +const extendBodyTag = ''; + +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('', 'ios').should.equal('') + }); + + it('should inject platform specific class into body tag with concat', function () { + injector.injectCordovaClass(baseBodyTag, 'ios').should.equal('') + }); + + it('should inject manifest into html when manifest valid', function () { + injector.injectManifest(baseHtmlTag, 'manifest/mocha.manifest').should.equal('') + }); + + 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('') + }); + + it('should inject application into body when application valid', function () { + injector.injectAngularApp(baseBodyTag, 'Mocha').should.equal('') + }); + + it('should inject nothing into body when already exist and application valid', function () { + injector.injectAngularApp(extendBodyTag, 'Mocha').should.equal('') + }); + + it('should inject nothing into body when application invalid', function () { + injector.injectAngularApp(baseBodyTag).should.equal(baseBodyTag); + }); +}); \ No newline at end of file diff --git a/test/sonar.spec.js b/test/sonar.spec.js index ded73c6..6644008 100644 --- a/test/sonar.spec.js +++ b/test/sonar.spec.js @@ -31,10 +31,6 @@ describe('sonar sub module', function () { sonar.seekClassAttr('').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');