فهرست منبع

testing both cases of the logic required for #167

El RIDO 8 سال پیش
والد
کامیت
414693fa90
5فایلهای تغییر یافته به همراه30 افزوده شده و 14 حذف شده
  1. 0 2
      .gitattributes
  2. 6 2
      js/privatebin.js
  3. 22 8
      js/test.js
  4. 1 1
      tpl/bootstrap.php
  5. 1 1
      tpl/page.php

+ 0 - 2
.gitattributes

@@ -2,8 +2,6 @@ doc/ export-ignore
 tst/ export-ignore
 js/.istanbul.yml export-ignore
 js/test.js export-ignore
-js/mocha-3.2.0.js export-ignore
-css/mocha-3.2.0.css export-ignore
 .codeclimate.yml export-ignore
 .csslintrc export-ignore
 .dockerignore export-ignore

+ 6 - 2
js/privatebin.js

@@ -965,10 +965,14 @@ jQuery.PrivateBin = function($, sjcl, Base64, RawDeflate) {
          *
          * @name   UiHelper.mockHistoryChange
          * @function
+         * @param  {string} state   (optional) state to mock
          */
-        me.mockHistoryChange = function()
+        me.mockHistoryChange = function(state)
         {
-            historyChange($.Event('popstate', {originalEvent: new PopStateEvent('popstate', {state: null}), target: window}));
+            if (typeof state === 'undefined') {
+                state = null;
+            }
+            historyChange($.Event('popstate', {originalEvent: new PopStateEvent('popstate', {state: state}), target: window}));
         }
 
         /**

+ 22 - 8
js/test.js

@@ -818,27 +818,41 @@ describe('Model', function () {
 });
 
 describe('UiHelper', function () {
+    // TODO: As per https://github.com/tmpvar/jsdom/issues/1565 there is no navigation support in jsdom, yet.
+    // for now we use a mock function to trigger the event
     describe('historyChange', function () {
         before(function () {
             $.PrivateBin.Helper.reset();
         });
 
-        // TODO: As per https://github.com/tmpvar/jsdom/issues/1565 there is no navigation support in jsdom, yet.
-        // for now we use a mock function to trigger the event
         jsc.property(
-            'returns the URL without query & fragment',
+            'redirects to home, when the state is null',
             jsc.elements(schemas),
             jsc.nearray(jsc.elements(a2zString)),
-            jsc.array(jsc.elements(queryString)),
-            'string',
-            function (schema, address, query, fragment) {
+            function (schema, address) {
                 var expected = schema + '://' + address.join('') + '/',
-                    clean = jsdom('', {url: expected + '?' + query.join('') + '#' + fragment});
+                    clean = jsdom('', {url: expected});
 
                 $.PrivateBin.UiHelper.mockHistoryChange();
                 var result = window.location.href;
                 clean();
-                console.log(expected, result);
+                return expected === result;
+            }
+        );
+
+        jsc.property(
+            'does not redirect to home, when a new paste is created',
+            jsc.elements(schemas),
+            jsc.nearray(jsc.elements(a2zString)),
+            jsc.array(jsc.elements(queryString)),
+            jsc.nearray(jsc.elements(base64String)),
+            function (schema, address, query, fragment) {
+                var expected = schema + '://' + address.join('') + '/' + '?' + query.join('') + '#' + fragment.join(''),
+                    clean = jsdom('', {url: expected});
+
+                $.PrivateBin.UiHelper.mockHistoryChange([{type: 'newpaste'}, '', expected]);
+                var result = window.location.href;
+                clean();
                 return expected === result;
             }
         );

+ 1 - 1
tpl/bootstrap.php

@@ -69,7 +69,7 @@ if ($MARKDOWN):
 <?php
 endif;
 ?>
-		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-08YP16cuZ9x9zHHsPLEnAQU2vD8xXFGD0KYfYZeRkje8hSUhf/j1F1ifWKZCVoZST2XXA1PJjnVHTcKxeWAGNA==" crossorigin="anonymous"></script>
+		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-m9jvM3XYbrYmKTg/UNhGytuBsMQ7t6V/s/IdCUJa0UNH459k4ryJgYc/zVAOjgTddE3KZ7yZ406XJ9Fud1wJbg==" crossorigin="anonymous"></script>
 		<!--[if lt IE 10]>
 		<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
 		<![endif]-->

+ 1 - 1
tpl/page.php

@@ -47,7 +47,7 @@ if ($MARKDOWN):
 <?php
 endif;
 ?>
-		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-08YP16cuZ9x9zHHsPLEnAQU2vD8xXFGD0KYfYZeRkje8hSUhf/j1F1ifWKZCVoZST2XXA1PJjnVHTcKxeWAGNA==" crossorigin="anonymous"></script>
+		<script type="text/javascript" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-m9jvM3XYbrYmKTg/UNhGytuBsMQ7t6V/s/IdCUJa0UNH459k4ryJgYc/zVAOjgTddE3KZ7yZ406XJ9Fud1wJbg==" crossorigin="anonymous"></script>
 		<!--[if lt IE 10]>
 		<style type="text/css">body {padding-left:60px;padding-right:60px;} #ienotice {display:block;} #oldienotice {display:block;}</style>
 		<![endif]-->