@@ -37,12 +37,16 @@ describe('FlexCard Community Targets Functionality', () => {
3737 } ) ,
3838 } ;
3939
40- // Call the private method via type assertion
41- ( cardTool as any ) . ensureCommunityTargets ( mappedObject ) ;
40+ // Call the private method via type assertion with isCardActive = true
41+ ( cardTool as any ) . ensureCommunityTargets ( mappedObject , true ) ;
4242
4343 const updatedDefinition = JSON . parse ( mappedObject [ CardMappings . Definition__c ] ) ;
4444 expect ( updatedDefinition . xmlObject . targets ) . to . exist ;
4545 expect ( updatedDefinition . xmlObject . targets . target ) . to . be . an ( 'array' ) ;
46+ expect ( updatedDefinition . xmlObject . targets . target ) . to . have . length ( 5 ) ;
47+ expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightning__RecordPage' ) ;
48+ expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightning__AppPage' ) ;
49+ expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightning__HomePage' ) ;
4650 expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightningCommunity__Page' ) ;
4751 expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightningCommunity__Default' ) ;
4852 } ) ;
@@ -58,10 +62,13 @@ describe('FlexCard Community Targets Functionality', () => {
5862 } ) ,
5963 } ;
6064
61- ( cardTool as any ) . ensureCommunityTargets ( mappedObject ) ;
65+ ( cardTool as any ) . ensureCommunityTargets ( mappedObject , true ) ;
6266
6367 const updatedDefinition = JSON . parse ( mappedObject [ CardMappings . Definition__c ] ) ;
64- expect ( updatedDefinition . xmlObject . targets . target ) . to . have . length ( 2 ) ;
68+ expect ( updatedDefinition . xmlObject . targets . target ) . to . have . length ( 5 ) ;
69+ expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightning__RecordPage' ) ;
70+ expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightning__AppPage' ) ;
71+ expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightning__HomePage' ) ;
6572 expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightningCommunity__Page' ) ;
6673 expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightningCommunity__Default' ) ;
6774 } ) ;
@@ -77,36 +84,46 @@ describe('FlexCard Community Targets Functionality', () => {
7784 } ) ,
7885 } ;
7986
80- ( cardTool as any ) . ensureCommunityTargets ( mappedObject ) ;
87+ ( cardTool as any ) . ensureCommunityTargets ( mappedObject , true ) ;
8188
8289 const updatedDefinition = JSON . parse ( mappedObject [ CardMappings . Definition__c ] ) ;
83- expect ( updatedDefinition . xmlObject . targets . target ) . to . have . length ( 3 ) ;
90+ expect ( updatedDefinition . xmlObject . targets . target ) . to . have . length ( 5 ) ;
91+ expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightning__RecordPage' ) ;
8492 expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightning__AppPage' ) ;
93+ expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightning__HomePage' ) ;
8594 expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightningCommunity__Page' ) ;
8695 expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightningCommunity__Default' ) ;
8796 } ) ;
8897
89- it ( 'should not add duplicate community targets when they already exist' , ( ) => {
98+ it ( 'should not add duplicate targets when they already exist' , ( ) => {
9099 const mappedObject = {
91100 [ CardMappings . Definition__c ] : JSON . stringify ( {
92101 xmlObject : {
93102 targets : {
94- target : [ 'lightningCommunity__Page' , 'lightningCommunity__Default' , 'lightning__AppPage' ] ,
103+ target : [
104+ 'lightning__RecordPage' ,
105+ 'lightning__AppPage' ,
106+ 'lightning__HomePage' ,
107+ 'lightningCommunity__Page' ,
108+ 'lightningCommunity__Default' ,
109+ ] ,
95110 } ,
96111 } ,
97112 } ) ,
98113 } ;
99114
100- ( cardTool as any ) . ensureCommunityTargets ( mappedObject ) ;
115+ ( cardTool as any ) . ensureCommunityTargets ( mappedObject , true ) ;
101116
102117 const updatedDefinition = JSON . parse ( mappedObject [ CardMappings . Definition__c ] ) ;
103- expect ( updatedDefinition . xmlObject . targets . target ) . to . have . length ( 3 ) ;
118+ expect ( updatedDefinition . xmlObject . targets . target ) . to . have . length ( 5 ) ;
119+ expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightning__RecordPage' ) ;
120+ expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightning__AppPage' ) ;
121+ expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightning__HomePage' ) ;
104122 expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightningCommunity__Page' ) ;
105123 expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightningCommunity__Default' ) ;
106- expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightning__AppPage' ) ;
107124 } ) ;
108125
109- it ( 'should convert non-array target to array and add community targets' , ( ) => {
126+ it ( 'should convert non-array target to empty array and add all required targets' , ( ) => {
110127 const mappedObject = {
111128 [ CardMappings . Definition__c ] : JSON . stringify ( {
112129 xmlObject : {
@@ -117,12 +134,14 @@ describe('FlexCard Community Targets Functionality', () => {
117134 } ) ,
118135 } ;
119136
120- ( cardTool as any ) . ensureCommunityTargets ( mappedObject ) ;
137+ ( cardTool as any ) . ensureCommunityTargets ( mappedObject , true ) ;
121138
122139 const updatedDefinition = JSON . parse ( mappedObject [ CardMappings . Definition__c ] ) ;
123140 expect ( updatedDefinition . xmlObject . targets . target ) . to . be . an ( 'array' ) ;
124- expect ( updatedDefinition . xmlObject . targets . target ) . to . have . length ( 3 ) ;
141+ expect ( updatedDefinition . xmlObject . targets . target ) . to . have . length ( 5 ) ;
142+ expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightning__RecordPage' ) ;
125143 expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightning__AppPage' ) ;
144+ expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightning__HomePage' ) ;
126145 expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightningCommunity__Page' ) ;
127146 expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightningCommunity__Default' ) ;
128147 } ) ;
@@ -134,7 +153,7 @@ describe('FlexCard Community Targets Functionality', () => {
134153
135154 // Should not throw an error
136155 expect ( ( ) => {
137- ( cardTool as any ) . ensureCommunityTargets ( mappedObject ) ;
156+ ( cardTool as any ) . ensureCommunityTargets ( mappedObject , true ) ;
138157 } ) . to . not . throw ( ) ;
139158
140159 const updatedDefinition = JSON . parse ( mappedObject [ CardMappings . Definition__c ] ) ;
@@ -146,7 +165,7 @@ describe('FlexCard Community Targets Functionality', () => {
146165
147166 // Should not throw an error
148167 expect ( ( ) => {
149- ( cardTool as any ) . ensureCommunityTargets ( mappedObject ) ;
168+ ( cardTool as any ) . ensureCommunityTargets ( mappedObject , true ) ;
150169 } ) . to . not . throw ( ) ;
151170 } ) ;
152171
@@ -160,7 +179,7 @@ describe('FlexCard Community Targets Functionality', () => {
160179
161180 // Should not throw an error
162181 expect ( ( ) => {
163- ( cardTool as any ) . ensureCommunityTargets ( mappedObject ) ;
182+ ( cardTool as any ) . ensureCommunityTargets ( mappedObject , true ) ;
164183 } ) . to . not . throw ( ) ;
165184
166185 const updatedDefinition = JSON . parse ( mappedObject [ CardMappings . Definition__c ] ) ;
@@ -177,7 +196,7 @@ describe('FlexCard Community Targets Functionality', () => {
177196
178197 // Should not throw an error
179198 expect ( ( ) => {
180- ( cardTool as any ) . ensureCommunityTargets ( mappedObject ) ;
199+ ( cardTool as any ) . ensureCommunityTargets ( mappedObject , true ) ;
181200 } ) . to . not . throw ( ) ;
182201
183202 const updatedDefinition = JSON . parse ( mappedObject [ CardMappings . Definition__c ] ) ;
@@ -199,14 +218,17 @@ describe('FlexCard Community Targets Functionality', () => {
199218 } ) ,
200219 } ;
201220
202- ( cardTool as any ) . ensureCommunityTargets ( mappedObject ) ;
221+ ( cardTool as any ) . ensureCommunityTargets ( mappedObject , true ) ;
203222
204223 const updatedDefinition = JSON . parse ( mappedObject [ CardMappings . Definition__c ] ) ;
205224 expect ( updatedDefinition . xmlObject . apiVersion ) . to . equal ( '55.0' ) ;
206225 expect ( updatedDefinition . xmlObject . isExposed ) . to . be . true ;
207226 expect ( updatedDefinition . xmlObject . masterLabel ) . to . equal ( 'Test Card' ) ;
208227 expect ( updatedDefinition . otherProperty ) . to . equal ( 'preserved' ) ;
228+ expect ( updatedDefinition . xmlObject . targets . target ) . to . have . length ( 5 ) ;
229+ expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightning__RecordPage' ) ;
209230 expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightning__AppPage' ) ;
231+ expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightning__HomePage' ) ;
210232 expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightningCommunity__Page' ) ;
211233 expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightningCommunity__Default' ) ;
212234 } ) ;
@@ -218,11 +240,11 @@ describe('FlexCard Community Targets Functionality', () => {
218240
219241 // Should throw an error due to JSON.parse, but not crash the application
220242 expect ( ( ) => {
221- ( cardTool as any ) . ensureCommunityTargets ( mappedObject ) ;
243+ ( cardTool as any ) . ensureCommunityTargets ( mappedObject , true ) ;
222244 } ) . to . throw ( ) ;
223245 } ) ;
224246
225- it ( 'should verify both required community targets are added' , ( ) => {
247+ it ( 'should verify all required targets are added' , ( ) => {
226248 const mappedObject = {
227249 [ CardMappings . Definition__c ] : JSON . stringify ( {
228250 xmlObject : {
@@ -233,16 +255,22 @@ describe('FlexCard Community Targets Functionality', () => {
233255 } ) ,
234256 } ;
235257
236- ( cardTool as any ) . ensureCommunityTargets ( mappedObject ) ;
258+ ( cardTool as any ) . ensureCommunityTargets ( mappedObject , true ) ;
237259
238260 const updatedDefinition = JSON . parse ( mappedObject [ CardMappings . Definition__c ] ) ;
239- const requiredTargets = [ 'lightningCommunity__Page' , 'lightningCommunity__Default' ] ;
261+ const requiredTargets = [
262+ 'lightning__RecordPage' ,
263+ 'lightning__AppPage' ,
264+ 'lightning__HomePage' ,
265+ 'lightningCommunity__Page' ,
266+ 'lightningCommunity__Default' ,
267+ ] ;
240268
241269 requiredTargets . forEach ( ( target ) => {
242270 expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( target ) ;
243271 } ) ;
244272
245- expect ( updatedDefinition . xmlObject . targets . target ) . to . have . length ( 2 ) ;
273+ expect ( updatedDefinition . xmlObject . targets . target ) . to . have . length ( 5 ) ;
246274 } ) ;
247275
248276 it ( 'should handle complex existing target arrays' , ( ) => {
@@ -251,6 +279,7 @@ describe('FlexCard Community Targets Functionality', () => {
251279 'lightning__HomePage' ,
252280 'lightning__RecordPage' ,
253281 'lightningCommunity__Page' , // Already exists
282+ 'someCustomTarget' ,
254283 ] ;
255284
256285 const mappedObject = {
@@ -263,24 +292,51 @@ describe('FlexCard Community Targets Functionality', () => {
263292 } ) ,
264293 } ;
265294
266- ( cardTool as any ) . ensureCommunityTargets ( mappedObject ) ;
295+ ( cardTool as any ) . ensureCommunityTargets ( mappedObject , true ) ;
267296
268297 const updatedDefinition = JSON . parse ( mappedObject [ CardMappings . Definition__c ] ) ;
269298
270299 // Should have all original targets plus the missing community target
271- expect ( updatedDefinition . xmlObject . targets . target ) . to . have . length ( 5 ) ;
300+ expect ( updatedDefinition . xmlObject . targets . target ) . to . have . length ( 6 ) ;
272301 existingTargets . forEach ( ( target ) => {
273302 expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( target ) ;
274303 } ) ;
275304 expect ( updatedDefinition . xmlObject . targets . target ) . to . include ( 'lightningCommunity__Default' ) ;
276305 } ) ;
306+
307+ it ( 'should return early and not modify definition when card is inactive' , ( ) => {
308+ const mappedObject = {
309+ [ CardMappings . Definition__c ] : JSON . stringify ( {
310+ xmlObject : {
311+ targets : {
312+ target : [ ] ,
313+ } ,
314+ } ,
315+ } ) ,
316+ } ;
317+
318+ // Call with isCardActive = false
319+ ( cardTool as any ) . ensureCommunityTargets ( mappedObject , false ) ;
320+
321+ const updatedDefinition = JSON . parse ( mappedObject [ CardMappings . Definition__c ] ) ;
322+
323+ // The definition should remain unchanged
324+ expect ( updatedDefinition . xmlObject . targets . target ) . to . be . an ( 'array' ) ;
325+ expect ( updatedDefinition . xmlObject . targets . target ) . to . have . length ( 0 ) ;
326+ expect ( updatedDefinition . xmlObject . targets . target ) . to . not . include ( 'lightning__RecordPage' ) ;
327+ expect ( updatedDefinition . xmlObject . targets . target ) . to . not . include ( 'lightning__AppPage' ) ;
328+ expect ( updatedDefinition . xmlObject . targets . target ) . to . not . include ( 'lightning__HomePage' ) ;
329+ expect ( updatedDefinition . xmlObject . targets . target ) . to . not . include ( 'lightningCommunity__Page' ) ;
330+ expect ( updatedDefinition . xmlObject . targets . target ) . to . not . include ( 'lightningCommunity__Default' ) ;
331+ } ) ;
277332 } ) ;
278333
279334 describe ( 'Integration with mapVlocityCardRecord' , ( ) => {
280- it ( 'should ensure community targets are added during card mapping' , ( ) => {
335+ it ( 'should ensure all required targets are added during card mapping for active cards ' , ( ) => {
281336 const testCard : any = {
282337 Id : 'card1' ,
283338 Name : 'Test Card' ,
339+ vlocity_ins__Active__c : true , // Active card
284340 vlocity_ins__Definition__c : JSON . stringify ( {
285341 xmlObject : {
286342 targets : {
@@ -293,15 +349,45 @@ describe('FlexCard Community Targets Functionality', () => {
293349 const result = ( cardTool as any ) . mapVlocityCardRecord ( testCard , new Map ( ) , new Map ( ) ) ;
294350 const definition = JSON . parse ( result [ 'PropertySetConfig' ] ) ;
295351
352+ expect ( definition . xmlObject . targets . target ) . to . have . length ( 5 ) ;
353+ expect ( definition . xmlObject . targets . target ) . to . include ( 'lightning__RecordPage' ) ;
296354 expect ( definition . xmlObject . targets . target ) . to . include ( 'lightning__AppPage' ) ;
355+ expect ( definition . xmlObject . targets . target ) . to . include ( 'lightning__HomePage' ) ;
297356 expect ( definition . xmlObject . targets . target ) . to . include ( 'lightningCommunity__Page' ) ;
298357 expect ( definition . xmlObject . targets . target ) . to . include ( 'lightningCommunity__Default' ) ;
299358 } ) ;
300359
360+ it ( 'should not add targets for inactive cards during card mapping' , ( ) => {
361+ const testCard : any = {
362+ Id : 'card2' ,
363+ Name : 'Inactive Card' ,
364+ vlocity_ins__Active__c : false , // Inactive card
365+ vlocity_ins__Definition__c : JSON . stringify ( {
366+ xmlObject : {
367+ targets : {
368+ target : [ 'lightning__AppPage' ] ,
369+ } ,
370+ } ,
371+ } ) ,
372+ } ;
373+
374+ const result = ( cardTool as any ) . mapVlocityCardRecord ( testCard , new Map ( ) , new Map ( ) ) ;
375+ const definition = JSON . parse ( result [ 'PropertySetConfig' ] ) ;
376+
377+ // Should remain unchanged for inactive cards
378+ expect ( definition . xmlObject . targets . target ) . to . have . length ( 1 ) ;
379+ expect ( definition . xmlObject . targets . target ) . to . include ( 'lightning__AppPage' ) ;
380+ expect ( definition . xmlObject . targets . target ) . to . not . include ( 'lightning__RecordPage' ) ;
381+ expect ( definition . xmlObject . targets . target ) . to . not . include ( 'lightning__HomePage' ) ;
382+ expect ( definition . xmlObject . targets . target ) . to . not . include ( 'lightningCommunity__Page' ) ;
383+ expect ( definition . xmlObject . targets . target ) . to . not . include ( 'lightningCommunity__Default' ) ;
384+ } ) ;
385+
301386 it ( 'should handle cards without xmlObject during mapping' , ( ) => {
302387 const testCard : any = {
303388 Id : 'card1' ,
304389 Name : 'Test Card' ,
390+ vlocity_ins__Active__c : true ,
305391 vlocity_ins__Definition__c : JSON . stringify ( {
306392 someProperty : 'value' ,
307393 } ) ,
0 commit comments