From c5675f3073aba3bb159660de66e65ba68a8a1084 Mon Sep 17 00:00:00 2001 From: Tobias Weisskopf Date: Mon, 27 Jul 2020 22:43:40 +0200 Subject: [PATCH 01/10] Unit Testing Photo Service, initial setup --- src/app/core/services/photo.service.spec.ts | 49 ++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/app/core/services/photo.service.spec.ts b/src/app/core/services/photo.service.spec.ts index 0a2c956c..3cb7c286 100644 --- a/src/app/core/services/photo.service.spec.ts +++ b/src/app/core/services/photo.service.spec.ts @@ -1,4 +1,4 @@ -import { TestBed } from '@angular/core/testing'; +import { TestBed, async } from '@angular/core/testing'; import { PhotoService } from './photo.service'; describe('PhotoService', () => { @@ -9,3 +9,50 @@ describe('PhotoService', () => { expect(service).toBeTruthy(); }); }); + + +// Unit Testing Write Tests for the following cases +// [] 001 Check if permissions given +// IF permission is given +// [] 002 Store the photo -> should succeed +// [] 003 Retrieve a photo -> should succeed +// IF permission is NOT given +// [] 004 Retrieve -> should fail +// [] 005 Store -> should fail + +// Test case 001 +// I think we should test if a photo is accessible, in both cases. If the user has given perission +// and if a user has not given permission to access the camera. + +// Test case 002 +fdescribe('create()', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should create', async (done) => { + const service: PhotoService = TestBed.get(PhotoService); + + const cameraPhoto = '"data:image/gif;base64,R0lGODlhPQBEAPeoAJosM//AwO/AwHVYZ/z595kzAP/s7P+goOXMv8+fhw/v739/f+8PD98fH/8mJl+fn/9ZWb8/PzWlwv///6wWGbImAPgTEMImIN9gUFCEm/gDALULDN8PAD6atYdCTX9gUNKlj8wZAKUsAOzZz+UMAOsJAP/Z2ccMDA8PD/95eX5NWvsJCOVNQPtfX/8zM8+QePLl38MGBr8JCP+zs9myn/8GBqwpAP/GxgwJCPny78lzYLgjAJ8vAP9fX/+MjMUcAN8zM/9wcM8ZGcATEL+QePdZWf/29uc/P9cmJu9MTDImIN+/r7+/vz8/P8VNQGNugV8AAF9fX8swMN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1A2EWDfDEUVLyADj5AChSIQW6gu10bE/JG2VnCZGfo4R4d0sdQoBAHhPjhIB94v/wRoRKQWGRHgrhGSQJxCS+0pCZbEhAAOw=="' + + const expectedOutput = JSON.stringify(cameraPhoto); + + service.create().subscribe(x => { + expect(JSON.stringify(x)).toEqual(expectedOutput); + done(); + }); + }); +}); + + +// Test case 003 +fdescribe('getCameraPhoto', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('#getCameraPhoto should return an observable', + (done: DoneFn) => { + const service: PhotoService = TestBed.get(PhotoService); + service.getCameraPhoto().subscribe(x => { + expect(x).toBe('observable value'); + done(); + }); + }) +}); From df56839ce84fe46ae0c7c872ab9e6e06193b1966 Mon Sep 17 00:00:00 2001 From: ethanwu155 Date: Thu, 30 Jul 2020 17:47:28 +0800 Subject: [PATCH 02/10] added recordservice unit test --- src/app/core/services/record.service.spec.ts | 86 +++++++++++++++++++- 1 file changed, 85 insertions(+), 1 deletion(-) diff --git a/src/app/core/services/record.service.spec.ts b/src/app/core/services/record.service.spec.ts index 6419b0b3..49632cb2 100644 --- a/src/app/core/services/record.service.spec.ts +++ b/src/app/core/services/record.service.spec.ts @@ -1,12 +1,96 @@ import { TestBed } from '@angular/core/testing'; import { RecordService } from './record.service'; +import { Record } from '@core/classes/record'; +import { Plugins } from '@capacitor/core'; +import { GeolocationService } from './geolocation.service'; +import { RecordPreset } from './preset.service'; + +const { Storage } = Plugins; describe('RecordService', () => { beforeEach(() => TestBed.configureTestingModule({})); it('should be created', () => { - const service: RecordService = TestBed.get(RecordService); + const service: RecordService = TestBed.inject(RecordService); expect(service).toBeTruthy(); }); }); + +fdescribe('save', () => { + let originalTimeOut; + beforeEach(() => { + originalTimeOut = jasmine.DEFAULT_TIMEOUT_INTERVAL; + jasmine.DEFAULT_TIMEOUT_INTERVAL = 100000; + }); + + beforeEach(() => TestBed.configureTestingModule({})); + + it('should save', async (done) => { + const service: RecordService = TestBed.inject(RecordService); + + const record = new Record(20200730); + + service.save(record).subscribe(x => { + expect(JSON.stringify(x[x.length - 1])).toEqual(JSON.stringify(record)); + done(); + }); + await Storage.clear(); + }); + afterEach(() => { + jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeOut; + }); +}); + +fdescribe('attachProof method attached location proof', () => { + let originalTimeOut; + beforeEach(() => { + originalTimeOut = jasmine.DEFAULT_TIMEOUT_INTERVAL; + jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000000; + }); + + beforeEach(() => TestBed.configureTestingModule({})); + + it('should attach proof', async (done) => { + const service: RecordService = TestBed.inject(RecordService); + + const record = new Record(20200731); + + service.attachProof(record).subscribe(x => { + GeolocationService.prototype.getPosition().subscribe(y => { + + expect(x.proof.location.accuracy).toEqual(y.coords.accuracy); + expect(x.proof.location.latitude).toEqual(y.coords.latitude); + expect(x.proof.location.longitude).toEqual(y.coords.longitude); + done(); + }); + }); + }); + afterEach(() => { + jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeOut; + }); +}); + +fdescribe('create method with commonCold template', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should create commonCold template', () => { + const service: RecordService = TestBed.inject(RecordService); + + service.create(RecordPreset.COMMON_COLD).subscribe(x => { + expect(x.templateName).toEqual('commonCold'); + }); + }); +}); + +fdescribe('create method with heartFailure template', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should create heartFailure template', () => { + const service: RecordService = TestBed.inject(RecordService); + + service.create(RecordPreset.HEART_FAILURE).subscribe(x => { + expect(x.templateName).toEqual('heartFailure'); + }); + }); +}); \ No newline at end of file From 4d0de20c6f80c26e5183b33f1bce894370116c4a Mon Sep 17 00:00:00 2001 From: ethanwu155 Date: Mon, 3 Aug 2020 14:58:31 +0800 Subject: [PATCH 03/10] added photo-service unit test --- src/app/core/services/photo.service.spec.ts | 73 +++++++++++---------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/src/app/core/services/photo.service.spec.ts b/src/app/core/services/photo.service.spec.ts index 3cb7c286..06574ecb 100644 --- a/src/app/core/services/photo.service.spec.ts +++ b/src/app/core/services/photo.service.spec.ts @@ -1,58 +1,61 @@ -import { TestBed, async } from '@angular/core/testing'; +import { TestBed } from '@angular/core/testing'; import { PhotoService } from './photo.service'; describe('PhotoService', () => { beforeEach(() => TestBed.configureTestingModule({})); it('should be created', () => { - const service: PhotoService = TestBed.get(PhotoService); + const service: PhotoService = TestBed.inject(PhotoService); expect(service).toBeTruthy(); }); }); +fdescribe('getCameraPhoto', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be be defined', () => { + const newPhoto = new PhotoService(); + const spyGetCameraPhoto = spyOn(newPhoto, 'getCameraPhoto'); + expect(spyGetCameraPhoto).toBeDefined(); + }); +}); -// Unit Testing Write Tests for the following cases -// [] 001 Check if permissions given -// IF permission is given -// [] 002 Store the photo -> should succeed -// [] 003 Retrieve a photo -> should succeed -// IF permission is NOT given -// [] 004 Retrieve -> should fail -// [] 005 Store -> should fail +fdescribe('getCameraPhoto', () => { -// Test case 001 -// I think we should test if a photo is accessible, in both cases. If the user has given perission -// and if a user has not given permission to access the camera. + let photo; -// Test case 002 -fdescribe('create()', () => { beforeEach(() => TestBed.configureTestingModule({})); - it('should create', async (done) => { - const service: PhotoService = TestBed.get(PhotoService); - - const cameraPhoto = '"data:image/gif;base64,R0lGODlhPQBEAPeoAJosM//AwO/AwHVYZ/z595kzAP/s7P+goOXMv8+fhw/v739/f+8PD98fH/8mJl+fn/9ZWb8/PzWlwv///6wWGbImAPgTEMImIN9gUFCEm/gDALULDN8PAD6atYdCTX9gUNKlj8wZAKUsAOzZz+UMAOsJAP/Z2ccMDA8PD/95eX5NWvsJCOVNQPtfX/8zM8+QePLl38MGBr8JCP+zs9myn/8GBqwpAP/GxgwJCPny78lzYLgjAJ8vAP9fX/+MjMUcAN8zM/9wcM8ZGcATEL+QePdZWf/29uc/P9cmJu9MTDImIN+/r7+/vz8/P8VNQGNugV8AAF9fX8swMNgTAFlDOICAgPNSUnNWSMQ5MBAQEJE3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JG2VnCZGfo4R4d0sdQoBAHhPjhIB94v/wRoRKQWGRHgrhGSQJxCS+0pCZbEhAAOw=="' - - const expectedOutput = JSON.stringify(cameraPhoto); + beforeEach(() => { + photo = new PhotoService(); + spyOn(photo, 'getCameraPhoto').and.callThrough(); + photo.create(); + }); - service.create().subscribe(x => { - expect(JSON.stringify(x)).toEqual(expectedOutput); - done(); - }); + it('should be have been called in create method', () => { + expect(photo.getCameraPhoto).toHaveBeenCalled(); }); }); +fdescribe('create()', () => { + beforeEach(() => TestBed.configureTestingModule({})); -// Test case 003 -fdescribe('getCameraPhoto', () => { + it('should be defined', () => { + const newPhoto = new PhotoService(); + const spyCreate = spyOn(newPhoto, 'create'); + expect(spyCreate).toBeDefined(); + }); +}); + +fdescribe('create()', () => { beforeEach(() => TestBed.configureTestingModule({})); - it('#getCameraPhoto should return an observable', - (done: DoneFn) => { - const service: PhotoService = TestBed.get(PhotoService); - service.getCameraPhoto().subscribe(x => { - expect(x).toBe('observable value'); - done(); - }); - }) + it('should be called', async () => { + const newPhoto = new PhotoService(); + spyOn(newPhoto, 'create'); + newPhoto.create(); + expect(newPhoto.create).toHaveBeenCalled(); + }); }); + + From 12b5d6c2e444b2ccbe0feed1227ff4cb9b642300 Mon Sep 17 00:00:00 2001 From: ethanwu155 Date: Wed, 26 Aug 2020 00:28:47 +0800 Subject: [PATCH 04/10] added geolocation service unit test --- .../core/services/geolocation.service.spec.ts | 64 ++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/src/app/core/services/geolocation.service.spec.ts b/src/app/core/services/geolocation.service.spec.ts index 97e632c9..c428a667 100644 --- a/src/app/core/services/geolocation.service.spec.ts +++ b/src/app/core/services/geolocation.service.spec.ts @@ -5,7 +5,69 @@ describe('GeolocationService', () => { beforeEach(() => TestBed.configureTestingModule({})); it('should be created', () => { - const service: GeolocationService = TestBed.get(GeolocationService); + const service: GeolocationService = TestBed.inject(GeolocationService); expect(service).toBeTruthy(); }); }); + +fdescribe('getPosition', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('method should be defined', () => { + const service: GeolocationService = TestBed.inject(GeolocationService); + + expect(service.getPosition()).toBeDefined(); + }); +}); + +fdescribe('getPosition', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be called', () => { + const geolocation = new GeolocationService(); + spyOn(geolocation, 'getPosition'); + geolocation.getPosition(); + expect(geolocation.getPosition).toHaveBeenCalled(); + }); +}); + +describe('watchPosition with default options', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be the same as getPosition', async (done) => { + const service: GeolocationService = TestBed.inject(GeolocationService); + + service.watchPosition().subscribe(x => { + service.getPosition().subscribe(y => { + expect(x).toEqual(y); + done(); + }); + }); + }); +}); + +describe('private method isCachedPositionValid', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be defined', () => { + const geolocation = new GeolocationService(); + const spyIsCachedPositionValid = spyOn(geolocation, 'isCachedPositionValid'); + expect(spyIsCachedPositionValid).toBeDefined(); + }); +}); + +describe('isCachedPositionValid', () => { + let geolocation; + beforeEach(() => TestBed.configureTestingModule({})); + + beforeEach(() => { + geolocation = new GeolocationService(); + spyOn(geolocation, 'isCachedPositionValid').and.callThrough(); + geolocation.getPosition(); + }); + + it('should be called in getPosition', () => { + expect(geolocation.isCachedPositionValid).toHaveBeenCalled(); + }); +}); + From b154d79b50213d1470422104bd2b43a6a22b4d74 Mon Sep 17 00:00:00 2001 From: ethanwu155 Date: Wed, 26 Aug 2020 00:29:20 +0800 Subject: [PATCH 05/10] edit photo service unit test --- src/app/core/services/photo.service.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/core/services/photo.service.spec.ts b/src/app/core/services/photo.service.spec.ts index 06574ecb..339109a0 100644 --- a/src/app/core/services/photo.service.spec.ts +++ b/src/app/core/services/photo.service.spec.ts @@ -1,7 +1,7 @@ import { TestBed } from '@angular/core/testing'; import { PhotoService } from './photo.service'; -describe('PhotoService', () => { +fdescribe('PhotoService', () => { beforeEach(() => TestBed.configureTestingModule({})); it('should be created', () => { From 3c3fc3030e8fea3eac65b7f42851e0dbe6237d57 Mon Sep 17 00:00:00 2001 From: ethanwu155 Date: Wed, 26 Aug 2020 00:29:57 +0800 Subject: [PATCH 06/10] added preset unit tests --- src/app/core/services/preset.service.spec.ts | 33 ++++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/app/core/services/preset.service.spec.ts b/src/app/core/services/preset.service.spec.ts index 24d89939..580abdcb 100644 --- a/src/app/core/services/preset.service.spec.ts +++ b/src/app/core/services/preset.service.spec.ts @@ -1,12 +1,39 @@ import { TestBed } from '@angular/core/testing'; +import { Record } from '../classes/record'; -import { PresetService } from './preset.service'; +import { PresetService, RecordPreset } from './preset.service'; -describe('PresetService', () => { +fdescribe('PresetService', () => { beforeEach(() => TestBed.configureTestingModule({})); it('should be created', () => { - const service: PresetService = TestBed.get(PresetService); + const service: PresetService = TestBed.inject(PresetService); expect(service).toBeTruthy(); }); }); + +fdescribe('initRecordWithPreset with commonCold', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should initialize record with preset', () => { + const service: PresetService = TestBed.inject(PresetService); + + const record = new Record(20190619); + const result = service.initRecordWithPreset(record, RecordPreset.COMMON_COLD); + expect(result.timestamp).toEqual(20190619); + expect(result.templateName).toEqual('commonCold'); + }); +}); + +fdescribe('initRecordWithPreset with heartfailure', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should initialize record with preset', () => { + const service: PresetService = TestBed.inject(PresetService); + + const record = new Record(20201208); + const result = service.initRecordWithPreset(record, RecordPreset.HEART_FAILURE); + expect(result.timestamp).toEqual(20201208); + expect(result.templateName).toEqual('heartFailure'); + }); +}); From e0d82e8985167fd098a6e567378ac22c3a68b1e7 Mon Sep 17 00:00:00 2001 From: ethanwu155 Date: Wed, 26 Aug 2020 00:30:32 +0800 Subject: [PATCH 07/10] add proof service unit tests --- src/app/core/services/proof.service.spec.ts | 48 ++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/app/core/services/proof.service.spec.ts b/src/app/core/services/proof.service.spec.ts index 956dfc31..69915e69 100644 --- a/src/app/core/services/proof.service.spec.ts +++ b/src/app/core/services/proof.service.spec.ts @@ -1,12 +1,58 @@ import { TestBed } from '@angular/core/testing'; +import { of } from 'rxjs'; import { ProofService } from './proof.service'; +import { GeolocationService } from './geolocation.service'; describe('ProofService', () => { beforeEach(() => TestBed.configureTestingModule({})); it('should be created', () => { - const service: ProofService = TestBed.get(ProofService); + const service: ProofService = TestBed.inject(ProofService); expect(service).toBeTruthy(); }); }); + +fdescribe('private method getLocationProof', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be defined', () => { + const spyGetLocationProof = spyOn(ProofService.prototype, 'getLocationProof'); + + expect(spyGetLocationProof).toBeDefined(); + }); +}); + +fdescribe('createProofWithoutLocation()', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should return proof', () => { + const service: ProofService = TestBed.inject(ProofService); + expect(service.createProofWithoutLocation().timestamp).toEqual(Date.now()); + }); +}); + +fdescribe('createProof()', () => { + + let mockGeolocationService; + + beforeEach(() => { + mockGeolocationService = jasmine.createSpyObj(['getPosition']); + mockGeolocationService.getPosition.and.returnValue(of({coords: {latitude: 123, longitude: 123, accuracy: 123}})); + }); + + beforeEach(() => TestBed.configureTestingModule({ + providers: [{ provide: GeolocationService, useValue: mockGeolocationService }], + })); + + it('should return proof', (done: DoneFn) => { + const service: ProofService = TestBed.inject(ProofService); + + service.createProof().subscribe(x => { + expect(x.location.longitude).toEqual(123); + expect(x.location.latitude).toEqual(123); + expect(x.location.accuracy).toEqual(123); + done(); + }); + }); +}); From c35e3a747b6c41e608f69e6ccc507c7ed58d007b Mon Sep 17 00:00:00 2001 From: ethanwu155 Date: Wed, 26 Aug 2020 00:31:09 +0800 Subject: [PATCH 08/10] added record service unit test --- src/app/core/services/record.service.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/core/services/record.service.spec.ts b/src/app/core/services/record.service.spec.ts index 49632cb2..60e39436 100644 --- a/src/app/core/services/record.service.spec.ts +++ b/src/app/core/services/record.service.spec.ts @@ -8,7 +8,7 @@ import { RecordPreset } from './preset.service'; const { Storage } = Plugins; -describe('RecordService', () => { +fdescribe('RecordService', () => { beforeEach(() => TestBed.configureTestingModule({})); it('should be created', () => { From 8489e66a3ed972242b04a7793da7d566c7b98397 Mon Sep 17 00:00:00 2001 From: ethanwu155 Date: Wed, 26 Aug 2020 00:32:39 +0800 Subject: [PATCH 09/10] minor fix to existing unit test --- .../repository/record-repository.service.spec.ts | 12 ++++++------ .../repository/user-data-repository.service.spec.ts | 6 +++--- .../services/storage/file-system.service.spec.ts | 8 ++++---- .../services/storage/local-storage.service.spec.ts | 4 ++-- .../core/services/store/data-store.service.spec.ts | 12 ++++++------ 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/app/core/services/repository/record-repository.service.spec.ts b/src/app/core/services/repository/record-repository.service.spec.ts index 543ffd73..2034b3eb 100644 --- a/src/app/core/services/repository/record-repository.service.spec.ts +++ b/src/app/core/services/repository/record-repository.service.spec.ts @@ -17,7 +17,7 @@ describe('RecordRepositoryService', () => { }); }); -fdescribe('save()', () => { +describe('save()', () => { let originalTimeOut; beforeEach(() => { @@ -49,7 +49,7 @@ fdescribe('save()', () => { }); }); -fdescribe('save()', () => { +describe('save()', () => { beforeEach(() => TestBed.configureTestingModule({})); @@ -61,7 +61,7 @@ fdescribe('save()', () => { }); -fdescribe('getJsonAll()', () => { +describe('getJsonAll()', () => { let originalTimeOut; beforeEach(() => { @@ -89,7 +89,7 @@ fdescribe('getJsonAll()', () => { }); }); -fdescribe('getAll()', () => { +describe('getAll()', () => { let originalTimeOut; beforeEach(() => { @@ -118,7 +118,7 @@ fdescribe('getAll()', () => { }); }); -fdescribe('get()', () => { +describe('get()', () => { let originalTimeOut; beforeEach(() => { @@ -153,7 +153,7 @@ fdescribe('get()', () => { }); }); -fdescribe('getJson()', () => { +describe('getJson()', () => { beforeEach(() => TestBed.configureTestingModule({})); afterEach(async () => await Storage.clear()); diff --git a/src/app/core/services/repository/user-data-repository.service.spec.ts b/src/app/core/services/repository/user-data-repository.service.spec.ts index 4f26e7c9..ecc860d2 100644 --- a/src/app/core/services/repository/user-data-repository.service.spec.ts +++ b/src/app/core/services/repository/user-data-repository.service.spec.ts @@ -18,7 +18,7 @@ describe('UserDataRepositoryService', () => { }); }); -fdescribe('get() if no previous saved data', () => { +describe('get() if no previous saved data', () => { beforeEach(() => TestBed.configureTestingModule({})); it('should fail', (done) => { @@ -40,7 +40,7 @@ fdescribe('get() if no previous saved data', () => { }); }); -fdescribe('save()', () => { +describe('save()', () => { beforeEach(() => TestBed.configureTestingModule({})); afterEach(() => Storage.clear()); @@ -63,7 +63,7 @@ fdescribe('save()', () => { }); }); -fdescribe('get() if there is saved data', () => { +describe('get() if there is saved data', () => { beforeEach(() => TestBed.configureTestingModule({})); afterEach(() => Storage.clear()); diff --git a/src/app/core/services/storage/file-system.service.spec.ts b/src/app/core/services/storage/file-system.service.spec.ts index e86481d6..46ddf5cc 100644 --- a/src/app/core/services/storage/file-system.service.spec.ts +++ b/src/app/core/services/storage/file-system.service.spec.ts @@ -14,7 +14,7 @@ describe('FileSystemService', () => { }); }); -fdescribe('getFileHash', () => { +describe('getFileHash', () => { beforeEach(() => TestBed.configureTestingModule({})); afterEach(async () => await Filesystem.deleteFile({ @@ -37,7 +37,7 @@ fdescribe('getFileHash', () => { }); }); -fdescribe('getFileHash', () => { +describe('getFileHash', () => { beforeEach(() => TestBed.configureTestingModule({})); afterEach(async () => await Filesystem.deleteFile({ @@ -60,7 +60,7 @@ fdescribe('getFileHash', () => { }); }); -fdescribe('getJsonData', () => { +describe('getJsonData', () => { beforeEach(() => TestBed.configureTestingModule({})); afterEach(async () => await Filesystem.deleteFile({ path: 'file.txt', @@ -84,7 +84,7 @@ fdescribe('getJsonData', () => { }); }); -fdescribe('saveJsonData', () => { +describe('saveJsonData', () => { beforeEach(() => TestBed.configureTestingModule({})); it('Json Data should save', (done) => { diff --git a/src/app/core/services/storage/local-storage.service.spec.ts b/src/app/core/services/storage/local-storage.service.spec.ts index 2d50b066..9e90f8fd 100644 --- a/src/app/core/services/storage/local-storage.service.spec.ts +++ b/src/app/core/services/storage/local-storage.service.spec.ts @@ -13,7 +13,7 @@ describe('LocalStorageService', () => { }); }); -fdescribe('getData', () => { +describe('getData', () => { beforeEach(() => TestBed.configureTestingModule({})); afterEach(async () => await Storage.clear()); @@ -35,7 +35,7 @@ fdescribe('getData', () => { }); }); -fdescribe('setData', () => { +describe('setData', () => { beforeEach(() => TestBed.configureTestingModule({})); afterEach(async () => await Storage.clear()); diff --git a/src/app/core/services/store/data-store.service.spec.ts b/src/app/core/services/store/data-store.service.spec.ts index 3c32e32c..1343d5f6 100644 --- a/src/app/core/services/store/data-store.service.spec.ts +++ b/src/app/core/services/store/data-store.service.spec.ts @@ -15,7 +15,7 @@ describe('DataStoreService', () => { }); }); -fdescribe('pushData()', () => { +describe('pushData()', () => { let originalTimeOut; beforeEach(() => { @@ -39,7 +39,7 @@ fdescribe('pushData()', () => { }); }); -fdescribe('createOrReplaceUserData()', () => { +describe('createOrReplaceUserData()', () => { beforeEach(() => TestBed.configureTestingModule({})); it('should create or replace', async (done) => { @@ -61,7 +61,7 @@ fdescribe('createOrReplaceUserData()', () => { }); }); -fdescribe('createOrReplaceUserData()', () => { +describe('createOrReplaceUserData()', () => { beforeEach(() => TestBed.configureTestingModule({})); it('should replace', async (done) => { @@ -93,7 +93,7 @@ fdescribe('createOrReplaceUserData()', () => { }); }); -fdescribe('updateUserData() first & last name', () => { +describe('updateUserData() first & last name', () => { beforeEach(() => TestBed.configureTestingModule({})); it('should update user data', async (done) => { @@ -129,7 +129,7 @@ fdescribe('updateUserData() first & last name', () => { }); -fdescribe('updateUserData() with nothing', () => { +describe('updateUserData() with nothing', () => { beforeEach(() => TestBed.configureTestingModule({})); it('should do nothing', async (done) => { @@ -151,7 +151,7 @@ fdescribe('updateUserData() with nothing', () => { }); }); -fdescribe('updateUserData() with recordPresent and newUser', () => { +describe('updateUserData() with recordPresent and newUser', () => { beforeEach(() => TestBed.configureTestingModule({})); it('should udpate recordPresent and newUser', async (done) => { From b72f93cd83ea7c19cdf7ffed708bbe254baa3ee0 Mon Sep 17 00:00:00 2001 From: ethanwu155 Date: Wed, 26 Aug 2020 00:33:10 +0800 Subject: [PATCH 10/10] utility unit test added --- src/app/core/services/utility.service.spec.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/app/core/services/utility.service.spec.ts b/src/app/core/services/utility.service.spec.ts index c9d24f20..aa6236a8 100644 --- a/src/app/core/services/utility.service.spec.ts +++ b/src/app/core/services/utility.service.spec.ts @@ -2,11 +2,20 @@ import { TestBed } from '@angular/core/testing'; import { UtilityService } from './utility.service'; -describe('UtilityService', () => { +fdescribe('UtilityService', () => { beforeEach(() => TestBed.configureTestingModule({})); it('should be created', () => { - const service: UtilityService = TestBed.get(UtilityService); + const service: UtilityService = TestBed.inject(UtilityService); expect(service).toBeTruthy(); }); }); + +fdescribe('gen', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should gen', () => { + const service: UtilityService = TestBed.inject(UtilityService); + expect(service.gen(1)).toBeDefined(); + }); +});