Skip to content

Commit 967f60d

Browse files
authored
Updated richtext (#13)
* Updating Contentful Compare to use semeantic compare. Updated mock data. * Updated mock data and all tests pass * Working through an issue with stories * Storybook is working * Added alias imports and fixed tests * Fixed lint issue
1 parent 0f29f2e commit 967f60d

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

__mocks__/richtext.mock.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const originalRichText: Document = {
4040
data: {}
4141
},
4242
{
43-
nodeType: 'hyperlink',
43+
nodeType: 'hyperlink' as any,
4444
content: [{ nodeType: 'text', value: 'The Council of Elrond', marks: [], data: {} }],
4545
data: { uri: 'https://lotr.fandom.com/wiki/Council_of_Elrond' }
4646
},
@@ -56,6 +56,11 @@ export const originalRichText: Document = {
5656
nodeType: BLOCKS.LIST_ITEM,
5757
content: [{ nodeType: 'text', value: 'Samwise Gamgee', marks: [], data: {} }],
5858
data: {}
59+
},
60+
{
61+
nodeType: BLOCKS.LIST_ITEM,
62+
content: [{ nodeType: 'text', value: 'Legolas Greenleaf', marks: [], data: {} }],
63+
data: {}
5964
}
6065
],
6166
data: {}
@@ -76,11 +81,6 @@ export const originalRichText: Document = {
7681
],
7782
data: {}
7883
},
79-
{
80-
nodeType: BLOCKS.LIST_ITEM,
81-
content: [{ nodeType: 'text', value: 'Legolas Greenleaf', marks: [], data: {} }],
82-
data: {}
83-
},
8484
{
8585
nodeType: BLOCKS.QUOTE,
8686
content: [{ nodeType: 'text', value: 'Even the smallest person can change the course of the future.', marks: [], data: {} }],
@@ -90,15 +90,15 @@ export const originalRichText: Document = {
9090
nodeType: BLOCKS.TABLE,
9191
content: [
9292
{
93-
nodeType: 'table-row',
93+
nodeType: BLOCKS.TABLE_ROW,
9494
content: [
9595
{
96-
nodeType: 'table-cell',
96+
nodeType: BLOCKS.TABLE_CELL,
9797
content: [{ nodeType: 'text', value: 'Gimli', marks: [], data: {} }],
9898
data: {}
9999
},
100100
{
101-
nodeType: 'table-cell',
101+
nodeType: BLOCKS.TABLE_CELL,
102102
content: [{ nodeType: 'text', value: 'Boromir', marks: [], data: {} }],
103103
data: {}
104104
}
@@ -176,7 +176,7 @@ export const modifiedRichText: Document = {
176176
data: {}
177177
},
178178
{
179-
nodeType: 'hyperlink',
179+
nodeType: 'hyperlink' as any,
180180
content: [{ nodeType: 'text', value: 'The Council of Elrond', marks: [], data: {} }],
181181
data: { uri: 'https://lotr.fandom.com/wiki/Council_of_Elrond' }
182182
},
@@ -192,6 +192,11 @@ export const modifiedRichText: Document = {
192192
nodeType: BLOCKS.LIST_ITEM,
193193
content: [{ nodeType: 'text', value: 'Samwise Gamgee (Updated)', marks: [], data: {} }],
194194
data: {}
195+
},
196+
{
197+
nodeType: BLOCKS.LIST_ITEM,
198+
content: [{ nodeType: 'text', value: 'Legolas Greenleaf (Updated)', marks: [], data: {} }],
199+
data: {}
195200
}
196201
],
197202
data: {}
@@ -212,11 +217,6 @@ export const modifiedRichText: Document = {
212217
],
213218
data: {}
214219
},
215-
{
216-
nodeType: BLOCKS.LIST_ITEM,
217-
content: [{ nodeType: 'text', value: 'Legolas Greenleaf (Updated)', marks: [], data: {} }],
218-
data: {}
219-
},
220220
{
221221
nodeType: BLOCKS.QUOTE,
222222
content: [{ nodeType: 'text', value: 'Even the smallest person can change the course of the future. (Updated)', marks: [], data: {} }],
@@ -226,15 +226,15 @@ export const modifiedRichText: Document = {
226226
nodeType: BLOCKS.TABLE,
227227
content: [
228228
{
229-
nodeType: 'table-row',
229+
nodeType: BLOCKS.TABLE_ROW,
230230
content: [
231231
{
232-
nodeType: 'table-cell',
232+
nodeType: BLOCKS.TABLE_CELL,
233233
content: [{ nodeType: 'text', value: 'Gimli', marks: [], data: {} }],
234234
data: {}
235235
},
236236
{
237-
nodeType: 'table-cell',
237+
nodeType: BLOCKS.TABLE_CELL,
238238
content: [{ nodeType: 'text', value: 'Boromir (Updated)', marks: [], data: {} }],
239239
data: {}
240240
}

__tests__/Compare.test.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React from 'react';
33
import { render, screen } from '@testing-library/react';
44
import { Compare } from '../src/components/Compare';
55
import { originalRichText, modifiedRichText } from '../__mocks__/richtext.mock';
6+
import { BLOCKS, type Document, type TopLevelBlock } from '@contentful/rich-text-types';
67

78
describe('Compare', () => {
89
it('Contentful Document Comparison handles structure mode with word-level changes in same element type', async () => {
@@ -54,43 +55,43 @@ describe('Compare', () => {
5455
});
5556

5657
it('Contentful Document Comparison handles structure mode with different heading levels', async () => {
57-
const origDoc = {
58+
const origDoc: Document = {
5859
...originalRichText,
5960
content: [
6061
{
61-
nodeType: 'heading-1',
62+
nodeType: BLOCKS.HEADING_1,
6263
content: [
6364
{ nodeType: 'text', value: 'Main Title', marks: [], data: {} }
6465
],
6566
data: {}
6667
},
6768
{
68-
nodeType: 'heading-2',
69+
nodeType: BLOCKS.HEADING_2,
6970
content: [
7071
{ nodeType: 'text', value: 'Subtitle', marks: [], data: {} }
7172
],
7273
data: {}
7374
}
74-
]
75+
] as TopLevelBlock[]
7576
};
76-
const modDoc = {
77+
const modDoc: Document = {
7778
...modifiedRichText,
7879
content: [
7980
{
80-
nodeType: 'heading-1',
81+
nodeType: BLOCKS.HEADING_1,
8182
content: [
8283
{ nodeType: 'text', value: 'Main Title', marks: [], data: {} }
8384
],
8485
data: {}
8586
},
8687
{
87-
nodeType: 'heading-2',
88+
nodeType: BLOCKS.HEADING_2,
8889
content: [
8990
{ nodeType: 'text', value: 'Updated Subtitle', marks: [], data: {} }
9091
],
9192
data: {}
9293
}
93-
]
94+
] as TopLevelBlock[]
9495
};
9596
render(
9697
<Compare

0 commit comments

Comments
 (0)