@@ -6,32 +6,28 @@ describe('Project Storage', () => {
66 let storageProjects : Project [ ] ;
77 let projectsIdentifier : string ;
88 let serverProjects : Project [ ] ;
9+ let testProject : Project ;
10+ let localStorageGetItemMock ;
911
1012 beforeEach ( ( ) => {
1113 projectsIdentifier = 'projectsSelected' ;
1214
15+ testProject = {
16+ customer : {
17+ name : 'ioet Inc. (was E&Y)' ,
18+ } ,
19+ id : 'f3630e59-9408-497e-945b-848112bd5a44' ,
20+ name : 'Time Tracker' ,
21+ customer_id : '20c96c4d-5e26-4426-a704-8bdd98c83319' ,
22+ status : 'active' ,
23+ } ;
24+
1325 storageProjects = [
14- {
15- customer : {
16- name : 'ioet Inc. (was E&Y)' ,
17- } ,
18- id : 'f3630e59-9408-497e-945b-848112bd5a44' ,
19- name : 'Time Tracker' ,
20- customer_id : '20c96c4d-5e26-4426-a704-8bdd98c83319' ,
21- status : 'active' ,
22- }
26+ testProject
2327 ] ;
2428
2529 serverProjects = [
26- {
27- customer : {
28- name : 'ioet Inc. (was E&Y)' ,
29- } ,
30- id : 'f3630e59-9408-497e-945b-848112bd5a44' ,
31- name : 'Time Tracker' ,
32- customer_id : '20c96c4d-5e26-4426-a704-8bdd98c83319' ,
33- status : 'active' ,
34- } ,
30+ testProject ,
3531 {
3632 customer : {
3733 name : 'No Matter Name' ,
@@ -43,21 +39,19 @@ describe('Project Storage', () => {
4339 }
4440 ] ;
4541
42+ localStorageGetItemMock = spyOn ( localStorage , 'getItem' ) . and . returnValue ( JSON . stringify ( storageProjects ) ) ;
43+ spyOn ( localStorage , 'setItem' ) ;
44+
4645 } ) ;
4746
4847 it ( 'If exists projects in localStorage and the server returns the same project, should keep the same localStorage variables' , ( ) => {
49- spyOn ( localStorage , 'getItem' ) . and . returnValue ( JSON . stringify ( storageProjects ) ) ;
50- spyOn ( localStorage , 'setItem' ) ;
51-
5248 updateProjectStorage ( serverProjects ) ;
5349
5450 expect ( localStorage . setItem ) . toHaveBeenCalledWith ( projectsIdentifier , JSON . stringify ( storageProjects ) ) ;
5551 } ) ;
5652
5753 it ( 'If exists projects in localStorage and the server does not return that project, should update the localStorage variable' , ( ) => {
5854 serverProjects . shift ( ) ;
59- spyOn ( localStorage , 'getItem' ) . and . returnValue ( JSON . stringify ( storageProjects ) ) ;
60- spyOn ( localStorage , 'setItem' ) ;
6155
6256 updateProjectStorage ( serverProjects ) ;
6357
@@ -66,8 +60,6 @@ describe('Project Storage', () => {
6660
6761 it ( 'If Server projects is empty, should not update the localStorage' , ( ) => {
6862 serverProjects = [ ] ;
69- spyOn ( localStorage , 'getItem' ) . and . returnValue ( JSON . stringify ( storageProjects ) ) ;
70- spyOn ( localStorage , 'setItem' ) ;
7163
7264 updateProjectStorage ( serverProjects ) ;
7365
@@ -76,7 +68,8 @@ describe('Project Storage', () => {
7668
7769 it ( 'If variables does not exists on localStorage, getProjectsOnStorage should return undefined' , ( ) => {
7870 projectsIdentifier = 'no-matter-identifier' ;
79- spyOn ( localStorage , 'getItem' ) . and . returnValue ( undefined ) ;
71+
72+ localStorageGetItemMock . and . returnValue ( undefined ) ;
8073
8174 const projects = getProjectsOnStorage ( projectsIdentifier ) ;
8275
@@ -85,7 +78,7 @@ describe('Project Storage', () => {
8578
8679 it ( 'If variables not exists on localStorage, getProjectsOnStorage should return an array of Projects' , ( ) => {
8780 const storageProjectsString = JSON . stringify ( storageProjects ) ;
88- spyOn ( localStorage , 'getItem' ) . and . returnValue ( storageProjectsString ) ;
81+ localStorageGetItemMock . and . returnValue ( storageProjectsString ) ;
8982
9083 const projects = getProjectsOnStorage ( projectsIdentifier ) ;
9184
0 commit comments