I recently wrote a Javascript function that times out the user due to being inactive. My current setTimeout is set for 10 sec for testing purposes. After 10 sec a modal is fired that alerts the user that they have been signed out and directs them to sign back in again. I would now like to write a Jasmine test for this function but I don't know where to start. I've read the docs on jasmine.github.io and I'm still lost. Although my function is small there are a lot of moving parts to test.
My code is below. Any help is greatly appreciated.
App.inactivityTime = function () {
var t;
$(document).on('mousemove', resetTimer);
$(document).on('keypress', resetTimer);
$(document).ready(resetTimer);
function logout() {
$.ajax({
url: '/users/sign_out',
type: "DELETE"
}).done(function(){
$('#logoutModal').modal('show');
$('#logoutModal .btn-primary').click(function () {
window.location.href = '/users/sign_in';
});
});
}
function resetTimer() {
clearTimeout(t);
t = setTimeout(logout, 10000);
}
}
$(function() {
if (window.location.pathname !== '/users/sign_in') {
App.inactivityTime();
}
});
Aucun commentaire:
Enregistrer un commentaire