import { ELLIPSE, GROUP, IMAGE, LIBRARY_COMPONENT, SECTION, } from '@adalo/constants' import { LIST_ITEM_PUSH_NODE_NESTING_LIMIT, hasListItemContainerParent, } from './calculatePushRelations' import { mockPushNode } from './testutils' describe('calculatePushRelations helper functions', () => { test('hasListItemContainerParent returns true for nodes that are children of list items', () => { const pushNode = mockPushNode({ type: SECTION, parent: mockPushNode({ type: SECTION }), }) const hasListItemParent = hasListItemContainerParent(pushNode) expect(hasListItemParent).toBe(false) }) test('hasListItemContainerParent returns true for section type nodes within a list item', () => { // SECTION, IMAGE and ELLIPSIS are "SECTION_TYPES" const pushNodeSection = mockPushNode({ type: SECTION, parent: mockPushNode({ type: 'LIST_ITEM' }), }) const pushNodeImage = mockPushNode({ type: IMAGE, parent: mockPushNode({ type: 'LIST_ITEM' }), }) const pushNodeEllipse = mockPushNode({ type: ELLIPSE, parent: mockPushNode({ type: 'LIST_ITEM' }), }) const pushNodeGroup = mockPushNode({ type: GROUP, parent: mockPushNode({ type: 'LIST_ITEM' }), }) const pushNodeLibraryComponent = mockPushNode({ type: LIBRARY_COMPONENT, parent: mockPushNode({ type: 'LIST_ITEM' }), }) expect(hasListItemContainerParent(pushNodeSection)).toBe(true) expect(hasListItemContainerParent(pushNodeImage)).toBe(true) expect(hasListItemContainerParent(pushNodeEllipse)).toBe(true) expect(hasListItemContainerParent(pushNodeGroup)).toBe(true) expect(hasListItemContainerParent(pushNodeLibraryComponent)).toBe(false) }) test('hasListItemContainerParent returns true for nodes that are deeply nested within a list item', () => { const pushNode = mockPushNode({ type: SECTION, parent: mockPushNode({ type: SECTION, parent: mockPushNode({ type: SECTION, parent: mockPushNode({ type: SECTION, parent: mockPushNode({ type: SECTION, parent: mockPushNode({ type: SECTION, parent: mockPushNode({ type: 'LIST_ITEM' }), }), }), }), }), }), }) const hasListItemParent = hasListItemContainerParent(pushNode) expect(hasListItemParent).toBe(true) }) test('hasListItemContainerParent returns true for nodes that are nested exceeding the nesting check limit within a list item', () => { const pushNode = mockPushNode({ type: SECTION, parent: mockPushNode({ type: SECTION, parent: mockPushNode({ type: SECTION, parent: mockPushNode({ type: SECTION, parent: mockPushNode({ type: SECTION, parent: mockPushNode({ type: SECTION, parent: mockPushNode({ type: 'LIST_ITEM' }), }), }), }), }), }), }) const hasListItemParent = hasListItemContainerParent( pushNode, LIST_ITEM_PUSH_NODE_NESTING_LIMIT - 2 // Start nesting a few levels below the limit to exceed it quickly ) expect(hasListItemParent).toBe(false) }) })