Skip to content

Commit 0c86f93

Browse files
author
Chris Sloop
committedApr 30, 2021
feat: fix test types
1 parent c281aea commit 0c86f93

File tree

4 files changed

+26
-70
lines changed

4 files changed

+26
-70
lines changed
 

‎packages/contentful-slatejs-adapter/src/__test__/contentful-to-slatejs-adapter.test.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import toSlatejsDocument from '../contentful-to-slatejs-adapter';
22
import toContentfulDocument from '../slatejs-to-contentful-adapter';
3-
import * as Contentful from '@contentful/rich-text-types';
4-
5-
import * as slate from './slate-helpers';
63
import * as contentful from './contentful-helpers';
74

5+
import * as Contentful from '@contentful/rich-text-types';
6+
import type { SlateNode } from '../types';
7+
88
const schema = { blocks: { [Contentful.BLOCKS.EMBEDDED_ENTRY]: { isVoid: true } } };
99

1010
describe('adapters', () => {
1111
const testAdapters = (
1212
message: string,
1313
contentfulDoc: Contentful.Document,
14-
slateDoc: Slate.Document,
14+
slateDoc: SlateNode[],
1515
) => {
1616
describe('toSlatejsDocument()', () => {
1717
it(message, () => {
@@ -34,7 +34,7 @@ describe('adapters', () => {
3434
};
3535

3636
describe('document', () => {
37-
testAdapters('empty document', contentful.document(), slate.document());
37+
testAdapters('empty document', contentful.document(), []);
3838

3939
testAdapters(
4040
'document with block',
@@ -269,7 +269,8 @@ describe('adapters', () => {
269269
{
270270
text: 'YO',
271271
data: { a: 3 },
272-
]
272+
},
273+
],
273274
},
274275
],
275276
},
@@ -313,7 +314,7 @@ describe('adapters', () => {
313314
],
314315
};
315316

316-
const slateDoc: Slate.Document = [
317+
const slateDoc = [
317318
{
318319
type: Contentful.BLOCKS.EMBEDDED_ENTRY,
319320
data: { a: 1 },

‎packages/contentful-slatejs-adapter/src/__test__/slate-helpers.ts

-59
This file was deleted.

‎packages/contentful-slatejs-adapter/src/slatejs-to-contentful-adapter.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import flatMap from 'lodash.flatmap';
2-
import * as Contentful from '@contentful/rich-text-types';
3-
import { ContentfulNode, SlateNode } from './types';
42
import { getDataOfDefault } from './helpers';
53
import { SchemaJSON, Schema, fromJSON } from './schema';
64

5+
import * as Contentful from '@contentful/rich-text-types';
6+
import { ContentfulNode, SlateNode } from './types';
7+
78
export interface ToContentfulDocumentProperties {
8-
document: Slate.Document;
9+
document: SlateNode[];
910
schema?: SchemaJSON;
1011
}
1112

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
import * as Contentful from '@contentful/rich-text-types';
2+
import type { BaseText } from 'slate';
3+
4+
type SlateText = BaseText & {
5+
bold?: boolean;
6+
italic?: boolean;
7+
underline?: boolean;
8+
};
9+
type SlateElement = {
10+
type: string;
11+
children?: SlateNode[];
12+
data?: object;
13+
isVoid?: boolean;
14+
};
215

316
export type ContentfulNode = Contentful.Block | Contentful.Inline | Contentful.Text;
4-
export type SlateNode = Slate.Block | Slate.Inline | Slate.Text;
17+
export type SlateNode = SlateElement | SlateText;
518
export type ContentfulNonTextNodes = Contentful.Block | Contentful.Inline;

0 commit comments

Comments
 (0)
Please sign in to comment.