Initial commit
This commit is contained in:
30
packages/core-shared/src/payload/fields/seo-fields.test.ts
Normal file
30
packages/core-shared/src/payload/fields/seo-fields.test.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { seoFields } from "./seo-fields";
|
||||
|
||||
describe("seoFields", () => {
|
||||
it("is a group field named 'seo'", () => {
|
||||
if (seoFields.type !== "group" || !("name" in seoFields)) {
|
||||
throw new Error("seoFields must be a named group");
|
||||
}
|
||||
expect(seoFields.name).toBe("seo");
|
||||
expect(seoFields.type).toBe("group");
|
||||
});
|
||||
|
||||
it("contains required title and optional description", () => {
|
||||
if (seoFields.type !== "group") {
|
||||
throw new Error("seoFields must be a group");
|
||||
}
|
||||
const fieldNames = seoFields.fields.map((f) =>
|
||||
"name" in f ? f.name : null,
|
||||
);
|
||||
expect(fieldNames).toContain("title");
|
||||
expect(fieldNames).toContain("description");
|
||||
|
||||
const titleField = seoFields.fields.find(
|
||||
(f) => "name" in f && f.name === "title",
|
||||
);
|
||||
expect(titleField && "required" in titleField && titleField.required).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
});
|
||||
10
packages/core-shared/src/payload/fields/seo-fields.ts
Normal file
10
packages/core-shared/src/payload/fields/seo-fields.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { Field } from "payload";
|
||||
|
||||
export const seoFields: Field = {
|
||||
name: "seo",
|
||||
type: "group",
|
||||
fields: [
|
||||
{ name: "title", type: "text", required: true },
|
||||
{ name: "description", type: "textarea" },
|
||||
],
|
||||
};
|
||||
19
packages/core-shared/src/payload/fields/slug-field.test.ts
Normal file
19
packages/core-shared/src/payload/fields/slug-field.test.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { slugField } from "./slug-field";
|
||||
|
||||
describe("slugField", () => {
|
||||
it("returns a Payload Field with default name 'slug'", () => {
|
||||
const field = slugField();
|
||||
if (field.type !== "text") throw new Error("expected text field");
|
||||
expect(field.name).toBe("slug");
|
||||
expect(field.required).toBe(true);
|
||||
expect(field.unique).toBe(true);
|
||||
expect(field.index).toBe(true);
|
||||
});
|
||||
|
||||
it("accepts a custom field name", () => {
|
||||
const field = slugField("permalink");
|
||||
if (field.type !== "text") throw new Error("expected text field");
|
||||
expect(field.name).toBe("permalink");
|
||||
});
|
||||
});
|
||||
11
packages/core-shared/src/payload/fields/slug-field.ts
Normal file
11
packages/core-shared/src/payload/fields/slug-field.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import type { Field } from "payload";
|
||||
|
||||
export function slugField(name = "slug"): Field {
|
||||
return {
|
||||
name,
|
||||
type: "text",
|
||||
required: true,
|
||||
unique: true,
|
||||
index: true,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user