@@ -2,34 +2,40 @@ import { Yok } from "../../lib/common/yok";
2
2
import { assert } from "chai" ;
3
3
import { ProjectDataService } from "../../lib/services/project-data-service" ;
4
4
import { LoggerStub } from "../stubs" ;
5
+ import { NATIVESCRIPT_PROPS_INTERNAL_DELIMITER } from '../../lib/constants' ;
5
6
6
7
const CLIENT_NAME_KEY_IN_PROJECT_FILE = "nativescript" ;
7
8
8
- const testData : any = [ {
9
- "propertyValue" : 1 ,
10
- "propertyName" : "root" ,
11
- "description" : "returns correct result when a single propertyName is passed and the value of it is number"
12
- } ,
13
- {
14
- "propertyValue" : "expectedData" ,
15
- "propertyName" : "root" ,
16
- "description" : "returns correct result when a single propertyName is passed and the value of it is string"
17
- } ,
18
- {
19
- "propertyValue" : "expectedData" ,
20
- "propertyName" : "root.prop1" ,
21
- "description" : "returns correct result when inner propertyName is passed and the value of it is string"
22
- } ,
23
- {
24
- "propertyValue" : 1234 ,
25
- "propertyName" : "root.prop1" ,
26
- "description" : "returns correct result when inner propertyName is passed and the value of it is number"
27
- } ,
28
- {
29
- "propertyValue" : "expectedData" ,
30
- "propertyName" : "root.prop1.prop2.prop3.prop4" ,
31
- "description" : "returns correct result when really inner propertyName is passed and the value of it is string"
32
- }
9
+ const getPropertyName = ( props : string [ ] ) : string => {
10
+ return props . join ( NATIVESCRIPT_PROPS_INTERNAL_DELIMITER ) ;
11
+ } ;
12
+
13
+ const testData : any = [
14
+ {
15
+ "propertyValue" : 1 ,
16
+ "propertyName" : "root" ,
17
+ "description" : "returns correct result when a single propertyName is passed and the value of it is number"
18
+ } ,
19
+ {
20
+ "propertyValue" : "expectedData" ,
21
+ "propertyName" : "root" ,
22
+ "description" : "returns correct result when a single propertyName is passed and the value of it is string"
23
+ } ,
24
+ {
25
+ "propertyValue" : "expectedData" ,
26
+ "propertyName" : getPropertyName ( [ "root" , "prop1" ] ) ,
27
+ "description" : "returns correct result when inner propertyName is passed and the value of it is string"
28
+ } ,
29
+ {
30
+ "propertyValue" : 1234 ,
31
+ "propertyName" : getPropertyName ( [ "root" , "prop1" ] ) ,
32
+ "description" : "returns correct result when inner propertyName is passed and the value of it is number"
33
+ } ,
34
+ {
35
+ "propertyValue" : "expectedData" ,
36
+ "propertyName" : getPropertyName ( [ "root" , "prop1" , "prop2" , "prop3" , "prop4" ] ) ,
37
+ "description" : "returns correct result when really inner propertyName is passed and the value of it is string"
38
+ }
33
39
] ;
34
40
35
41
const createTestInjector = ( readTextData ?: string ) : IInjector => {
@@ -60,7 +66,7 @@ const createTestInjector = (readTextData?: string): IInjector => {
60
66
61
67
describe ( "projectDataService" , ( ) => {
62
68
const generateJsonDataFromTestData = ( currentTestData : any , skipNativeScriptKey ?: boolean ) => {
63
- const props = currentTestData . propertyName . split ( "." ) ;
69
+ const props = currentTestData . propertyName . split ( NATIVESCRIPT_PROPS_INTERNAL_DELIMITER ) ;
64
70
const data : any = { } ;
65
71
let currentData : any = skipNativeScriptKey ? data : ( data [ CLIENT_NAME_KEY_IN_PROJECT_FILE ] = { } ) ;
66
72
@@ -140,7 +146,7 @@ describe("projectDataService", () => {
140
146
} ;
141
147
142
148
const projectDataService : IProjectDataService = testInjector . resolve ( "projectDataService" ) ;
143
- projectDataService . setNSValue ( "projectDir" , "root. id" , "2" ) ;
149
+ projectDataService . setNSValue ( "projectDir" , getPropertyName ( [ "root" , " id"] ) , "2" ) ;
144
150
const expectedData = _ . cloneDeep ( initialData ) ;
145
151
expectedData [ CLIENT_NAME_KEY_IN_PROJECT_FILE ] . root . id = "2" ;
146
152
assert . isTrue ( ! ! dataPassedToWriteJson [ CLIENT_NAME_KEY_IN_PROJECT_FILE ] , "Data passed to write JSON must contain nativescript key." ) ;
@@ -154,7 +160,7 @@ describe("projectDataService", () => {
154
160
describe ( "removeNSProperty" , ( ) => {
155
161
156
162
const generateExpectedDataFromTestData = ( currentTestData : any ) => {
157
- const props = currentTestData . propertyName . split ( "." ) ;
163
+ const props = currentTestData . propertyName . split ( NATIVESCRIPT_PROPS_INTERNAL_DELIMITER ) ;
158
164
props . splice ( props . length - 1 , 1 ) ;
159
165
160
166
const data : any = { } ;
@@ -207,15 +213,15 @@ describe("projectDataService", () => {
207
213
} ;
208
214
209
215
const projectDataService : IProjectDataService = testInjector . resolve ( "projectDataService" ) ;
210
- projectDataService . removeNSProperty ( "projectDir" , "root. id" ) ;
216
+ projectDataService . removeNSProperty ( "projectDir" , getPropertyName ( [ "root" , " id"] ) ) ;
211
217
assert . deepEqual ( dataPassedToWriteJson , { nativescript : { root : { constantItem : "myValue" } } } ) ;
212
218
} ) ;
213
219
} ) ;
214
220
215
221
describe ( "removeDependency" , ( ) => {
216
222
it ( "removes specified dependency from project file" , ( ) => {
217
223
const currentTestData = {
218
- propertyName : "dependencies. myDeps" ,
224
+ propertyName : getPropertyName ( [ "dependencies" , " myDeps"] ) ,
219
225
propertyValue : "1.0.0"
220
226
} ;
221
227
0 commit comments