Skip to content

Commit

Permalink
test: fix test type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloashmore committed Oct 6, 2023
1 parent f3bb48e commit e1b875b
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 39 deletions.
4 changes: 2 additions & 2 deletions test/__testutils__/createRichTextFixtures.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { RichTextField } from "@prismicio/client";

import cnRichTextJSON from "../__fixtures__/cnRichText.json";
import emojiRichTextJSON from "../__fixtures__/emojiRichText.json";
import enRichTextJSON from "../__fixtures__/enRichText.json";
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 = <T>(json: T): T => {
return JSON.parse(JSON.stringify(json));
};
Expand Down
21 changes: 21 additions & 0 deletions test/helpers-asImagePixelDensitySrcSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions test/helpers-asImageSrc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
82 changes: 76 additions & 6 deletions test/helpers-asImageWidthSrcSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
21 changes: 19 additions & 2 deletions test/helpers-isFilled.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down
Loading

0 comments on commit e1b875b

Please sign in to comment.