adding unit tests for TopNav.resetInput(), triggering bug described in #682

This commit is contained in:
El RIDO 2021-04-05 12:50:23 +02:00
parent 8864523173
commit 5fd829aa09
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92

View file

@ -317,6 +317,92 @@ describe('TopNav', function () {
); );
}); });
describe('resetInput', function () {
before(function () {
cleanup();
});
it(
'reset inputs to defaults (options off)',
function () {
var results = [];
$('body').html(
'<nav><div id="navbar"><ul><li id="burnafterreadingoption" ' +
'class="hidden"><label><input type="checkbox" ' +
'id="burnafterreading" name="burnafterreading" /> ' +
'Burn after reading</label></li><li id="opendiscussionoption" ' +
'class="hidden"><label><input type="checkbox" ' +
'id="opendiscussion" name="opendiscussion" /> ' +
'Open discussion</label></li></ul></div></nav>'
);
$.PrivateBin.TopNav.init();
results.push(
!$.PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
!$.PrivateBin.TopNav.getOpenDiscussion()
);
$('#burnafterreading').attr('checked', 'checked');
$('#opendiscussion').attr('checked', 'checked');
results.push(
$.PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
$.PrivateBin.TopNav.getOpenDiscussion()
);
$.PrivateBin.TopNav.resetInput();
results.push(
!$.PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
!$.PrivateBin.TopNav.getOpenDiscussion()
);
cleanup();
assert.ok(results.every(element => element));
}
);
it(
'reset inputs to defaults (options on)',
function () {
var results = [];
$('body').html(
'<nav><div id="navbar"><ul><li id="burnafterreadingoption" ' +
'class="hidden"><label><input type="checkbox" ' +
'id="burnafterreading" name="burnafterreading" checked="checked" /> ' +
'Burn after reading</label></li><li id="opendiscussionoption" ' +
'class="hidden"><label><input type="checkbox" ' +
'id="opendiscussion" name="opendiscussion" checked="checked" /> ' +
'Open discussion</label></li></ul></div></nav>'
);
$.PrivateBin.TopNav.init();
results.push(
$.PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
$.PrivateBin.TopNav.getOpenDiscussion()
);
$('#burnafterreading').removeAttr('checked');
$('#opendiscussion').removeAttr('checked');
results.push(
!$.PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
!$.PrivateBin.TopNav.getOpenDiscussion()
);
$.PrivateBin.TopNav.resetInput();
results.push(
$.PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
$.PrivateBin.TopNav.getOpenDiscussion()
);
cleanup();
assert.ok(results.every(element => element));
}
);
});
describe('getExpiration', function () { describe('getExpiration', function () {
before(function () { before(function () {
cleanup(); cleanup();