Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ fileignoreconfig:
ignore_detectors:
- filecontent
- filename: package-lock.json
checksum: 54777ceb615ca49bc21baf255b1ee9781da7e2868ff3d4292a6715bcbed33196
checksum: 67614c9c8ad75adf4479b309dbea1d8baac81c28175b21f51fbb487840ca6bda
- filename: src/entry-editable.ts
checksum: 3ba7af9ed1c1adef2e2bd5610099716562bebb8ba750d4b41ddda99fc9eaf115
- filename: .husky/pre-commit
checksum: 5baabd7d2c391648163f9371f0e5e9484f8fb90fa2284cfc378732ec3192c193
- filename: src/endpoints.ts
checksum: 721a1df93b02d04c1c19a76c171fe2748e4abb1fc3e43452e76fecfd8f384751
- filename: src/options/default-node-options.ts
checksum: d455330cc4f9306889fb299171364a37ad2c3bafe1fbd334033edc94f21694a6
334 changes: 334 additions & 0 deletions __test__/default-node-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Node from '../src/nodes/node'
import NodeType from '../src/nodes/node-type'
import { Next, RenderMark, RenderNode } from '../src/options'
import { defaultNodeOption } from '../src/options/default-node-options'
import { Attributes } from '../src/Models/metadata-model'

const text = 'text'
const next : Next = () => text
Expand Down Expand Up @@ -233,4 +234,337 @@ describe('Default node render options', () => {
expect(renderString).toEqual('<sup>text</sup>')
done()
})
})

describe('Default node render options - Missing attrs cases', () => {
// Create nodes with undefined attrs using type assertion
const nodeWithoutAttrs = {
type: NodeType.PARAGRAPH,
children: []
} as unknown as Node

const nodeWithUndefinedAttrs = {
type: NodeType.PARAGRAPH,
attrs: undefined as unknown as Attributes,
children: []
} as Node

it('Should handle paragraph without attrs', done => {
const renderString = (defaultNodeOption[NodeType.PARAGRAPH] as RenderNode)(nodeWithoutAttrs, next)
expect(renderString).toEqual('<p>text</p>')
done()
})

it('Should handle paragraph with undefined attrs', done => {
const renderString = (defaultNodeOption[NodeType.PARAGRAPH] as RenderNode)(nodeWithUndefinedAttrs, next)
expect(renderString).toEqual('<p>text</p>')
done()
})

it('Should handle link without attrs', done => {
const linkNodeNoAttrs = {
type: NodeType.LINK,
children: []
} as unknown as Node
const renderString = (defaultNodeOption[NodeType.LINK] as RenderNode)(linkNodeNoAttrs, next)
expect(renderString).toEqual('<a>text</a>')
done()
})

it('Should handle link without href or url', done => {
const linkNodePartialAttrs = {
type: NodeType.LINK,
attrs: { style: 'color: red;' },
children: []
} as Node
const renderString = (defaultNodeOption[NodeType.LINK] as RenderNode)(linkNodePartialAttrs, next)
expect(renderString).toEqual('<a style="color: red;">text</a>')
done()
})

it('Should handle image without attrs', done => {
const imgNodeNoAttrs = {
type: NodeType.IMAGE,
children: []
} as unknown as Node
const renderString = (defaultNodeOption[NodeType.IMAGE] as RenderNode)(imgNodeNoAttrs, next)
expect(renderString).toEqual('<img />text')
done()
})

it('Should handle image without src or url', done => {
const imgNodePartialAttrs = {
type: NodeType.IMAGE,
attrs: { id: 'img-id' },
children: []
} as Node
const renderString = (defaultNodeOption[NodeType.IMAGE] as RenderNode)(imgNodePartialAttrs, next)
expect(renderString).toEqual('<img id="img-id" />text')
done()
})

it('Should handle embed without attrs', done => {
const embedNodeNoAttrs = {
type: NodeType.EMBED,
children: []
} as unknown as Node
const renderString = (defaultNodeOption[NodeType.EMBED] as RenderNode)(embedNodeNoAttrs, next)
expect(renderString).toEqual('<iframe>text</iframe>')
done()
})

it('Should handle headings without attrs', done => {
const headingNodeNoAttrs = {
type: NodeType.HEADING_1,
children: []
} as unknown as Node
const renderString = (defaultNodeOption[NodeType.HEADING_1] as RenderNode)(headingNodeNoAttrs, next)
expect(renderString).toEqual('<h1>text</h1>')
done()
})

it('Should handle headings with partial attrs', done => {
const headingNodePartialAttrs = {
type: NodeType.HEADING_2,
attrs: { style: 'font-weight: bold;' },
children: []
} as Node
const renderString = (defaultNodeOption[NodeType.HEADING_2] as RenderNode)(headingNodePartialAttrs, next)
expect(renderString).toEqual('<h2 style="font-weight: bold;">text</h2>')
done()
})

it('Should handle lists without attrs', done => {
const listNodeNoAttrs = {
type: NodeType.ORDER_LIST,
children: []
} as unknown as Node
const renderString = (defaultNodeOption[NodeType.ORDER_LIST] as RenderNode)(listNodeNoAttrs, next)
expect(renderString).toEqual('<ol>text</ol>')
done()
})

it('Should handle table without attrs', done => {
const tableNodeNoAttrs = {
type: NodeType.TABLE,
children: []
} as unknown as Node
const renderString = (defaultNodeOption[NodeType.TABLE] as RenderNode)(tableNodeNoAttrs, next)
expect(renderString).toEqual('<table>text</table>')
done()
})

it('Should handle table without colWidths', done => {
const tableNodeNoColWidths = {
type: NodeType.TABLE,
attrs: { style: 'border: 1px solid;' },
children: []
} as Node
const renderString = (defaultNodeOption[NodeType.TABLE] as RenderNode)(tableNodeNoColWidths, next)
expect(renderString).toEqual('<table style="border: 1px solid;">text</table>')
done()
})

it('Should handle table head without attrs', done => {
const tableHeadNoAttrs = {
type: NodeType.TABLE_HEAD,
children: []
} as unknown as Node
const renderString = (defaultNodeOption[NodeType.TABLE_HEAD] as RenderNode)(tableHeadNoAttrs, next)
expect(renderString).toEqual('<th>text</th>')
done()
})

it('Should handle table head without rowSpan or colSpan', done => {
const tableHeadPartialAttrs = {
type: NodeType.TABLE_HEAD,
attrs: { style: 'background: gray;' },
children: []
} as Node
const renderString = (defaultNodeOption[NodeType.TABLE_HEAD] as RenderNode)(tableHeadPartialAttrs, next)
expect(renderString).toEqual('<th style="background: gray;">text</th>')
done()
})

it('Should handle table data without attrs', done => {
const tableDataNoAttrs = {
type: NodeType.TABLE_DATA,
children: []
} as unknown as Node
const renderString = (defaultNodeOption[NodeType.TABLE_DATA] as RenderNode)(tableDataNoAttrs, next)
expect(renderString).toEqual('<td>text</td>')
done()
})

it('Should handle table data with void attribute', done => {
const tableDataVoidNoAttrs = {
type: NodeType.TABLE_DATA,
attrs: { void: true },
children: []
} as Node
const renderString = (defaultNodeOption[NodeType.TABLE_DATA] as RenderNode)(tableDataVoidNoAttrs, next)
expect(renderString).toEqual('')
done()
})

it('Should handle blockquote without attrs', done => {
const blockquoteNoAttrs = {
type: NodeType.BLOCK_QUOTE,
children: []
} as unknown as Node
const renderString = (defaultNodeOption[NodeType.BLOCK_QUOTE] as RenderNode)(blockquoteNoAttrs, next)
expect(renderString).toEqual('<blockquote>text</blockquote>')
done()
})

it('Should handle code without attrs', done => {
const codeNoAttrs = {
type: NodeType.CODE,
children: []
} as unknown as Node
const renderString = (defaultNodeOption[NodeType.CODE] as RenderNode)(codeNoAttrs, next)
expect(renderString).toEqual('<code>text</code>')
done()
})

it('Should handle reference without attrs', done => {
const referenceNoAttrs = {
type: NodeType.REFERENCE,
children: []
} as unknown as Node
const renderString = (defaultNodeOption.reference as RenderNode)(referenceNoAttrs, next)
expect(renderString).toEqual('')
done()
})

it('Should handle reference with type but no display-type', done => {
const referencePartialAttrs = {
type: NodeType.REFERENCE,
attrs: { type: 'entry' },
children: []
} as Node
const renderString = (defaultNodeOption.reference as RenderNode)(referencePartialAttrs, next)
expect(renderString).toEqual('')
done()
})

it('Should handle reference with entry type and link display-type but missing href', done => {
const referenceLinkNoHref = {
type: NodeType.REFERENCE,
attrs: { type: 'entry', 'display-type': 'link' },
children: []
} as Node
const renderString = (defaultNodeOption.reference as RenderNode)(referenceLinkNoHref, next)
expect(renderString).toEqual('<a>text</a>')
done()
})

it('Should handle reference with asset type and link display-type but missing href', done => {
const referenceAssetLinkNoHref = {
type: NodeType.REFERENCE,
attrs: { type: 'asset', 'display-type': 'link' },
children: []
} as Node
const renderString = (defaultNodeOption.reference as RenderNode)(referenceAssetLinkNoHref, next)
expect(renderString).toEqual('<a type="asset" content-type-uid="sys_assets" sys-style-type="download">text</a>')
done()
})

it('Should handle reference with asset type but missing asset-link', done => {
const referenceAssetNoLink = {
type: NodeType.REFERENCE,
attrs: { type: 'asset' },
children: []
} as Node
const renderString = (defaultNodeOption.reference as RenderNode)(referenceAssetNoLink, next)
expect(renderString).toEqual('<figure><img /></figure>')
done()
})

it('Should handle reference with asset type but partial attributes', done => {
const referenceAssetPartial = {
type: NodeType.REFERENCE,
attrs: {
type: 'asset',
'asset-link': 'https://example.com/image.jpg',
style: 'border: 1px;'
},
children: []
} as Node
const renderString = (defaultNodeOption.reference as RenderNode)(referenceAssetPartial, next)
expect(renderString).toContain('<figure')
expect(renderString).toContain('style="border: 1px;"')
expect(renderString).toContain('src=')
done()
})

it('Should handle link with target attribute', done => {
const linkWithTarget = {
type: NodeType.LINK,
attrs: { href: 'https://example.com', target: '_blank' },
children: []
} as Node
const renderString = (defaultNodeOption[NodeType.LINK] as RenderNode)(linkWithTarget, next)
expect(renderString).toEqual('<a href="https://example.com" target="_blank">text</a>')
done()
})

it('Should handle link without target attribute', done => {
const linkWithoutTarget = {
type: NodeType.LINK,
attrs: { href: 'https://example.com' },
children: []
} as Node
const renderString = (defaultNodeOption[NodeType.LINK] as RenderNode)(linkWithoutTarget, next)
expect(renderString).toEqual('<a href="https://example.com">text</a>')
done()
})

it('Should handle elements with only class-name attribute', done => {
const nodeWithClass = {
type: NodeType.PARAGRAPH,
attrs: { 'class-name': 'custom-class' },
children: []
} as Node
const renderString = (defaultNodeOption[NodeType.PARAGRAPH] as RenderNode)(nodeWithClass, next)
expect(renderString).toEqual('<p class="custom-class">text</p>')
done()
})

it('Should handle elements with only id attribute', done => {
const nodeWithId = {
type: NodeType.PARAGRAPH,
attrs: { id: 'custom-id' },
children: []
} as Node
const renderString = (defaultNodeOption[NodeType.PARAGRAPH] as RenderNode)(nodeWithId, next)
expect(renderString).toEqual('<p id="custom-id">text</p>')
done()
})

it('Should handle elements with only style attribute', done => {
const nodeWithStyle = {
type: NodeType.PARAGRAPH,
attrs: { style: 'color: blue;' },
children: []
} as Node
const renderString = (defaultNodeOption[NodeType.PARAGRAPH] as RenderNode)(nodeWithStyle, next)
expect(renderString).toEqual('<p style="color: blue;">text</p>')
done()
})

it('Should handle all common attributes together', done => {
const nodeWithAllAttrs = {
type: NodeType.PARAGRAPH,
attrs: {
style: 'color: blue;',
'class-name': 'custom-class',
id: 'custom-id'
},
children: []
} as Node
const renderString = (defaultNodeOption[NodeType.PARAGRAPH] as RenderNode)(nodeWithAllAttrs, next)
expect(renderString).toEqual('<p style="color: blue;" class="custom-class" id="custom-id">text</p>')
done()
})
})
Loading
Loading