Skip to content

Commit

Permalink
Make sure idcard data is cleared along with other local storage (hype…
Browse files Browse the repository at this point in the history
…rledger-archives#2212)

Closes #2209

Signed-off-by: James Taylor <[email protected]>
  • Loading branch information
jt-nti authored Sep 22, 2017
1 parent 0bcaf0b commit 2df8eb4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/composer-playground/.istanbul.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ check:
global:
statements: 99
branches: 96.3
functions: 98.9
functions: 98.8
lines: 99.3
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
/* tslint:disable:max-classes-per-file */
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { DebugElement, NgZone, EventEmitter } from '@angular/core';

import { VersionCheckComponent } from './version-check.component';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { LocalStorageService } from 'angular-2-local-storage';

import { IdentityCardStorageService } from '../services/identity-card-storage.service';

import * as sinon from 'sinon';

describe('VersionCheckComponent', () => {
Expand All @@ -17,28 +20,29 @@ describe('VersionCheckComponent', () => {
let debug: DebugElement;
let element: HTMLElement;

let storageBool: boolean;

let ngbActiveModalMock = {
close: sinon.stub(),
dismiss: sinon.stub()
};

let localStorageServiceMock = {
clearAll: () => {
return storageBool;
}
};
let localStorageServiceMock;
let identityCardStorageServiceMock;

let reload;

beforeEach(async(() => {
localStorageServiceMock = sinon.createStubInstance(LocalStorageService);
identityCardStorageServiceMock = sinon.createStubInstance(IdentityCardStorageService);

TestBed.configureTestingModule({
declarations: [VersionCheckComponent],
providers: [{provide: NgbActiveModal, useValue: ngbActiveModalMock},
{provide: LocalStorageService, useValue: localStorageServiceMock}]
})
.compileComponents();
providers: [
{provide: NgbActiveModal, useValue: ngbActiveModalMock},
{provide: NgZone, useValue: new NgZone({})},
{provide: LocalStorageService, useValue: localStorageServiceMock},
{provide: IdentityCardStorageService, useValue: identityCardStorageServiceMock}
]
}).compileComponents();
}));

beforeEach(() => {
Expand All @@ -58,12 +62,26 @@ describe('VersionCheckComponent', () => {
element.textContent.should.contain('Invalid version!');
});

it('should clear all local storage', () => {
let runOutsideAngularStub = sinon.stub(fixture.ngZone, 'runOutsideAngular');
localStorageServiceMock.clearAll.returns(true);
identityCardStorageServiceMock.clearAll.returns(true);

component.clearLocalStorage();

localStorageServiceMock.clearAll.should.have.been.called;
identityCardStorageServiceMock.clearAll.should.have.been.called;
runOutsideAngularStub.should.have.been.called;
});

it('should handle unsupported browser for clearLocalStorage', () => {
storageBool = false;
let runOutsideAngularStub = sinon.stub(fixture.ngZone, 'runOutsideAngular');
localStorageServiceMock.clearAll.returns(false);

(() => {
component.clearLocalStorage();
}).should.throw(Error, 'Failed to clear local storage');

runOutsideAngularStub.should.not.have.been.called;
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Component } from '@angular/core';
import { Component, NgZone } from '@angular/core';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { LocalStorageService } from 'angular-2-local-storage';

import { IdentityCardStorageService } from '../services/identity-card-storage.service';

@Component({
selector: 'version-check-modal',
templateUrl: './version-check.component.html',
Expand All @@ -10,12 +12,16 @@ import { LocalStorageService } from 'angular-2-local-storage';
export class VersionCheckComponent {

constructor(public activeModal: NgbActiveModal,
private localStorageService: LocalStorageService) {
private zone: NgZone,
private localStorageService: LocalStorageService,
private identityCardStorageService: IdentityCardStorageService) {
}

public clearLocalStorage() {
if (this.localStorageService.clearAll()) {
return window.location.reload();
if (this.localStorageService.clearAll() && this.identityCardStorageService.clearAll()) {
this.zone.runOutsideAngular(() => {
location.reload();
});
} else {
throw new Error('Failed to clear local storage');
}
Expand Down

0 comments on commit 2df8eb4

Please sign in to comment.