Skip to content

Commit

Permalink
test: add new blocks renderer test
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasio committed Jun 10, 2024
1 parent 07b2c8f commit bd41697
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"build:packages": "turbo run build --filter=./packages/*",
"build:wpnextjs": "turbo run build --filter=./projects/wp-nextjs",
"test": "turbo run test",
"test:watch": "turbo run test:watch",
"lint": "turbo run lint",
"wp-env": "npm run wp-env:start -w=wp/headless-wp",
"dev": "turbo run dev --parallel --filter=!./projects/wp-multisite-nextjs --filter=!./projects/wp-multisite-i18n-nextjs",
Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"watch:ts:cjs": "npm run ts:cjs -- --watch",
"watch:ts": "npm run ts -- --watch",
"test": "jest",
"test:watch": "jest --watch",
"lint": "eslint src/"
},
"devDependencies": {
Expand Down
18 changes: 18 additions & 0 deletions packages/core/src/react/components/__tests__/BlocksRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,22 @@ describe('BlocksRenderer', () => {
</div>
`);
});

it('works correctly with chinese content', () => {
const StrongToDiv = ({ domNode, children }: BlockProps) => {
const className =
domNode instanceof Element ? domNode?.attribs.class || undefined : undefined;
return <div className={className}>{children}</div>;
};

const { container } = render(
<BlocksRenderer
html={`<h3 class="wp-block-heading" data-wp-block='{"level":3,"hash":"9fb25fc5-7456-4704-bffe-aa438487253b"}' data-wp-block-name="core/heading"><strong>&aelig;&acute;&raquo;&aring;&#139;&#149;&aelig;&#156;&#159;&eacute;&#150;&#147;</strong></h3>`}
>
<StrongToDiv tagName="strong" classList={['my-class']} />
</BlocksRenderer>,
);

expect(container).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`BlocksRenderer works correctly with chinese content 1`] = `
<div>
<h3
class="wp-block-heading"
data-wp-block="{"level":3,"hash":"9fb25fc5-7456-4704-bffe-aa438487253b"}"
data-wp-block-name="core/heading"
>
<strong>
活動期間
</strong>
</h3>
</div>
`;
3 changes: 2 additions & 1 deletion packages/next-redis-cache-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"dev": "npm run watch:ts",
"watch:ts": "npm run ts -- --watch",
"lint": "eslint src",
"test": "jest"
"test": "jest",
"test:watch": "jest --watch"
},
"dependencies": {
"ioredis": "^5.3.1"
Expand Down
1 change: 1 addition & 0 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"watch:ts:cjs": "npm run ts:cjs -- --watch",
"watch:ts": "npm run ts -- --watch",
"test": "jest",
"test:watch": "jest --watch",
"lint": "eslint src"
},
"dependencies": {
Expand Down
12 changes: 12 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
"test/**/*.ts"
]
},
"test:watch": {
"persistent": true,
"dependsOn": ["@headstartwp/core#build", "@headstartwp/next#build"],
"outputs": [
""
],
"inputs": [
"src/**/*.tsx",
"src/**/*.ts",
"test/**/*.ts"
]
},
"lint": {
"outputs": [
""
Expand Down

0 comments on commit bd41697

Please sign in to comment.