2017-12-15 14:20:51 +08:00
|
|
|
'use strict';
|
|
|
|
var common = require('../common');
|
|
|
|
|
|
|
|
describe('PasteStatus', function () {
|
|
|
|
describe('createPasteNotification', function () {
|
|
|
|
this.timeout(30000);
|
|
|
|
|
|
|
|
jsc.property(
|
|
|
|
'creates a notification after a successfull paste upload',
|
|
|
|
common.jscSchemas(),
|
|
|
|
jsc.nearray(common.jscA2zString()),
|
|
|
|
jsc.array(common.jscQueryString()),
|
|
|
|
'string',
|
|
|
|
common.jscSchemas(),
|
|
|
|
jsc.nearray(common.jscA2zString()),
|
|
|
|
jsc.array(common.jscQueryString()),
|
|
|
|
function (
|
|
|
|
schema1, address1, query1, fragment1,
|
|
|
|
schema2, address2, query2
|
|
|
|
) {
|
|
|
|
var expected1 = schema1 + '://' + address1.join('') + '/?' +
|
|
|
|
encodeURI(query1.join('').replace(/^&+|&+$/gm,'') + '#' + fragment1),
|
|
|
|
expected2 = schema2 + '://' + address2.join('') + '/?' +
|
2019-06-28 03:37:40 +08:00
|
|
|
encodeURI(query2.join('').replace(/^&+|&+$/gm,'')),
|
2017-12-15 14:20:51 +08:00
|
|
|
clean = jsdom();
|
|
|
|
$('body').html('<div><div id="deletelink"></div><div id="pastelink"></div></div>');
|
|
|
|
$.PrivateBin.PasteStatus.init();
|
|
|
|
$.PrivateBin.PasteStatus.createPasteNotification(expected1, expected2);
|
|
|
|
var result1 = $('#pasteurl')[0].href,
|
|
|
|
result2 = $('#deletelink a')[0].href;
|
|
|
|
clean();
|
2018-01-06 14:17:33 +08:00
|
|
|
return result1 === expected1 && result2 === expected2;
|
2017-12-15 14:20:51 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('showRemainingTime', function () {
|
|
|
|
this.timeout(30000);
|
|
|
|
|
|
|
|
jsc.property(
|
2019-05-15 13:44:03 +08:00
|
|
|
'shows burn after reading message or remaining time v1',
|
2017-12-15 14:20:51 +08:00
|
|
|
'bool',
|
|
|
|
'nat',
|
|
|
|
jsc.nearray(common.jscA2zString()),
|
|
|
|
jsc.nearray(common.jscA2zString()),
|
|
|
|
jsc.nearray(common.jscQueryString()),
|
|
|
|
'string',
|
|
|
|
function (
|
2018-01-06 17:57:54 +08:00
|
|
|
burnafterreading, remainingTime,
|
2017-12-15 14:20:51 +08:00
|
|
|
schema, address, query, fragment
|
|
|
|
) {
|
|
|
|
var clean = jsdom('', {
|
|
|
|
url: schema.join('') + '://' + address.join('') +
|
|
|
|
'/?' + query.join('') + '#' + fragment
|
2018-01-06 14:17:33 +08:00
|
|
|
}),
|
|
|
|
result;
|
2017-12-15 14:20:51 +08:00
|
|
|
$('body').html('<div id="remainingtime" class="hidden"></div>');
|
|
|
|
$.PrivateBin.PasteStatus.init();
|
2019-05-25 19:20:39 +08:00
|
|
|
$.PrivateBin.PasteStatus.showRemainingTime($.PrivateBin.Helper.PasteFactory({'meta': {
|
2017-12-15 14:20:51 +08:00
|
|
|
'burnafterreading': burnafterreading,
|
2019-05-15 13:44:03 +08:00
|
|
|
'remaining_time': remainingTime
|
2019-05-25 19:20:39 +08:00
|
|
|
}}));
|
2019-05-15 13:44:03 +08:00
|
|
|
if (burnafterreading) {
|
|
|
|
result = $('#remainingtime').hasClass('foryoureyesonly') &&
|
|
|
|
!$('#remainingtime').hasClass('hidden');
|
|
|
|
} else if (remainingTime) {
|
|
|
|
result =!$('#remainingtime').hasClass('foryoureyesonly') &&
|
|
|
|
!$('#remainingtime').hasClass('hidden');
|
|
|
|
} else {
|
|
|
|
result = $('#remainingtime').hasClass('hidden') &&
|
|
|
|
!$('#remainingtime').hasClass('foryoureyesonly');
|
|
|
|
}
|
|
|
|
clean();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
jsc.property(
|
|
|
|
'shows burn after reading message or remaining time v2',
|
|
|
|
'bool',
|
|
|
|
'nat',
|
|
|
|
jsc.nearray(common.jscA2zString()),
|
|
|
|
jsc.nearray(common.jscA2zString()),
|
|
|
|
jsc.nearray(common.jscQueryString()),
|
|
|
|
'string',
|
|
|
|
function (
|
|
|
|
burnafterreading, remainingTime,
|
|
|
|
schema, address, query, fragment
|
|
|
|
) {
|
|
|
|
var clean = jsdom('', {
|
|
|
|
url: schema.join('') + '://' + address.join('') +
|
|
|
|
'/?' + query.join('') + '#' + fragment
|
|
|
|
}),
|
|
|
|
result;
|
|
|
|
$('body').html('<div id="remainingtime" class="hidden"></div>');
|
|
|
|
$.PrivateBin.PasteStatus.init();
|
2019-05-25 19:20:39 +08:00
|
|
|
$.PrivateBin.PasteStatus.showRemainingTime($.PrivateBin.Helper.PasteFactory({
|
2019-05-15 13:44:03 +08:00
|
|
|
'adata': [null, null, null, burnafterreading],
|
2019-05-25 19:20:39 +08:00
|
|
|
'v': 2,
|
2019-05-15 13:44:03 +08:00
|
|
|
'meta': {
|
|
|
|
'time_to_live': remainingTime
|
|
|
|
}
|
2019-05-25 19:20:39 +08:00
|
|
|
}));
|
2017-12-15 14:20:51 +08:00
|
|
|
if (burnafterreading) {
|
2018-01-06 14:17:33 +08:00
|
|
|
result = $('#remainingtime').hasClass('foryoureyesonly') &&
|
|
|
|
!$('#remainingtime').hasClass('hidden');
|
2018-01-06 17:57:54 +08:00
|
|
|
} else if (remainingTime) {
|
2018-01-06 14:17:33 +08:00
|
|
|
result =!$('#remainingtime').hasClass('foryoureyesonly') &&
|
|
|
|
!$('#remainingtime').hasClass('hidden');
|
2017-12-15 14:20:51 +08:00
|
|
|
} else {
|
2018-01-06 14:17:33 +08:00
|
|
|
result = $('#remainingtime').hasClass('hidden') &&
|
|
|
|
!$('#remainingtime').hasClass('foryoureyesonly');
|
2017-12-15 14:20:51 +08:00
|
|
|
}
|
|
|
|
clean();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('hideMessages', function () {
|
|
|
|
it(
|
|
|
|
'hides all messages',
|
|
|
|
function() {
|
|
|
|
$('body').html(
|
|
|
|
'<div id="remainingtime"></div><div id="pastesuccess"></div>'
|
|
|
|
);
|
|
|
|
$.PrivateBin.PasteStatus.init();
|
|
|
|
$.PrivateBin.PasteStatus.hideMessages();
|
2018-03-01 13:43:30 +08:00
|
|
|
assert.ok(
|
|
|
|
$('#remainingtime').hasClass('hidden') &&
|
|
|
|
$('#pastesuccess').hasClass('hidden')
|
|
|
|
);
|
2017-12-15 14:20:51 +08:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|