Просмотр исходного кода

Merge branch 'js-unit-testing'

El RIDO 9 лет назад
Родитель
Сommit
a1881ff49b
3 измененных файлов с 40 добавлено и 3 удалено
  1. 1 1
      .travis.yml
  2. 34 0
      js/test.js
  3. 5 2
      tst/README.md

+ 1 - 1
.travis.yml

@@ -15,7 +15,7 @@ before_script:
   - composer install -n
   - npm install -g mocha
   - cd js
-  - npm install jsverify jsdom jsdom-global
+  - npm install jsverify jsdom@9 jsdom-global@2
   - cd ..
 
 script:

+ 34 - 0
js/test.js

@@ -561,6 +561,40 @@ describe('CryptTool', function () {
 });
 
 describe('Model', function () {
+    describe('getExpirationDefault', function () {
+        before(function () {
+            $.PrivateBin.Model.reset();
+            cleanup();
+        });
+
+        jsc.property(
+            'returns the contents of the element with id "pasteExpiration"',
+            'array asciinestring',
+            'string',
+            'small nat',
+            function (keys, value, key) {
+                keys = keys.map($.PrivateBin.Helper.htmlEntities);
+                value = $.PrivateBin.Helper.htmlEntities(value);
+                var content = keys.length > key ? keys[key] : (keys.length > 0 ? keys[0] : 'null'),
+                    contents = '<select id="pasteExpiration" name="pasteExpiration">';
+                keys.forEach(function(item) {
+                    contents += '<option value="' + item + '"';
+                    if (item === content) {
+                        contents += ' selected="selected"';
+                    }
+                    contents += '>' + value + '</option>';
+                });
+                contents += '</select>';
+                $('body').html(contents);
+                var result = $.PrivateBin.Helper.htmlEntities(
+                    $.PrivateBin.Model.getExpirationDefault()
+                );
+                $.PrivateBin.Model.reset();
+                return content === result;
+            }
+        );
+    });
+
     describe('getPasteId', function () {
         before(function () {
             $.PrivateBin.Model.reset();

+ 5 - 2
tst/README.md

@@ -51,7 +51,7 @@ and jsdom-global locally:
 ```console
 $ npm install -g mocha istanbul
 $ cd PrivateBin/js
-$ npm install jsverify jsdom jsdom-global
+$ npm install jsverify jsdom@9 jsdom-global@2
 ```
 
 Example for Debian and Ubuntu, including steps to allow the current user to
@@ -63,9 +63,12 @@ $ sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
 $ ln -s /usr/bin/nodejs /usr/local/bin/node
 $ npm install -g mocha istanbul
 $ cd PrivateBin/js
-$ npm install jsverify jsdom jsdom-global
+$ npm install jsverify jsdom@9 jsdom-global@2
 ```
 
+Note: If you use a distribution that provides nodeJS >= 6, then you can install
+the latest jsdom and jsdom-global packages and don't need to use @9 and @2.
+
 To run the tests, just change into the `js` directory and run istanbul:
 ```console
 $ cd PrivateBin/js