Skip to content

Commit

Permalink
add sonar 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 62c8b62 commit 76af9bf
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/fixture/index-origin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<meta name="format-detection" content="telephone=no"/>
<title>Internal Hybrid</title>

<!--lib:css-->
<!--endinject-->

<!--application:css-->
<!--endinject-->

<!--lib:js-->
<!--endinject-->

<!--cordova:js-->
<!--endinject-->

<!--application:js-->
<!--endinject-->

<!--template:js-->
<!--endinject-->
</head>

<body class="container">
</body>

</html>
42 changes: 42 additions & 0 deletions test/sonar.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"use strict";

const fs = require('fs');
const path = require('path');
const should = require('should');
const sonar = require('../base/sonar.js');
const template = fs.readFileSync(path.join(__dirname, 'fixture', 'index-origin.html')).toString();

describe('sonar sub module', function () {
it('should return html tag when template valid', function () {
sonar.seekHtmlTag(template).trim().should.equal('<html lang="zh-CN">')
});

it('should return false when template invalid', function () {
sonar.seekHtmlTag('<p class="text-info"></p>').should.be.false;
});

it('should return body tag when template valid', function () {
sonar.seekBodyTag(template).trim().should.equal('<body class="container">')
});

it('should return body tag when template invalid', function () {
sonar.seekBodyTag('<p class="text-info"></p>').should.be.false;
});

it('should return false when bodyTag have nothing class attribution', function () {
sonar.seekClassAttr('<body id="world">').should.be.false;
});

it('should return class name when bodyTag have class attribution', 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');
});
});

0 comments on commit 76af9bf

Please sign in to comment.