Skip to content

test: update test mocks #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 21, 2025
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Changelog

## [1.4.0](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.4.0) (2025-04-21)
- Fix: customRenderOption for entry-embedded-as-link nodes

## [1.3.20](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.20) (2025-02-24)
- Fix: Added data-mtec as allowed attribute
- Fix: customRenderOption for entry-embedded-as-link nodes

## [1.3.19](https://github.com/contentstack/contentstack-utils-javascript/tree/v1.3.19) (2025-02-24)
- Fix: Added fix for html injection in keys and values of attributes
Expand Down
16 changes: 8 additions & 8 deletions __test__/mock/json-element-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1102,14 +1102,14 @@ const entryReferenceLinkJson = {
"uid": "7626ea98e0e95d602210",
"type": "reference",
"attrs": {
"target": "_self",
"href": "/copy-of-entry-final-02",
"display-type": "link",
"entry-uid": "entry_uid_20",
"content-type-uid": "embeddedrte",
"locale": "en-us",
"type": "entry",
"class-name": "embedded-entry"
"target": "_self",
"href": "/copy-of-entry-final-02",
"display-type": "link",
"entry-uid": "entry_uid_20",
"content-type-uid": "embeddedrte",
"locale": "en-us",
"type": "entry",
"class-name": "embedded-entry"
},
"class": "class",
"children": [
Expand Down
2 changes: 1 addition & 1 deletion __test__/reference-to-html.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ describe('Reference Node To HTML', () => {
const resultHTML = referenceToHTML(node, renderOption, (metadata: Metadata) => {
return findEmbeddedItems(metadata, { uid: 'uid' })[0]
})
expect(resultHTML).toEqual('<a class=\"embedded-entry\" href=\"/copy-of-entry-final-02\" target=\"_self\">/copy-of-entry-final-02</a>')
expect(resultHTML).toEqual('<a href=\"entry_uid_20\">/copy-of-entry-final-02</a>')
done()
})
})
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/utils",
"version": "1.3.20",
"version": "1.4.0",
"description": "Contentstack utilities for Javascript",
"main": "dist/index.es.js",
"types": "dist/types/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion src/helper/enumerate-entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export function referenceToHTML(
): string {

function sendToRenderOption(referenceNode: Node): string {
return (renderOption[referenceNode.type] as RenderNode)(referenceNode, undefined);
const next: Next = (nodes) => nodeChildrenToHTML(nodes, renderOption, renderEmbed);
return (renderOption[referenceNode.type] as RenderNode)(referenceNode, next);
}

if ((node.attrs.type === 'entry' || node.attrs.type === 'asset') && node.attrs['display-type'] === 'link') {
Expand Down
11 changes: 11 additions & 0 deletions src/options/default-node-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ export const defaultNodeOption: RenderOption = {
},

['reference']:(node: Node, next: Next) => {
if ((node.attrs.type === 'entry' || node.attrs.type === 'asset') && node.attrs['display-type'] === 'link'){
let aTagAttrs = `${node.attrs.style ? ` style="${node.attrs.style}"` : ``}${node.attrs['class-name'] ? ` class="${node.attrs['class-name']}"` : ``}${node.attrs.id ? ` id="${node.attrs.id}"` : ``} href="${node.attrs.href || node.attrs.url}"`;
if (node.attrs.target) {
aTagAttrs +=` target="${node.attrs.target}"`;
}
if(node.attrs.type == 'asset') {
aTagAttrs += ` type="asset" content-type-uid="sys_assets" ${node.attrs['asset-uid'] ? `data-sys-asset-uid="${node.attrs['asset-uid']}"` : ``} sys-style-type="download"`
}
const aTag = `<a${aTagAttrs}>${sanitizeHTML(next(node.children))}</a>`;
return aTag;
}
if (node.attrs.type === 'asset') {
const src = encodeURI(node.attrs['asset-link']);
const alt = node.attrs?.['redactor-attributes']?.['alt'];
Expand Down
Loading