test('it should pop back in if student closes it', function(assert) { assert.expect(5) const done = assert.async() let latestWindow const onFailure = this.spy() const onOpen = this.spy() const onClose = this.spy() const originalOpen = window.open // needed for proper cleanup of windows const openStub = this.stub(window, 'open').callsFake(function() { return (latestWindow = originalOpen.apply(this, arguments)) }) server = sinon.fakeServer.create() server.respondWith('POST', /login/, [401, {}, 'Bad Request']) // a sticky version popup = new LDBLoginPopup({sticky: true}) popup.on('login_failure', onFailure) popup.on('open', onOpen) popup.on('close', onClose) popup.one('open', function(e, document) { $(document) .find('.btn-primary') .click() server.respond() ok(onFailure.calledOnce, 'logged out by passing in bad credentials') defer(() => whnd.close()) popup.one('close', () => // we need to defer because #open will not be called in the close handler defer(function() { ok(onOpen.calledTwice, 'popup popped back in') ok(onClose.calledOnce, 'popup closed') // clean up the dangling window which we don't have a handle to popup.off('close.sticky') latestWindow.close() ok(onClose.calledTwice, 'popup closed for good') done() }) ) }) whnd = popup.exec() ok(onOpen.called, 'popup opened') })
text: I18n.t("#buttons.login", "Login"), 'class': "btn-primary relogin_button button_type_submit", click: function() { quizSubmission.navigatingToRelogin = true; $('#deauthorized_dialog').submit(); } }] }); }; if (ENV.LOCKDOWN_BROWSER) { var ldbLoginPopup; ldbLoginPopup = new LDBLoginPopup(); ldbLoginPopup .on('login_success.take_quiz', function() { $.flashMessage(I18n.t('login_successful', 'Login successful.')); }) .on('login_failure.take_quiz', function() { $.flashError(I18n.t('login_failed', 'Login failed.')); }); showDeauthorizedDialog = _.bind(ldbLoginPopup.exec, ldbLoginPopup); } $(function() { var KC_T = 84; var $timeRunningTimeRemaining = $(".time_running,.time_remaining"); // we'll use this buffer to read our updates, then we won't have to steal // the user's focus or cursor away, and it will still read instantly thanks // to [aria-live="assertive"]!