Skip to content

Commit

Permalink
chore: add type tests
Browse files Browse the repository at this point in the history
  • Loading branch information
levimykel committed Oct 29, 2024
1 parent f0f46c8 commit c1e25ec
Show file tree
Hide file tree
Showing 3 changed files with 456 additions and 25 deletions.
182 changes: 168 additions & 14 deletions test/types/fields-contentRelationship.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as prismic from "../../src"
}

/**
* Filled state.
* Filled state (non-repeatable).
*/
expectType<prismic.ContentRelationshipField>({
link_type: prismic.LinkType.Document,
Expand Down Expand Up @@ -63,7 +63,57 @@ expectType<prismic.ContentRelationshipField<string, string, never, "empty">>({
})

/**
* Empty state.
* Filled state (repeatable).
*/
expectType<prismic.ContentRelationshipField>([
{
link_type: prismic.LinkType.Document,
id: "string",
uid: "string",
type: "string",
tags: ["string"],
lang: "string",
url: "string",
slug: "string",
isBroken: true,
data: undefined,
text: "string",
},
])
expectType<prismic.ContentRelationshipField<string, string, never, "filled">>([
{
link_type: prismic.LinkType.Document,
id: "string",
uid: "string",
type: "string",
tags: ["string"],
lang: "string",
url: "string",
slug: "string",
isBroken: true,
data: undefined,
text: "string",
},
])
expectType<prismic.ContentRelationshipField<string, string, never, "empty">>([
// @ts-expect-error - Empty repeatable fields cannot contain a value.
{
link_type: prismic.LinkType.Document,
id: "string",
uid: "string",
type: "string",
tags: ["string"],
lang: "string",
url: "string",
slug: "string",
isBroken: true,
data: undefined,
text: "string",
},
])

/**
* Empty state (non-repeatable).
*/
expectType<prismic.ContentRelationshipField>({
link_type: prismic.LinkType.Document,
Expand All @@ -79,7 +129,23 @@ expectType<prismic.ContentRelationshipField<string, string, never, "filled">>(
)

/**
* Empty state with text.
* Empty state (repeatable).
*/
expectType<prismic.ContentRelationshipField>([
{
link_type: prismic.LinkType.Document,
},
])
expectType<prismic.ContentRelationshipField<string, string, never, "empty">>([])
expectType<prismic.ContentRelationshipField<string, string, never, "empty">>([
// @ts-expect-error - Empty fields cannot contain a value.
{
link_type: prismic.LinkType.Document,
},
])

/**
* Empty state with text (only non-repeatable).
*/
expectType<prismic.ContentRelationshipField>({
link_type: prismic.LinkType.Document,
Expand All @@ -98,7 +164,23 @@ expectType<prismic.ContentRelationshipField<string, string, never, "filled">>(
)

/**
* Supports custom document type.
* Empty state with text (repeatable).
*/
expectType<prismic.ContentRelationshipField>([
{
link_type: prismic.LinkType.Document,
text: "string",
},
])
expectType<prismic.ContentRelationshipField<string, string, never, "filled">>([
{
link_type: prismic.LinkType.Document,
text: "string",
},
])

/**
* Supports custom document type (non-repeatable).
*/
expectType<prismic.ContentRelationshipField<"foo">>({
link_type: prismic.LinkType.Document,
Expand All @@ -107,17 +189,42 @@ expectType<prismic.ContentRelationshipField<"foo">>({
tags: [],
lang: "string",
})
expectType<prismic.ContentRelationshipField<"foo">>({
link_type: prismic.LinkType.Document,
id: "string",
expectType<prismic.ContentRelationshipField<"foo">>(
// @ts-expect-error - Document type must match the given type.
type: "string",
tags: [],
lang: "string",
})
{
link_type: prismic.LinkType.Document,
id: "string",
type: "string",
tags: [],
lang: "string",
},
)

/**
* Supports custom document language.
* Supports custom document type (repeatable).
*/
expectType<prismic.ContentRelationshipField<"foo">>([
{
link_type: prismic.LinkType.Document,
id: "string",
type: "foo",
tags: [],
lang: "string",
},
])
expectType<prismic.ContentRelationshipField<"foo">>([
{
link_type: prismic.LinkType.Document,
id: "string",
// @ts-expect-error - Document type must match the given type.
type: "string",
tags: [],
lang: "string",
},
])

/**
* Supports custom document language (non-repeatable).
*/
expectType<prismic.ContentRelationshipField<string, "fr-fr">>({
link_type: prismic.LinkType.Document,
Expand All @@ -126,17 +233,40 @@ expectType<prismic.ContentRelationshipField<string, "fr-fr">>({
tags: [],
lang: "fr-fr",
})
// @ts-expect-error - Document language must match the given type.
expectType<prismic.ContentRelationshipField<string, "fr-fr">>({
link_type: prismic.LinkType.Document,
id: "string",
type: "string",
tags: [],
// @ts-expect-error - Document language must match the given type.
lang: "string",
})

/**
* Supports custom document data.
* Supports custom document language (repeatable).
*/
expectType<prismic.ContentRelationshipField<string, "fr-fr">>([
{
link_type: prismic.LinkType.Document,
id: "string",
type: "string",
tags: [],
lang: "fr-fr",
},
])
expectType<prismic.ContentRelationshipField<string, "fr-fr">>([
{
link_type: prismic.LinkType.Document,
id: "string",
type: "string",
tags: [],
// @ts-expect-error - Document language must match the given type.
lang: "string",
},
])

/**
* Supports custom document data (non-repeatable).
*/
expectType<
prismic.ContentRelationshipField<
Expand All @@ -156,3 +286,27 @@ expectType<
bar: false,
},
})

/**
* Supports custom document data (repeatable).
*/
expectType<
prismic.ContentRelationshipField<
string,
string,
{ foo: prismic.BooleanField }
>
>([
{
link_type: prismic.LinkType.Document,
id: "string",
type: "string",
tags: [],
lang: "fr-fr",
data: {
foo: true,
// @ts-expect-error - Only given fields are valid.
bar: false,
},
},
])
Loading

0 comments on commit c1e25ec

Please sign in to comment.