Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions apps/dev/src/app/(payload)/admin/importMap.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { afterAll, beforeAll, describe, expect, it } from "vitest";

import { bootTestPayload } from "./bootTestPayload";
import type { TestPayload } from "./bootTestPayload";

// bootTestPayload caches one Payload per process, so a boot with different options needs its own file.

const tr = (locale: string, text: string) => `${locale}:${text}`;

describe("what auto-translate still does to a field nobody edited", () => {
let auto: TestPayload;

beforeAll(async () => {
auto = await bootTestPayload({ autoTranslate: { targets: ["de"] } });
});
afterAll(async () => {
await auto?.cleanup();
});

it("still overwrites a hand-corrected target when a sibling's source changes (overwrite, the default)", async () => {
const made = await auto.payload.create({
collection: "docs",
locale: "en",
data: { _status: "published", title: "Auto title", note: "Auto note" },
});
const id = String(made.id);

await auto.payload.update({
collection: "docs",
id,
locale: "de",
data: { _status: "published", title: "KORRIGIERT" },
});
await auto.payload.update({
collection: "docs",
id,
locale: "en",
data: { _status: "published", title: "Auto title", note: "Auto note, rewritten" },
});

const de = (await auto.payload.findByID({ collection: "docs", id, locale: "de" })) as Record<
string,
unknown
>;
expect(de.note).toBe(tr("de", "Auto note, rewritten"));
expect(de.title, "the correction is lost — this is the limitation, not the fix").toBe(
tr("de", "Auto title")
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { afterAll, beforeAll, describe, expect, it } from "vitest";

import { bootTestPayload } from "./bootTestPayload";
import type { TestPayload } from "./bootTestPayload";

// bootTestPayload caches one Payload per process, so a boot with different options needs its own file.

const tr = (locale: string, text: string) => `${locale}:${text}`;

describe("auto-translate on a collection that chose skip_existing", () => {
let auto: TestPayload;

beforeAll(async () => {
auto = await bootTestPayload({
autoTranslate: { targets: ["de"], strategy: "skip_existing" },
});
});
afterAll(async () => {
await auto?.cleanup();
});

it("refreshes the leaf whose source moved and leaves a hand correction alone", async () => {
const made = await auto.payload.create({
collection: "docs",
locale: "en",
data: { _status: "published", title: "Skip title", note: "Skip note" },
});
const id = String(made.id);

await auto.payload.update({
collection: "docs",
id,
locale: "de",
data: { _status: "published", title: "KORRIGIERT" },
});
await auto.payload.update({
collection: "docs",
id,
locale: "en",
data: { _status: "published", title: "Skip title", note: "Skip note, rewritten" },
});

const de = (await auto.payload.findByID({ collection: "docs", id, locale: "de" })) as Record<
string,
unknown
>;
expect(de.note, "its source moved").toBe(tr("de", "Skip note, rewritten"));
expect(de.title, "its source did not — and here the strategy is honoured").toBe("KORRIGIERT");
});
});
118 changes: 118 additions & 0 deletions apps/dev/src/integration/translator/hand-edit-in-a-draft.int.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { afterAll, beforeAll, describe, expect, it } from "vitest";

import { bootTestPayload } from "./bootTestPayload";
import type { TestPayload } from "./bootTestPayload";
import { callEndpoint } from "./callEndpoint";

let ctx: TestPayload;

const translate = (
id: string,
strategy: "overwrite" | "skip_existing",
{ publish }: { publish: boolean }
) =>
callEndpoint(ctx.payload, "post", "/translate/enqueue", {
body: {
source_lng: "en",
target_lng: "de",
collection_slug: "docs",
collection_id: [id],
strategy,
publish_on_translation: publish,
},
});

const germanDraft = (id: string) =>
ctx.payload.findByID({
collection: "docs",
id,
locale: "de",
draft: true,
}) as Promise<Record<string, unknown>>;

describe("a hand edit saved as a draft, then re-translated with skip_existing", () => {
beforeAll(async () => {
ctx = await bootTestPayload();
});
afterAll(async () => {
await ctx?.cleanup();
});

it("survives when the translation was published", async () => {
const made = await ctx.payload.create({
collection: "docs",
locale: "en",
data: { _status: "published", title: "Source title", note: "Source note" },
});
const id = String(made.id);

await translate(id, "overwrite", { publish: true });
await ctx.payload.update({
collection: "docs",
id,
locale: "de",
data: { title: "de:Source title — PLUS MEINE WORTE" },
draft: true,
});

await translate(id, "skip_existing", { publish: false });

expect((await germanDraft(id)).title).toBe("de:Source title — PLUS MEINE WORTE");
});

it("survives when the translation was left as a draft", async () => {
const made = await ctx.payload.create({
collection: "docs",
locale: "en",
data: { _status: "published", title: "Draft title", note: "Draft note" },
});
const id = String(made.id);

await translate(id, "overwrite", { publish: false });
await ctx.payload.update({
collection: "docs",
id,
locale: "de",
data: { title: "de:Draft title — PLUS MEINE WORTE" },
draft: true,
});

await translate(id, "skip_existing", { publish: false });

expect((await germanDraft(id)).title).toBe("de:Draft title — PLUS MEINE WORTE");
});

it("survives when ANOTHER English field is edited to make the document stale", async () => {
const made = await ctx.payload.create({
collection: "docs",
locale: "en",
data: { _status: "published", title: "Stale title", note: "Stale note" },
});
const id = String(made.id);

await translate(id, "overwrite", { publish: false });

await ctx.payload.update({
collection: "docs",
id,
locale: "de",
data: { title: "de:Stale title — PLUS MEINE WORTE" },
draft: true,
});

await ctx.payload.update({
collection: "docs",
id,
locale: "en",
data: { _status: "published", title: "Stale title", note: "Stale note, rewritten" },
});

await translate(id, "skip_existing", { publish: false });

const de = await germanDraft(id);
expect(de.note, "its source moved").toBe("de:Stale note, rewritten");
expect(de.title, "its source did NOT move — the hand edit must stand").toBe(
"de:Stale title — PLUS MEINE WORTE"
);
});
});
Loading
Loading