Skip to content

Commit

Permalink
add unit test for RichText nextjs component
Browse files Browse the repository at this point in the history
  • Loading branch information
yavorsk committed Apr 17, 2024
1 parent 0b05351 commit 46481cd
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions packages/sitecore-jss-nextjs/src/components/RichText.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,52 @@ describe('RichText', () => {

expect(router.prefetch).callCount(0);
});

it('should render field metadata component when metadata property is present', () => {
const app = document.createElement('main');

document.body.appendChild(app);

const router = Router();

const testMetadata = {
contextItem: {
id: '{09A07660-6834-476C-B93B-584248D3003B}',
language: 'en',
revision: 'a0b36ce0a7db49418edf90eb9621e145',
version: 1,
},
fieldId: '{414061F4-FBB1-4591-BC37-BFFA67F745EB}',
fieldType: 'image',
rawValue: 'Test1',
};

const props = {
field: {
value: `
<div id="test">
<h1>Hello!</h1>
<a href="/t10">1</a>
<a href="/t10">2</a>
<a href="/contains-children"><span id="child">Title</span></a>
</div>`,
metadata: testMetadata,
},
};

const rendered = mount(
<Page value={router}>
<RichText {...props} prefetchLinks={false} />
</Page>,
{ attachTo: app }
);

// const rendered = mount(<RichText {...props} />);

expect(rendered.find('code')).to.have.length(2);
expect(rendered.html()).to.contain('<div id="test">');
expect(rendered.html()).to.contain('kind="open"');
expect(rendered.html()).to.contain('kind="close"');
expect(rendered.html()).to.contain(JSON.stringify(testMetadata));
});
});

0 comments on commit 46481cd

Please sign in to comment.