@@ -3,36 +3,36 @@ import { Project } from './project';
3
3
4
4
describe ( 'Project' , ( ) => {
5
5
let service : Project ;
6
- let http : HttpStub ;
6
+ let api : ApiStub ;
7
7
8
8
beforeEach ( ( ) => {
9
- http = new HttpStub ( ) ;
10
- service = new Project ( http as any ) ;
9
+ api = new ApiStub ( ) ;
10
+ service = new Project ( api as any ) ;
11
11
} ) ;
12
12
13
13
it ( 'should be created' , ( ) => {
14
14
expect ( service ) . toBeTruthy ( ) ;
15
15
} ) ;
16
16
17
17
describe ( 'load()' , ( ) => {
18
- it ( 'should load data via http ' , ( ) => {
19
- const spy = spyOn ( http , 'get ' ) . and . callThrough ( ) ;
18
+ it ( 'should load data via api ' , ( ) => {
19
+ const spy = spyOn ( api , 'getProject ' ) . and . callThrough ( ) ;
20
20
service . load ( ) . subscribe ( ( ) => {
21
21
} ) ;
22
- expect ( spy ) . toHaveBeenCalledWith ( '/api/project' ) ;
22
+ expect ( spy ) . toHaveBeenCalled ( ) ;
23
23
} ) ;
24
24
25
25
it ( 'should store data' , ( ) => {
26
26
service . load ( ) . subscribe ( ( ) => {
27
27
} ) ;
28
- expect ( service . data ) . toEqual ( http . project as any ) ;
28
+ expect ( service . data ) . toEqual ( api . project as any ) ;
29
29
} ) ;
30
30
31
31
it ( 'should run setCurrent() with first locale' , ( ) => {
32
32
const spy = spyOn ( service , 'setCurrent' ) ;
33
33
service . load ( ) . subscribe ( ( ) => {
34
34
} ) ;
35
- expect ( spy ) . toHaveBeenCalledWith ( http . project . output . translations [ 0 ] . locale ) ;
35
+ expect ( spy ) . toHaveBeenCalledWith ( api . project . output . translations [ 0 ] . locale ) ;
36
36
} ) ;
37
37
} ) ;
38
38
@@ -86,13 +86,13 @@ describe('Project', () => {
86
86
} ) ;
87
87
88
88
it ( 'should trim messages' , ( ) => {
89
- http . project . input . translations = {
89
+ api . project . input . translations = {
90
90
'KEY' : ' Source' ,
91
91
} ;
92
- http . project . output . source . translations = {
92
+ api . project . output . source . translations = {
93
93
'KEY' : 'Source ' ,
94
94
} ;
95
- http . project . output . translations [ 0 ] . translations = {
95
+ api . project . output . translations [ 0 ] . translations = {
96
96
'KEY' : 'Target' ,
97
97
} ;
98
98
service . load ( ) . subscribe ( ( ) => {
@@ -110,16 +110,16 @@ describe('Project', () => {
110
110
} ) ;
111
111
112
112
it ( 'should suggest' , ( ) => {
113
- http . project . input . translations = {
113
+ api . project . input . translations = {
114
114
'KEY_1' : 'Input Source 1' ,
115
115
'KEY_2' : 'Input Source 2' ,
116
116
} ;
117
- http . project . output . source . translations = {
117
+ api . project . output . source . translations = {
118
118
'KEY_1' : 'Input Source 2' ,
119
119
'KEY_2' : 'Input Source 1' ,
120
120
'KEY_3' : 'Input Source 2' ,
121
121
} ;
122
- http . project . output . translations [ 0 ] . translations = {
122
+ api . project . output . translations [ 0 ] . translations = {
123
123
'KEY_1' : 'Target 1' ,
124
124
'KEY_2' : 'Target 2' ,
125
125
'KEY_3' : 'Target 3' ,
@@ -170,13 +170,12 @@ describe('Project', () => {
170
170
171
171
describe ( 'save()' , ( ) => {
172
172
it ( 'should compile body and send via http' , ( ) => {
173
- const spy = spyOn ( http , 'post ' ) . and . callThrough ( ) ;
173
+ const spy = spyOn ( api , 'postProject ' ) . and . callThrough ( ) ;
174
174
service . load ( ) . subscribe ( ( ) => {
175
175
} ) ;
176
176
service . save ( ) . subscribe ( ( ) => {
177
177
} ) ;
178
178
expect ( spy ) . toHaveBeenCalledWith (
179
- '/api/project' ,
180
179
{
181
180
input : {
182
181
locale : 'INP_LOC' ,
@@ -193,34 +192,33 @@ describe('Project', () => {
193
192
} ) ;
194
193
195
194
it ( 'should sort messages by ID' , ( ) => {
196
- http . project . input . translations = {
195
+ api . project . input . translations = {
197
196
'KEY_3' : 'Key3' ,
198
197
'KEY_1' : 'Key1' ,
199
198
'A_KEY' : 'AKey' ,
200
199
'Z_KEY' : 'ZKey' ,
201
200
'KEY_2' : 'Key2' ,
202
201
} ;
203
- http . project . output . source . translations = {
202
+ api . project . output . source . translations = {
204
203
'KEY_3' : 'Key3' ,
205
204
'KEY_1' : 'Key1' ,
206
205
'A_KEY' : 'AKey' ,
207
206
'Z_KEY' : 'ZKey' ,
208
207
'KEY_2' : 'Key2' ,
209
208
} ;
210
- http . project . output . translations [ 0 ] . translations = {
209
+ api . project . output . translations [ 0 ] . translations = {
211
210
'KEY_3' : 'Key3' ,
212
211
'KEY_1' : 'Key1' ,
213
212
'A_KEY' : 'AKey' ,
214
213
'Z_KEY' : 'ZKey' ,
215
214
'KEY_2' : 'Key2' ,
216
215
} ;
217
- const spy = spyOn ( http , 'post ' ) . and . callThrough ( ) ;
216
+ const spy = spyOn ( api , 'postProject ' ) . and . callThrough ( ) ;
218
217
service . load ( ) . subscribe ( ( ) => {
219
218
} ) ;
220
219
service . save ( ) . subscribe ( ( ) => {
221
220
} ) ;
222
221
expect ( spy ) . toHaveBeenCalledWith (
223
- '/api/project' ,
224
222
{
225
223
input : {
226
224
locale : 'INP_LOC' ,
@@ -237,23 +235,22 @@ describe('Project', () => {
237
235
} ) ;
238
236
239
237
it ( 'should remove non existed messages in source from target' , ( ) => {
240
- http . project . input . translations = {
238
+ api . project . input . translations = {
241
239
'KEY' : 'Source' ,
242
240
} ;
243
- http . project . output . source . translations = {
241
+ api . project . output . source . translations = {
244
242
'KEY' : 'Source' ,
245
243
} ;
246
- http . project . output . translations [ 0 ] . translations = {
244
+ api . project . output . translations [ 0 ] . translations = {
247
245
'KEY' : 'Target' ,
248
246
'UNEX_KEY' : 'Unex' ,
249
247
} ;
250
- const spy = spyOn ( http , 'post ' ) . and . callThrough ( ) ;
248
+ const spy = spyOn ( api , 'postProject ' ) . and . callThrough ( ) ;
251
249
service . load ( ) . subscribe ( ( ) => {
252
250
} ) ;
253
251
service . save ( ) . subscribe ( ( ) => {
254
252
} ) ;
255
253
expect ( spy ) . toHaveBeenCalledWith (
256
- '/api/project' ,
257
254
{
258
255
input : {
259
256
locale : 'INP_LOC' ,
@@ -271,7 +268,7 @@ describe('Project', () => {
271
268
} ) ;
272
269
} ) ;
273
270
274
- class HttpStub {
271
+ class ApiStub {
275
272
project : any = {
276
273
success : true ,
277
274
config : 'CONFIG' ,
@@ -304,11 +301,11 @@ class HttpStub {
304
301
} ,
305
302
} ;
306
303
307
- get ( url : string ) {
304
+ getProject ( ) {
308
305
return of ( this . project ) ;
309
306
}
310
307
311
- post ( url : string , body : any ) {
308
+ postProject ( body : any ) {
312
309
return of ( true ) ;
313
310
}
314
311
}
0 commit comments