diff --git a/test/__testutils__/createRichTextFixtures.ts b/test/__testutils__/createRichTextFixtures.ts index 7526ee1f..1744946c 100644 --- a/test/__testutils__/createRichTextFixtures.ts +++ b/test/__testutils__/createRichTextFixtures.ts @@ -1,5 +1,3 @@ -import type { RichTextField } from "@prismicio/client"; - import cnRichTextJSON from "../__fixtures__/cnRichText.json"; import emojiRichTextJSON from "../__fixtures__/emojiRichText.json"; import enRichTextJSON from "../__fixtures__/enRichText.json"; @@ -7,6 +5,8 @@ import koRichTextJSON from "../__fixtures__/koRichText.json"; import overlappedRichTextJSON from "../__fixtures__/overlappedRichText.json"; import xssRichTextJSON from "../__fixtures__/xssRichText.json"; +import type { RichTextField } from "../../src"; + const deepCloneJSON = (json: T): T => { return JSON.parse(JSON.stringify(json)); }; diff --git a/test/helpers-asImagePixelDensitySrcSet.test.ts b/test/helpers-asImagePixelDensitySrcSet.test.ts index 5aed1b4e..6bd37493 100644 --- a/test/helpers-asImagePixelDensitySrcSet.test.ts +++ b/test/helpers-asImagePixelDensitySrcSet.test.ts @@ -9,6 +9,13 @@ it("returns null for nullish inputs", () => { it("returns an image field pixel-density-based srcset with [1, 2, 3] pxiel densities by default", () => { const field: ImageField = { + id: "id", + edit: { + x: 0, + y: 0, + zoom: 1, + background: "background", + }, url: "https://images.prismic.io/qwerty/image.png?auto=compress%2Cformat", alt: null, copyright: null, @@ -26,6 +33,13 @@ it("returns an image field pixel-density-based srcset with [1, 2, 3] pxiel densi it("supports custom pixel densities", () => { const field: ImageField = { + id: "id", + edit: { + x: 0, + y: 0, + zoom: 1, + background: "background", + }, url: "https://images.prismic.io/qwerty/image.png?auto=compress%2Cformat", alt: null, copyright: null, @@ -47,6 +61,13 @@ it("supports custom pixel densities", () => { it("applies given Imgix URL parameters", () => { const field: ImageField = { + id: "id", + edit: { + x: 0, + y: 0, + zoom: 1, + background: "background", + }, url: "https://images.prismic.io/qwerty/image.png?auto=compress%2Cformat", alt: null, copyright: null, diff --git a/test/helpers-asImageSrc.test.ts b/test/helpers-asImageSrc.test.ts index 6c6a0f59..8df8a4e6 100644 --- a/test/helpers-asImageSrc.test.ts +++ b/test/helpers-asImageSrc.test.ts @@ -9,6 +9,13 @@ it("returns null for nullish inputs", () => { it("returns an image field URL", () => { const field: ImageField = { + id: "id", + edit: { + x: 0, + y: 0, + zoom: 1, + background: "background", + }, url: "https://images.prismic.io/qwerty/image.png?auto=compress%2Cformat", alt: null, copyright: null, @@ -20,6 +27,13 @@ it("returns an image field URL", () => { it("applies given Imgix URL parameters", () => { const field: ImageField = { + id: "id", + edit: { + x: 0, + y: 0, + zoom: 1, + background: "background", + }, url: "https://images.prismic.io/qwerty/image.png?auto=compress%2Cformat", alt: null, copyright: null, diff --git a/test/helpers-asImageWidthSrcSet.test.ts b/test/helpers-asImageWidthSrcSet.test.ts index 712cfcb7..6dac502a 100644 --- a/test/helpers-asImageWidthSrcSet.test.ts +++ b/test/helpers-asImageWidthSrcSet.test.ts @@ -9,6 +9,13 @@ it("returns null for nullish inputs", () => { it("returns an image field src and width-based srcset with [640, 750, 828, 1080, 1200, 1920, 2048, 3840] widths by default", () => { const field: ImageField = { + id: "id", + edit: { + x: 0, + y: 0, + zoom: 1, + background: "background", + }, url: "https://images.prismic.io/qwerty/image.png?auto=compress%2Cformat", alt: null, copyright: null, @@ -28,6 +35,13 @@ it("returns an image field src and width-based srcset with [640, 750, 828, 1080, it("supports custom widths", () => { const field: ImageField = { + id: "id", + edit: { + x: 0, + y: 0, + zoom: 1, + background: "background", + }, url: "https://images.prismic.io/qwerty/image.png?auto=compress%2Cformat", alt: null, copyright: null, @@ -49,6 +63,13 @@ it("supports custom widths", () => { it("applies given Imgix URL parameters", () => { const field: ImageField = { + id: "id", + edit: { + x: 0, + y: 0, + zoom: 1, + background: "background", + }, url: "https://images.prismic.io/qwerty/image.png?auto=compress%2Cformat", alt: null, copyright: null, @@ -70,19 +91,40 @@ it("applies given Imgix URL parameters", () => { }); }); -it('if widths is "auto", returns a srcset of responsive views if the field contains responsive views', () => { - const field = { +it('if widths is "thumbnails", returns a srcset of responsive views if the field contains responsive views', () => { + const field: ImageField<"foo" | "bar"> = { + id: "id", + edit: { + x: 0, + y: 0, + zoom: 1, + background: "background", + }, url: "https://images.prismic.io/qwerty/image.png?auto=compress%2Cformat", alt: null, copyright: null, dimensions: { width: 1000, height: 800 }, foo: { + id: "id", + edit: { + x: 0, + y: 0, + zoom: 1, + background: "background", + }, url: "https://images.prismic.io/qwerty/image.png?auto=compress%2Cformat", alt: null, copyright: null, dimensions: { width: 500, height: 400 }, }, bar: { + id: "id", + edit: { + x: 0, + y: 0, + zoom: 1, + background: "background", + }, url: "https://images.prismic.io/qwerty/image.png?auto=compress%2Cformat", alt: null, copyright: null, @@ -99,8 +141,15 @@ it('if widths is "auto", returns a srcset of responsive views if the field conta }); }); -it('if widths is "auto", but the field does not contain responsive views, uses the default widths', () => { - const field = { +it('if widths is "thumbnails", but the field does not contain responsive views, uses the default widths', () => { + const field: ImageField = { + id: "id", + edit: { + x: 0, + y: 0, + zoom: 1, + background: "background", + }, url: "https://images.prismic.io/qwerty/image.png?auto=compress%2Cformat", alt: null, copyright: null, @@ -118,19 +167,40 @@ it('if widths is "auto", but the field does not contain responsive views, uses t }); }); -it('if widths is not "auto", but the field contains responsive views, uses the default widths and ignores thumbnails', () => { - const field = { +it('if widths is not "thumbnails", but the field contains responsive views, uses the default widths and ignores thumbnails', () => { + const field: ImageField<"foo" | "bar"> = { + id: "id", + edit: { + x: 0, + y: 0, + zoom: 1, + background: "background", + }, url: "https://images.prismic.io/qwerty/image.png?auto=compress%2Cformat", alt: null, copyright: null, dimensions: { width: 1000, height: 800 }, foo: { + id: "id", + edit: { + x: 0, + y: 0, + zoom: 1, + background: "background", + }, url: "https://images.prismic.io/qwerty/image.png?auto=compress%2Cformat", alt: null, copyright: null, dimensions: { width: 500, height: 400 }, }, bar: { + id: "id", + edit: { + x: 0, + y: 0, + zoom: 1, + background: "background", + }, url: "https://images.prismic.io/qwerty/image.png?auto=compress%2Cformat", alt: null, copyright: null, diff --git a/test/helpers-isFilled.test.ts b/test/helpers-isFilled.test.ts index ef712761..533f315e 100644 --- a/test/helpers-isFilled.test.ts +++ b/test/helpers-isFilled.test.ts @@ -60,7 +60,12 @@ it("image", (ctx) => { expect(isFilled.image(null)).toBe(false); expect(isFilled.image(undefined)).toBe(false); expect(isFilled.image({})).toBe(false); - expect(isFilled.image(ctx.mock.value.image())).toBe(true); + expect( + isFilled.image( + // @ts-expect-error Remove this comment after v7.3.0 is published. + ctx.mock.value.image(), + ), + ).toBe(true); }); it("image thumbnail", () => { @@ -69,6 +74,13 @@ it("image thumbnail", () => { expect(isFilled.imageThumbnail({})).toBe(false); expect( isFilled.imageThumbnail({ + id: "id", + edit: { + x: 0, + y: 0, + zoom: 1, + background: "background", + }, url: "url", alt: null, copyright: null, @@ -124,7 +136,12 @@ it("rich text", (ctx) => { expect(isFilled.richText([{ type: "paragraph", text: "", spans: [] }])).toBe( false, ); - expect(isFilled.richText(ctx.mock.value.richText())).toBe(true); + expect( + isFilled.richText( + // @ts-expect-error Remove this comment after v7.3.0 is published. + ctx.mock.value.richText(), + ), + ).toBe(true); }); it("select", (ctx) => { diff --git a/test/helpers-unstable_mapSliceZone.test.ts b/test/helpers-unstable_mapSliceZone.test.ts index 26800b08..60136bb8 100644 --- a/test/helpers-unstable_mapSliceZone.test.ts +++ b/test/helpers-unstable_mapSliceZone.test.ts @@ -35,10 +35,14 @@ const generateTestData = (ctx: TestContext) => { it("maps a Slice Zone", async (ctx) => { const { sliceZone, model1, model2 } = generateTestData(ctx); - const actual = await unstable_mapSliceZone(sliceZone, { - [model1.id]: () => ({ foo: "bar" }), - [model2.id]: () => ({ baz: "qux" }), - }); + const actual = await unstable_mapSliceZone( + // @ts-expect-error Remove this comment after v7.3.0 is published. + sliceZone, + { + [model1.id]: () => ({ foo: "bar" }), + [model2.id]: () => ({ baz: "qux" }), + }, + ); expect(actual).toStrictEqual([ { __mapped: true, id: undefined, slice_type: model1.id, foo: "bar" }, @@ -49,10 +53,14 @@ it("maps a Slice Zone", async (ctx) => { it("supports mapping functions that return undefined", async (ctx) => { const { sliceZone, model1, model2 } = generateTestData(ctx); - const actual = await unstable_mapSliceZone(sliceZone, { - [model1.id]: () => void 0, - [model2.id]: () => void 0, - }); + const actual = await unstable_mapSliceZone( + // @ts-expect-error Remove this comment after v7.3.0 is published. + sliceZone, + { + [model1.id]: () => void 0, + [model2.id]: () => void 0, + }, + ); expect(actual).toStrictEqual([ { __mapped: true, id: undefined, slice_type: model1.id }, @@ -63,10 +71,14 @@ it("supports mapping functions that return undefined", async (ctx) => { it("supports async mapping functions", async (ctx) => { const { sliceZone, model1, model2 } = generateTestData(ctx); - const actual = await unstable_mapSliceZone(sliceZone, { - [model1.id]: async () => ({ foo: "bar" }), - [model2.id]: async () => ({ baz: "qux" }), - }); + const actual = await unstable_mapSliceZone( + // @ts-expect-error Remove this comment after v7.3.0 is published. + sliceZone, + { + [model1.id]: async () => ({ foo: "bar" }), + [model2.id]: async () => ({ baz: "qux" }), + }, + ); expect(actual).toStrictEqual([ { __mapped: true, id: undefined, slice_type: model1.id, foo: "bar" }, @@ -77,10 +89,14 @@ it("supports async mapping functions", async (ctx) => { it("supports overriding id and slice_type properties", async (ctx) => { const { sliceZone, model1, model2 } = generateTestData(ctx); - const actual = await unstable_mapSliceZone(sliceZone, { - [model1.id]: async () => ({ id: "foo", slice_type: "bar" }), - [model2.id]: async () => ({ id: "baz", slice_type: "qux" }), - }); + const actual = await unstable_mapSliceZone( + // @ts-expect-error Remove this comment after v7.3.0 is published. + sliceZone, + { + [model1.id]: async () => ({ id: "foo", slice_type: "bar" }), + [model2.id]: async () => ({ id: "baz", slice_type: "qux" }), + }, + ); expect(actual).toStrictEqual([ { __mapped: true, id: "foo", slice_type: "bar" }, @@ -94,10 +110,14 @@ it("provides Slice data to mapping functions", async (ctx) => { const mapper1 = vi.fn(); const mapper2 = vi.fn(); - await unstable_mapSliceZone(sliceZone, { - [model1.id]: mapper1, - [model2.id]: mapper2, - }); + await unstable_mapSliceZone( + // @ts-expect-error Remove this comment after v7.3.0 is published. + sliceZone, + { + [model1.id]: mapper1, + [model2.id]: mapper2, + }, + ); expect(mapper1).toHaveBeenCalledWith({ context: undefined, @@ -122,6 +142,7 @@ it("supports context", async (ctx) => { const context = { foo: "bar" }; await unstable_mapSliceZone( + // @ts-expect-error Remove this comment after v7.3.0 is published. sliceZone, { [model1.id]: mapper1, @@ -147,12 +168,16 @@ it("supports context", async (ctx) => { it("supports lazy-loaded mapping functions", async (ctx) => { const { sliceZone, model1, model2 } = generateTestData(ctx); - const actual = await unstable_mapSliceZone(sliceZone, { - // Simulates `import()` with a named `default` export. - [model1.id]: async () => ({ default: () => ({ foo: "bar" }) }), - // Simulates `import()` with a default export. - [model2.id]: async () => () => ({ baz: "qux" }), - }); + const actual = await unstable_mapSliceZone( + // @ts-expect-error Remove this comment after v7.3.0 is published. + sliceZone, + { + // Simulates `import()` with a named `default` export. + [model1.id]: async () => ({ default: () => ({ foo: "bar" }) }), + // Simulates `import()` with a default export. + [model2.id]: async () => () => ({ baz: "qux" }), + }, + ); expect(actual).toStrictEqual([ { __mapped: true, id: undefined, slice_type: model1.id, foo: "bar" }, @@ -163,9 +188,13 @@ it("supports lazy-loaded mapping functions", async (ctx) => { it("skips Slices without a mapping function", async (ctx) => { const { sliceZone, model1 } = generateTestData(ctx); - const actual = await unstable_mapSliceZone(sliceZone, { - [model1.id]: () => void 0, - }); + const actual = await unstable_mapSliceZone( + // @ts-expect-error Remove this comment after v7.3.0 is published. + sliceZone, + { + [model1.id]: () => void 0, + }, + ); expect(actual).toStrictEqual([ { __mapped: true, id: undefined, slice_type: model1.id }, diff --git a/test/types/fields-sliceZone.types.ts b/test/types/fields-sliceZone.types.ts index 8e495541..4f03d3c5 100644 --- a/test/types/fields-sliceZone.types.ts +++ b/test/types/fields-sliceZone.types.ts @@ -34,6 +34,7 @@ import * as prismic from "../../src"; expectType([ // Slice { + id: "id", slice_type: "string", slice_label: "string", primary: {}, @@ -41,6 +42,7 @@ expectType([ }, // Shared Slice { + id: "id", slice_type: "string", slice_label: null, variation: "string", @@ -61,6 +63,7 @@ expectType([]); */ expectType>>([ { + id: "id", slice_type: "foo", slice_label: "string", primary: {}, @@ -69,6 +72,7 @@ expectType>>([ ]); expectType>>([ { + id: "id", // @ts-expect-error - Slice must match the given type. slice_type: "string", slice_label: "string", @@ -82,6 +86,7 @@ expectType>>([ */ expectType>>([ { + id: "id", slice_type: "foo", slice_label: null, variation: "string", @@ -92,6 +97,7 @@ expectType>>([ ]); expectType>>([ { + id: "id", // @ts-expect-error - Slice must match the given type. slice_type: "string", slice_label: null,