mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
feat: Refine clear local storage function
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
describe('Auth Controller', function() {
|
||||
var scope, ctrl, user, $httpBackend, $window;
|
||||
var scope, ctrl, user, $httpBackend, $window, $modal;
|
||||
|
||||
beforeEach(function(){
|
||||
module(function($provide) {
|
||||
@@ -9,12 +9,13 @@ describe('Auth Controller', function() {
|
||||
$provide.value('Chat', { seenMessage: function() {} });
|
||||
});
|
||||
|
||||
inject(function(_$httpBackend_, $rootScope, $controller) {
|
||||
inject(function(_$httpBackend_, $rootScope, $controller, _$modal_) {
|
||||
$httpBackend = _$httpBackend_;
|
||||
scope = $rootScope.$new();
|
||||
scope.loginUsername = 'user';
|
||||
scope.loginPassword = 'pass';
|
||||
$window = { location: { href: ""}, alert: sandbox.spy() };
|
||||
$modal = _$modal_;
|
||||
user = { user: {}, authenticate: sandbox.spy() };
|
||||
|
||||
ctrl = $controller('AuthCtrl', {$scope: scope, $window: $window, User: user});
|
||||
@@ -39,4 +40,82 @@ describe('Auth Controller', function() {
|
||||
expect($window.alert).to.be.calledOnce;
|
||||
});
|
||||
});
|
||||
|
||||
describe.only('#clearLocalStorage', function () {
|
||||
var timer;
|
||||
|
||||
beforeEach(function () {
|
||||
timer = sandbox.useFakeTimers();
|
||||
sandbox.stub($modal, 'open');
|
||||
});
|
||||
|
||||
it('opens modal with message about clearing local storage and logging out', function () {
|
||||
scope.clearLocalStorage();
|
||||
|
||||
expect($modal.open).to.be.calledOnce;
|
||||
expect($modal.open).to.be.calledWith({
|
||||
templateUrl: 'modals/message-modal.html',
|
||||
scope: scope
|
||||
});
|
||||
|
||||
expect(scope.messageModal.title).to.eql(window.env.t('localStorageClearing'));
|
||||
expect(scope.messageModal.body).to.eql(window.env.t('localStorageClearingExplanation'));
|
||||
});
|
||||
|
||||
it('does not call $scope.logout before 3 seconds', function () {
|
||||
sandbox.stub(scope, 'logout');
|
||||
|
||||
scope.clearLocalStorage();
|
||||
|
||||
timer.tick(2999);
|
||||
|
||||
expect(scope.logout).to.not.be.called;
|
||||
});
|
||||
|
||||
it('calls $scope.logout after 3 seconds', function () {
|
||||
sandbox.stub(scope, 'logout');
|
||||
|
||||
scope.clearLocalStorage();
|
||||
|
||||
timer.tick(3000);
|
||||
|
||||
expect(scope.logout).to.be.calledOnce;
|
||||
});
|
||||
|
||||
it('does not clear local storage before 3 seconds', function () {
|
||||
sandbox.stub(localStorage, 'clear');
|
||||
|
||||
scope.clearLocalStorage();
|
||||
|
||||
timer.tick(2999);
|
||||
|
||||
expect(localStorage.clear).to.not.be.called;
|
||||
});
|
||||
|
||||
it('clears local storage after 3 seconds', function () {
|
||||
sandbox.stub(localStorage, 'clear');
|
||||
|
||||
scope.clearLocalStorage();
|
||||
|
||||
timer.tick(3000);
|
||||
|
||||
expect(localStorage.clear).to.be.calledOnce;
|
||||
});
|
||||
|
||||
it('does not redirect to /logout route before 3 seconds', function () {
|
||||
scope.clearLocalStorage();
|
||||
|
||||
timer.tick(2999);
|
||||
|
||||
expect($window.location.href).to.eql('');
|
||||
});
|
||||
|
||||
it('redirects to /logout after 3 seconds', function () {
|
||||
scope.clearLocalStorage();
|
||||
|
||||
timer.tick(3000);
|
||||
|
||||
expect($window.location.href).to.eql('/logout');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user