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
5 changes: 5 additions & 0 deletions .changeset/yummy-socks-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@saleor/app-sdk": patch
---

Added missing seoName and seoDescriptiont to formPayload action
119 changes: 113 additions & 6 deletions src/app-bridge/app-bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
AppBridge,
DashboardEventFactory,
DispatchResponseEvent,
FormPayloadProductEdit,
FormPayloadProductTranslate,
HandshakeEvent,
ThemeEvent,
} from ".";
Expand Down Expand Up @@ -330,7 +332,7 @@ describe("AppBridge", () => {
it("Updates state with form context when form payload event is received", () => {
expect(appBridge.getState().formContext).toEqual({});

const formPayload = {
const formPayload: FormPayloadProductTranslate = {
form: "product-translate" as const,
productId: "product-123",
translationLanguage: "es",
Expand All @@ -343,6 +345,27 @@ describe("AppBridge", () => {
currentValue: "Original Product",
type: "short-text" as const,
},
productDescription: {
fieldName: "",
originalValue: "",
translatedValue: "",
currentValue: "",
type: "short-text",
},
seoName: {
fieldName: "",
originalValue: "",
translatedValue: "",
currentValue: "",
type: "short-text",
},
seoDescription: {
fieldName: "",
originalValue: "",
translatedValue: "",
currentValue: "",
type: "short-text",
},
},
};

Expand Down Expand Up @@ -373,7 +396,7 @@ describe("AppBridge", () => {

expect(callback).not.toHaveBeenCalled();

const formPayload = {
const formPayload: FormPayloadProductTranslate = {
form: "product-translate" as const,
productId: "product-456",
translationLanguage: "fr",
Expand All @@ -386,6 +409,27 @@ describe("AppBridge", () => {
currentValue: "Description",
type: "editorjs" as const,
},
productName: {
fieldName: "",
originalValue: "",
translatedValue: "",
currentValue: "",
type: "short-text",
},
seoName: {
fieldName: "",
originalValue: "",
translatedValue: "",
currentValue: "",
type: "short-text",
},
seoDescription: {
fieldName: "",
originalValue: "",
translatedValue: "",
currentValue: "",
type: "short-text",
},
},
};

Expand Down Expand Up @@ -435,7 +479,7 @@ describe("AppBridge", () => {
});

it("Updates form context with new fields when multiple form events are received", () => {
const firstFormPayload = {
const firstFormPayload: FormPayloadProductTranslate = {
form: "product-translate" as const,
productId: "product-1",
translationLanguage: "es",
Expand All @@ -448,6 +492,27 @@ describe("AppBridge", () => {
currentValue: "Product 1",
type: "short-text" as const,
},
productDescription: {
fieldName: "",
originalValue: "",
translatedValue: "",
currentValue: "",
type: "short-text",
},
seoName: {
fieldName: "",
originalValue: "",
translatedValue: "",
currentValue: "",
type: "short-text",
},
seoDescription: {
fieldName: "",
originalValue: "",
translatedValue: "",
currentValue: "",
type: "short-text",
},
},
};

Expand All @@ -461,7 +526,7 @@ describe("AppBridge", () => {

expect(appBridge.getState().formContext?.["product-translate"]?.productId).toBe("product-1");

const secondFormPayload = {
const secondFormPayload: FormPayloadProductTranslate = {
form: "product-translate" as const,
productId: "product-2",
translationLanguage: "fr",
Expand All @@ -474,6 +539,27 @@ describe("AppBridge", () => {
currentValue: "Product 2",
type: "short-text" as const,
},
productDescription: {
fieldName: "",
originalValue: "",
translatedValue: "",
currentValue: "",
type: "short-text",
},
seoName: {
fieldName: "",
originalValue: "",
translatedValue: "",
currentValue: "",
type: "short-text",
},
seoDescription: {
fieldName: "",
originalValue: "",
translatedValue: "",
currentValue: "",
type: "short-text",
},
},
};

Expand All @@ -497,7 +583,7 @@ describe("AppBridge", () => {
it("Stores multiple form contexts for different form types simultaneously", () => {
expect(appBridge.getState().formContext).toEqual({});

const productTranslatePayload = {
const productTranslatePayload: FormPayloadProductTranslate = {
form: "product-translate" as const,
productId: "product-123",
translationLanguage: "es",
Expand All @@ -510,10 +596,31 @@ describe("AppBridge", () => {
currentValue: "Original Product",
type: "short-text" as const,
},
productDescription: {
fieldName: "",
originalValue: "",
translatedValue: "",
currentValue: "",
type: "editorjs",
},
seoName: {
fieldName: "",
originalValue: "",
translatedValue: "",
currentValue: "",
type: "short-text",
},
seoDescription: {
fieldName: "",
originalValue: "",
translatedValue: "",
currentValue: "",
type: "editorjs",
},
},
};

const productEditPayload = {
const productEditPayload: FormPayloadProductEdit = {
form: "product-edit" as const,
productId: "product-456",
fields: {
Expand Down
51 changes: 17 additions & 34 deletions src/app-bridge/events.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { describe, expect, it } from "vitest";

import { FormPayloadProductTranslate } from "@/app-bridge/form-payload";

import { DashboardEventFactory } from "./events";

describe("DashboardEventFactory", () => {
Expand Down Expand Up @@ -67,7 +69,7 @@ describe("DashboardEventFactory", () => {
});

it("Creates form payload event for product translation", () => {
const formPayload = {
const formPayload: FormPayloadProductTranslate = {
form: "product-translate" as const,
productId: "product-123",
translationLanguage: "es",
Expand All @@ -87,6 +89,20 @@ describe("DashboardEventFactory", () => {
currentValue: "Original description",
type: "editorjs" as const,
},
seoName: {
fieldName: "",
originalValue: "",
translatedValue: "",
currentValue: "",
type: "short-text",
},
seoDescription: {
fieldName: "",
originalValue: "",
translatedValue: "",
currentValue: "",
type: "short-text",
},
},
};

Expand All @@ -95,37 +111,4 @@ describe("DashboardEventFactory", () => {
payload: formPayload,
});
});

it("Creates form payload event with all translation field types", () => {
const formPayload = {
form: "product-translate" as const,
productId: "product-456",
translationLanguage: "fr",
currentLanguage: "en",
fields: {
shortTextField: {
fieldName: "shortTextField",
originalValue: "Short text",
translatedValue: "Texte court",
currentValue: "Short text",
type: "short-text" as const,
},
editorField: {
fieldName: "editorField",
originalValue: "{\"blocks\": []}",
translatedValue: "{\"blocks\": []}",
currentValue: "{\"blocks\": []}",
type: "editorjs" as const,
},
},
};

const event = DashboardEventFactory.createFormEvent(formPayload);

expect(event.type).toBe("formPayload");
if (event.payload.form === "product-translate") {
expect(event.payload.fields.shortTextField.type).toBe("short-text");
expect(event.payload.fields.editorField.type).toBe("editorjs");
}
});
});
5 changes: 4 additions & 1 deletion src/app-bridge/form-payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ type TranslationField = {
type TranslationPayloadBase = {
translationLanguage: string;
currentLanguage: string;
fields: Record<string, TranslationField>;
};

export type FormPayloadProductTranslate = TranslationPayloadBase &
ProductPayloadBase & {
form: "product-translate";
fields: Record<
"productName" | "productDescription" | "seoName" | "seoDescription",
TranslationField
>;
};

export type FormPayloadUpdatePayloadProductTranslate = BaseFormPayloadUpdatePayload & {
Expand Down
Loading