@@ -2,34 +2,40 @@ import { Yok } from "../../lib/common/yok";
22import { assert } from "chai" ;
33import { ProjectDataService } from "../../lib/services/project-data-service" ;
44import { LoggerStub } from "../stubs" ;
5+ import { NATIVESCRIPT_PROPS_INTERNAL_DELIMITER } from '../../lib/constants' ;
56
67const CLIENT_NAME_KEY_IN_PROJECT_FILE = "nativescript" ;
78
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+ }
3339] ;
3440
3541const createTestInjector = ( readTextData ?: string ) : IInjector => {
@@ -60,7 +66,7 @@ const createTestInjector = (readTextData?: string): IInjector => {
6066
6167describe ( "projectDataService" , ( ) => {
6268 const generateJsonDataFromTestData = ( currentTestData : any , skipNativeScriptKey ?: boolean ) => {
63- const props = currentTestData . propertyName . split ( "." ) ;
69+ const props = currentTestData . propertyName . split ( NATIVESCRIPT_PROPS_INTERNAL_DELIMITER ) ;
6470 const data : any = { } ;
6571 let currentData : any = skipNativeScriptKey ? data : ( data [ CLIENT_NAME_KEY_IN_PROJECT_FILE ] = { } ) ;
6672
@@ -140,7 +146,7 @@ describe("projectDataService", () => {
140146 } ;
141147
142148 const projectDataService : IProjectDataService = testInjector . resolve ( "projectDataService" ) ;
143- projectDataService . setNSValue ( "projectDir" , "root. id" , "2" ) ;
149+ projectDataService . setNSValue ( "projectDir" , getPropertyName ( [ "root" , " id"] ) , "2" ) ;
144150 const expectedData = _ . cloneDeep ( initialData ) ;
145151 expectedData [ CLIENT_NAME_KEY_IN_PROJECT_FILE ] . root . id = "2" ;
146152 assert . isTrue ( ! ! dataPassedToWriteJson [ CLIENT_NAME_KEY_IN_PROJECT_FILE ] , "Data passed to write JSON must contain nativescript key." ) ;
@@ -154,7 +160,7 @@ describe("projectDataService", () => {
154160 describe ( "removeNSProperty" , ( ) => {
155161
156162 const generateExpectedDataFromTestData = ( currentTestData : any ) => {
157- const props = currentTestData . propertyName . split ( "." ) ;
163+ const props = currentTestData . propertyName . split ( NATIVESCRIPT_PROPS_INTERNAL_DELIMITER ) ;
158164 props . splice ( props . length - 1 , 1 ) ;
159165
160166 const data : any = { } ;
@@ -207,15 +213,15 @@ describe("projectDataService", () => {
207213 } ;
208214
209215 const projectDataService : IProjectDataService = testInjector . resolve ( "projectDataService" ) ;
210- projectDataService . removeNSProperty ( "projectDir" , "root. id" ) ;
216+ projectDataService . removeNSProperty ( "projectDir" , getPropertyName ( [ "root" , " id"] ) ) ;
211217 assert . deepEqual ( dataPassedToWriteJson , { nativescript : { root : { constantItem : "myValue" } } } ) ;
212218 } ) ;
213219 } ) ;
214220
215221 describe ( "removeDependency" , ( ) => {
216222 it ( "removes specified dependency from project file" , ( ) => {
217223 const currentTestData = {
218- propertyName : "dependencies. myDeps" ,
224+ propertyName : getPropertyName ( [ "dependencies" , " myDeps"] ) ,
219225 propertyValue : "1.0.0"
220226 } ;
221227
0 commit comments