mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-11-28 10:10:37 -05:00
improve JS unit test readability & error reporting
This commit is contained in:
parent
06e95a0911
commit
e853a934ea
5 changed files with 97 additions and 39 deletions
|
|
@ -306,10 +306,8 @@ describe('Alert', function () {
|
||||||
$('body').addClass('loading');
|
$('body').addClass('loading');
|
||||||
$.PrivateBin.Alert.init();
|
$.PrivateBin.Alert.init();
|
||||||
$.PrivateBin.Alert.hideLoading();
|
$.PrivateBin.Alert.hideLoading();
|
||||||
assert.ok(
|
assert.ok(!$('body').hasClass('loading'));
|
||||||
!$('body').hasClass('loading') &&
|
assert.ok($('#loadingindicator').hasClass('hidden'));
|
||||||
$('#loadingindicator').hasClass('hidden')
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -328,10 +326,8 @@ describe('Alert', function () {
|
||||||
);
|
);
|
||||||
$.PrivateBin.Alert.init();
|
$.PrivateBin.Alert.init();
|
||||||
$.PrivateBin.Alert.hideMessages();
|
$.PrivateBin.Alert.hideMessages();
|
||||||
assert.ok(
|
assert.ok($('#status').hasClass('hidden'));
|
||||||
$('#status').hasClass('hidden') &&
|
assert.ok($('#errormessage').hasClass('hidden'));
|
||||||
$('#errormessage').hasClass('hidden')
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -381,4 +377,3 @@ describe('Alert', function () {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,9 +58,10 @@ describe('CryptTool', function () {
|
||||||
'foo', 'bar', cipherMessage
|
'foo', 'bar', cipherMessage
|
||||||
);
|
);
|
||||||
clean();
|
clean();
|
||||||
const result = (message === plaintext);
|
if (message !== plaintext) {
|
||||||
if (!result) console.log(plaintext, cipherMessage);
|
console.log(plaintext, cipherMessage);
|
||||||
assert.ok(result);
|
}
|
||||||
|
assert.strictEqual(message, plaintext);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can en- and decrypt a particular message (#260)', function () {
|
it('can en- and decrypt a particular message (#260)', function () {
|
||||||
|
|
|
||||||
|
|
@ -217,10 +217,8 @@ describe('PasteStatus', function () {
|
||||||
);
|
);
|
||||||
$.PrivateBin.PasteStatus.init();
|
$.PrivateBin.PasteStatus.init();
|
||||||
$.PrivateBin.PasteStatus.hideMessages();
|
$.PrivateBin.PasteStatus.hideMessages();
|
||||||
assert.ok(
|
assert.ok($('#remainingtime').hasClass('hidden'));
|
||||||
$('#remainingtime').hasClass('hidden') &&
|
assert.ok($('#pastesuccess').hasClass('hidden'));
|
||||||
$('#pastesuccess').hasClass('hidden')
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,11 @@ describe('TopNav', function () {
|
||||||
$('#qrcodelink').hasClass('hidden')
|
$('#qrcodelink').hasClass('hidden')
|
||||||
);
|
);
|
||||||
cleanup();
|
cleanup();
|
||||||
assert.ok(results.every(element => element));
|
const result = results.every(element => element);
|
||||||
|
if (!result) {
|
||||||
|
console.log(results);
|
||||||
|
}
|
||||||
|
assert.ok(result);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -113,7 +117,11 @@ describe('TopNav', function () {
|
||||||
$('#attach').hasClass('hidden')
|
$('#attach').hasClass('hidden')
|
||||||
);
|
);
|
||||||
cleanup();
|
cleanup();
|
||||||
assert.ok(results.every(element => element));
|
const result = results.every(element => element);
|
||||||
|
if (!result) {
|
||||||
|
console.log(results);
|
||||||
|
}
|
||||||
|
assert.ok(result);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -140,7 +148,11 @@ describe('TopNav', function () {
|
||||||
!$('#newbutton').hasClass('hidden')
|
!$('#newbutton').hasClass('hidden')
|
||||||
);
|
);
|
||||||
cleanup();
|
cleanup();
|
||||||
assert.ok(results.every(element => element));
|
const result = results.every(element => element);
|
||||||
|
if (!result) {
|
||||||
|
console.log(results);
|
||||||
|
}
|
||||||
|
assert.ok(result);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -169,7 +181,11 @@ describe('TopNav', function () {
|
||||||
$('#clonebutton').hasClass('hidden')
|
$('#clonebutton').hasClass('hidden')
|
||||||
);
|
);
|
||||||
cleanup();
|
cleanup();
|
||||||
assert.ok(results.every(element => element));
|
const result = results.every(element => element);
|
||||||
|
if (!result) {
|
||||||
|
console.log(results);
|
||||||
|
}
|
||||||
|
assert.ok(result);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -199,7 +215,11 @@ describe('TopNav', function () {
|
||||||
$('#rawtextbutton').hasClass('hidden')
|
$('#rawtextbutton').hasClass('hidden')
|
||||||
);
|
);
|
||||||
cleanup();
|
cleanup();
|
||||||
assert.ok(results.every(element => element));
|
const result = results.every(element => element);
|
||||||
|
if (!result) {
|
||||||
|
console.log(results);
|
||||||
|
}
|
||||||
|
assert.ok(result);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -233,7 +253,11 @@ describe('TopNav', function () {
|
||||||
$('#filewrap').hasClass('hidden')
|
$('#filewrap').hasClass('hidden')
|
||||||
);
|
);
|
||||||
cleanup();
|
cleanup();
|
||||||
assert.ok(results.every(element => element));
|
const result = results.every(element => element);
|
||||||
|
if (!result) {
|
||||||
|
console.log(results);
|
||||||
|
}
|
||||||
|
assert.ok(result);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -267,7 +291,11 @@ describe('TopNav', function () {
|
||||||
!$('#customattachment').hasClass('hidden')
|
!$('#customattachment').hasClass('hidden')
|
||||||
);
|
);
|
||||||
cleanup();
|
cleanup();
|
||||||
assert.ok(results.every(element => element));
|
const result = results.every(element => element);
|
||||||
|
if (!result) {
|
||||||
|
console.log(results);
|
||||||
|
}
|
||||||
|
assert.ok(result);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -318,7 +346,11 @@ describe('TopNav', function () {
|
||||||
);
|
);
|
||||||
*/
|
*/
|
||||||
clean();
|
clean();
|
||||||
assert.ok(results.every(element => element));
|
const result = results.every(element => element);
|
||||||
|
if (!result) {
|
||||||
|
console.log(results);
|
||||||
|
}
|
||||||
|
assert.ok(result);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -364,7 +396,11 @@ describe('TopNav', function () {
|
||||||
!$.PrivateBin.TopNav.getOpenDiscussion()
|
!$.PrivateBin.TopNav.getOpenDiscussion()
|
||||||
);
|
);
|
||||||
cleanup();
|
cleanup();
|
||||||
assert.ok(results.every(element => element));
|
const result = results.every(element => element);
|
||||||
|
if (!result) {
|
||||||
|
console.log(results);
|
||||||
|
}
|
||||||
|
assert.ok(result);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -403,7 +439,11 @@ describe('TopNav', function () {
|
||||||
!$.PrivateBin.TopNav.getOpenDiscussion()
|
!$.PrivateBin.TopNav.getOpenDiscussion()
|
||||||
);
|
);
|
||||||
cleanup();
|
cleanup();
|
||||||
assert.ok(results.every(element => element));
|
const result = results.every(element => element);
|
||||||
|
if (!result) {
|
||||||
|
console.log(results);
|
||||||
|
}
|
||||||
|
assert.ok(result);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -443,7 +483,11 @@ describe('TopNav', function () {
|
||||||
$.PrivateBin.TopNav.getOpenDiscussion()
|
$.PrivateBin.TopNav.getOpenDiscussion()
|
||||||
);
|
);
|
||||||
cleanup();
|
cleanup();
|
||||||
assert.ok(results.every(element => element));
|
const result = results.every(element => element);
|
||||||
|
if (!result) {
|
||||||
|
console.log(results);
|
||||||
|
}
|
||||||
|
assert.ok(result);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -462,7 +506,7 @@ describe('TopNav', function () {
|
||||||
'<option value="never">Never</option></select>'
|
'<option value="never">Never</option></select>'
|
||||||
);
|
);
|
||||||
$.PrivateBin.TopNav.init();
|
$.PrivateBin.TopNav.init();
|
||||||
assert.ok($.PrivateBin.TopNav.getExpiration() === '1day');
|
assert.strictEqual($.PrivateBin.TopNav.getExpiration(), '1day');
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
@ -541,7 +585,11 @@ describe('TopNav', function () {
|
||||||
files[1].name === 'busy.gif'
|
files[1].name === 'busy.gif'
|
||||||
);
|
);
|
||||||
cleanup();
|
cleanup();
|
||||||
assert.ok(results.every(element => element));
|
const result = results.every(element => element);
|
||||||
|
if (!result) {
|
||||||
|
console.log(results);
|
||||||
|
}
|
||||||
|
assert.ok(result);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -574,7 +622,11 @@ describe('TopNav', function () {
|
||||||
!$.PrivateBin.TopNav.getBurnAfterReading()
|
!$.PrivateBin.TopNav.getBurnAfterReading()
|
||||||
);
|
);
|
||||||
cleanup();
|
cleanup();
|
||||||
assert.ok(results.every(element => element));
|
const result = results.every(element => element);
|
||||||
|
if (!result) {
|
||||||
|
console.log(results);
|
||||||
|
}
|
||||||
|
assert.ok(result);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -607,7 +659,11 @@ describe('TopNav', function () {
|
||||||
!$.PrivateBin.TopNav.getOpenDiscussion()
|
!$.PrivateBin.TopNav.getOpenDiscussion()
|
||||||
);
|
);
|
||||||
cleanup();
|
cleanup();
|
||||||
assert.ok(results.every(element => element));
|
const result = results.every(element => element);
|
||||||
|
if (!result) {
|
||||||
|
console.log(results);
|
||||||
|
}
|
||||||
|
assert.ok(result);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -642,7 +698,11 @@ describe('TopNav', function () {
|
||||||
$.PrivateBin.TopNav.getPassword() === ''
|
$.PrivateBin.TopNav.getPassword() === ''
|
||||||
);
|
);
|
||||||
cleanup();
|
cleanup();
|
||||||
return results.every(element => element);
|
const result = results.every(element => element);
|
||||||
|
if (!result) {
|
||||||
|
console.log(results);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -676,7 +736,11 @@ describe('TopNav', function () {
|
||||||
$.PrivateBin.TopNav.getCustomAttachment().hasClass('test')
|
$.PrivateBin.TopNav.getCustomAttachment().hasClass('test')
|
||||||
);
|
);
|
||||||
cleanup();
|
cleanup();
|
||||||
assert.ok(results.every(element => element));
|
const result = results.every(element => element);
|
||||||
|
if (!result) {
|
||||||
|
console.log(results);
|
||||||
|
}
|
||||||
|
assert.ok(result);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -738,7 +802,7 @@ describe('TopNav', function () {
|
||||||
$.PrivateBin.Helper.reset();
|
$.PrivateBin.Helper.reset();
|
||||||
$.PrivateBin.TopNav.init();
|
$.PrivateBin.TopNav.init();
|
||||||
$('#rawtextbutton').click();
|
$('#rawtextbutton').click();
|
||||||
assert.equal($('pre').text(), sample);
|
assert.strictEqual($('pre').text(), sample);
|
||||||
clean();
|
clean();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ function stubWinOpen($element) {
|
||||||
|
|
||||||
// Extract and decode the body from a "mailto:?body=..." URL.
|
// Extract and decode the body from a "mailto:?body=..." URL.
|
||||||
function extractMailtoBody(mailtoUrl) {
|
function extractMailtoBody(mailtoUrl) {
|
||||||
assert.ok(/^mailto:\?body=/.test(mailtoUrl), 'expected a mailto:?body= URL');
|
assert.match(mailtoUrl, /^mailto:\?body=/, 'expected a mailto:?body= URL');
|
||||||
return decodeURIComponent(mailtoUrl.replace(/^mailto:\?body=/, ''));
|
return decodeURIComponent(mailtoUrl.replace(/^mailto:\?body=/, ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,8 +104,8 @@ describe('Email - mail body content (short URL vs. fallback)', function () {
|
||||||
assert.ok(openedUrl, 'window.open should have been called');
|
assert.ok(openedUrl, 'window.open should have been called');
|
||||||
|
|
||||||
const body = extractMailtoBody(openedUrl);
|
const body = extractMailtoBody(openedUrl);
|
||||||
assert.ok(body.includes('https://short.example/xYz'), 'email body should include the short URL');
|
assert.match(body, /https:\/\/short\.example\/xYz/, 'email body should include the short URL');
|
||||||
assert.ok(!body.includes('undefined'), 'email body must not contain "undefined"');
|
assert.doesNotMatch(body, /undefined/, 'email body must not contain "undefined"');
|
||||||
} finally {
|
} finally {
|
||||||
restore();
|
restore();
|
||||||
cleanup();
|
cleanup();
|
||||||
|
|
@ -127,8 +127,8 @@ describe('Email - mail body content (short URL vs. fallback)', function () {
|
||||||
assert.ok(openedUrl, 'window.open should have been called');
|
assert.ok(openedUrl, 'window.open should have been called');
|
||||||
|
|
||||||
const body = extractMailtoBody(openedUrl);
|
const body = extractMailtoBody(openedUrl);
|
||||||
assert.ok(body.includes(win.location.href), 'email body should include the fallback page URL');
|
assert.match(body, new RegExp(win.location.href), 'email body should include the fallback page URL');
|
||||||
assert.ok(!body.includes('undefined'), 'email body must not contain "undefined"');
|
assert.doesNotMatch(body, /undefined/, 'email body must not contain "undefined"');
|
||||||
} finally {
|
} finally {
|
||||||
restore();
|
restore();
|
||||||
cleanup();
|
cleanup();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue