Skip to content

Commit

Permalink
Session Timeout: Fixed the async portions of the test
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentGoderre committed Oct 14, 2014
1 parent 020aa33 commit bc3af46
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/plugins/session-timeout/test.js
Expand Up @@ -19,7 +19,8 @@ describe( "Session Timeout test suite", function() {
var clock, server, $session,
spies = {},
sandbox = sinon.sandbox.create(),
$document = wb.doc;
$document = wb.doc,
callback;

this.timeout(5000);

Expand All @@ -32,30 +33,27 @@ describe( "Session Timeout test suite", function() {
spies.trigger = sandbox.spy( $.prototype, "trigger" );
spies.post = sandbox.spy( $, "post" );

$document.on( "wb-ready.wb-sessto", ".wb-sessto", function() {
done();
});
callback = done;

$document.on( "inactivity.wb-sessto", function() {
$( ".wb-sessto-confirm.btn-primary" ).trigger( "click" );
});

// Inject the test element after the Modernizr.load calls in wb.js
// have finished. This is required because the session timeout
// plugin relies on the i18n libraries being loaded.

$document.one( "wb-ready.wb timerpoke.wb", function() {
$session = $( "<span class='wb-sessto'></span>" )
.data( "wet-boew", {
inactivity: 10000,
sessionalive: 10000,
refreshLimit: 42000,
refreshOnClick: true
})
.appendTo( $document.find( "body" ))
.trigger( "wb-init.wb-sessto" );
});

$document.on( "wb-ready.wb-sessto", ".wb-sessto", function() {
if ( callback ) {
callback();
}
});

$session = $( "<span class='wb-sessto'></span>" )
.data( "wet-boew", {
inactivity: 10000,
sessionalive: 10000,
refreshLimit: 42000,
refreshOnClick: true
})
.appendTo( $document.find( "body" ))
.trigger( "wb-init.wb-sessto" );
});

/*
Expand All @@ -64,6 +62,7 @@ describe( "Session Timeout test suite", function() {
after(function() {
// Cleanup the test element
$session.remove();
$( "#wb-sessto-modal" ).remove();

// Restore the original behaviour of spies, server and timer
sandbox.restore();
Expand Down Expand Up @@ -175,14 +174,15 @@ describe( "Session Timeout test suite", function() {

describe( "refreshCallbackUrl", function() {

before(function() {
before(function( done ) {
// Setup the fake server response for all POST requests to foo.html
server = sandbox.useFakeServer();
server.respondWith( "POST", "foo.html", "true" );

callback = done;

// Add the session timeout element and trigger it's init'
$session = $( ".wb-sessto" )
.data( "wet-boew", {
$session.data( "wet-boew", {
sessionalive: 5000,
refreshCallbackUrl: "foo.html"
})
Expand Down

0 comments on commit bc3af46

Please sign in to comment.