Skip to content

Commit 50e5600

Browse files
test: add test cases
1 parent 870d1bf commit 50e5600

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

__test__/entry-editable.test.ts

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,110 @@ describe('Entry editable test', () => {
232232
done()
233233
})
234234

235+
it('Entry with array containing null values should skip null elements', done => {
236+
const entryWithNullInArray = {
237+
"locale": "en-us",
238+
"uid": "uid",
239+
"items": [
240+
null,
241+
{ "title": "valid item" },
242+
null
243+
]
244+
}
245+
246+
expect(() => addTags(entryWithNullInArray, 'content_type', false)).not.toThrow()
247+
expect((entryWithNullInArray as any)['items'][1]['$']['title']).toEqual('data-cslp=content_type.uid.en-us.items.1.title')
248+
249+
done()
250+
})
251+
252+
it('Entry with array containing undefined values should skip undefined elements', done => {
253+
const entryWithUndefinedInArray = {
254+
"locale": "en-us",
255+
"uid": "uid",
256+
"items": [
257+
undefined,
258+
{ "title": "valid item" },
259+
undefined
260+
]
261+
}
262+
263+
expect(() => addTags(entryWithUndefinedInArray, 'content_type', false)).not.toThrow()
264+
expect((entryWithUndefinedInArray as any)['items'][1]['$']['title']).toEqual('data-cslp=content_type.uid.en-us.items.1.title')
265+
266+
done()
267+
})
268+
269+
it('Entry with array containing mixed null and undefined values should skip both', done => {
270+
const entryWithMixedNullUndefined = {
271+
"locale": "en-us",
272+
"uid": "uid",
273+
"items": [
274+
null,
275+
undefined,
276+
{ "title": "valid item 1" },
277+
null,
278+
{ "title": "valid item 2" },
279+
undefined
280+
]
281+
}
282+
283+
expect(() => addTags(entryWithMixedNullUndefined, 'content_type', true)).not.toThrow()
284+
expect((entryWithMixedNullUndefined as any)['items'][2]['$']['title']).toEqual({'data-cslp': 'content_type.uid.en-us.items.2.title'})
285+
expect((entryWithMixedNullUndefined as any)['items'][4]['$']['title']).toEqual({'data-cslp': 'content_type.uid.en-us.items.4.title'})
286+
287+
done()
288+
})
289+
290+
it('Entry with _embedded_items containing null values should handle gracefully', done => {
291+
const entryWithEmbeddedNull: any = {
292+
"locale": "en-us",
293+
"uid": "uid",
294+
"blocks": [
295+
{
296+
"items": [
297+
{ "heading": "Item heading" }
298+
]
299+
}
300+
],
301+
"_embedded_items": {
302+
"blocks.items.description": [null]
303+
}
304+
}
305+
306+
expect(() => addTags(entryWithEmbeddedNull, 'content_type', false)).not.toThrow()
307+
expect((entryWithEmbeddedNull as any)['blocks'][0]['items'][0]['$']['heading']).toEqual('data-cslp=content_type.uid.en-us.blocks.0.items.0.heading')
308+
expect((entryWithEmbeddedNull as any)['_embedded_items']['blocks.items.description'][0]).toBeNull()
309+
310+
done()
311+
})
312+
313+
it('Entry with nested arrays containing nulls in complex structure should work', done => {
314+
const entryWithComplexNulls: any = {
315+
"locale": "en-us",
316+
"uid": "uid",
317+
"blocks": [
318+
{
319+
"hero": {
320+
"title": "Hero title",
321+
"items": [null, { "name": "Item name" }, undefined]
322+
}
323+
},
324+
null,
325+
{
326+
"content": "Content text"
327+
}
328+
]
329+
}
330+
331+
expect(() => addTags(entryWithComplexNulls, 'content_type', true)).not.toThrow()
332+
expect((entryWithComplexNulls as any)['blocks'][0]['hero']['$']['title']).toEqual({'data-cslp': 'content_type.uid.en-us.blocks.0.hero.title'})
333+
expect((entryWithComplexNulls as any)['blocks'][0]['hero']['items'][1]['$']['name']).toEqual({'data-cslp': 'content_type.uid.en-us.blocks.0.hero.items.1.name'})
334+
expect((entryWithComplexNulls as any)['blocks'][2]['$']['content']).toEqual({'data-cslp': 'content_type.uid.en-us.blocks.2.content'})
335+
336+
done()
337+
})
338+
235339
it('Variant path sorting should work correctly for nested paths', done => {
236340
const entryWithComplexVariants = {
237341
"_version": 10,

0 commit comments

Comments
 (0)