diff --git a/docs/api/classes/FragmentSwapExtensionService.md b/docs/api/classes/FragmentSwapExtensionService.md index cc8a3e8..60a6b29 100644 --- a/docs/api/classes/FragmentSwapExtensionService.md +++ b/docs/api/classes/FragmentSwapExtensionService.md @@ -20,30 +20,6 @@ Manages swap field extension functionality for swapping field content ## Methods -### close() - -> `static` **close**(`connection`: `any`): `void` - -Closes the swap field extension dialog - -#### Parameters - -##### connection - -`any` - -The guest connection to the host - -#### Returns - -`void` - -#### Throws - -Error if connection is missing - -*** - ### getExperience() > `static` **getExperience**(`connection`: `any`): `Promise`\<[`Experience`](../interfaces/Experience.md)\> @@ -96,36 +72,6 @@ Error if connection is missing *** -### open() - -> `static` **open**(`connection`: `any`, `extensionId`: `string`): `void` - -Opens the swap field extension dialog - -#### Parameters - -##### connection - -`any` - -The guest connection to the host - -##### extensionId - -`string` - -The ID of the extension to open - -#### Returns - -`void` - -#### Throws - -Error if connection is missing - -*** - ### setSwapValue() > `static` **setSwapValue**(`connection`: `any`, `value`: `string`): `void` diff --git a/docs/api/interfaces/FragmentSwapExtensionApi.md b/docs/api/interfaces/FragmentSwapExtensionApi.md index 9b0d9b7..861a939 100644 --- a/docs/api/interfaces/FragmentSwapExtensionApi.md +++ b/docs/api/interfaces/FragmentSwapExtensionApi.md @@ -18,19 +18,11 @@ ### api -> **api**: \{ `fragmentSwapExtension`: \{ `close`: () => `void`; `getExperience`: () => `Promise`\<[`Experience`](Experience.md)\>; `getGenerationContext`: () => `Promise`\<[`GenerationContext`](../type-aliases/GenerationContext.md)\>; `open`: (`extensionId`: `string`) => `void`; `setSwapValue`: (`value`: `string`) => `void`; \}; \} +> **api**: \{ `fragmentSwapExtension`: \{ `getExperience`: () => `Promise`\<[`Experience`](Experience.md)\>; `getGenerationContext`: () => `Promise`\<[`GenerationContext`](../type-aliases/GenerationContext.md)\>; `setSwapValue`: (`value`: `string`) => `void`; \}; \} #### fragmentSwapExtension -> **fragmentSwapExtension**: \{ `close`: () => `void`; `getExperience`: () => `Promise`\<[`Experience`](Experience.md)\>; `getGenerationContext`: () => `Promise`\<[`GenerationContext`](../type-aliases/GenerationContext.md)\>; `open`: (`extensionId`: `string`) => `void`; `setSwapValue`: (`value`: `string`) => `void`; \} - -##### fragmentSwapExtension.close() - -> **close**: () => `void` - -###### Returns - -`void` +> **fragmentSwapExtension**: \{ `getExperience`: () => `Promise`\<[`Experience`](Experience.md)\>; `getGenerationContext`: () => `Promise`\<[`GenerationContext`](../type-aliases/GenerationContext.md)\>; `setSwapValue`: (`value`: `string`) => `void`; \} ##### fragmentSwapExtension.getExperience() @@ -48,20 +40,6 @@ `Promise`\<[`GenerationContext`](../type-aliases/GenerationContext.md)\> -##### fragmentSwapExtension.open() - -> **open**: (`extensionId`: `string`) => `void` - -###### Parameters - -###### extensionId - -`string` - -###### Returns - -`void` - ##### fragmentSwapExtension.setSwapValue() > **setSwapValue**: (`value`: `string`) => `void` diff --git a/src/services/fragment-swap-extension-service.ts b/src/services/fragment-swap-extension-service.ts index e49546c..40b9a1e 100644 --- a/src/services/fragment-swap-extension-service.ts +++ b/src/services/fragment-swap-extension-service.ts @@ -17,8 +17,6 @@ import { GenerationContext } from "../types/generationContext/GenerationContext" export interface FragmentSwapExtensionApi extends VirtualApi { api: { fragmentSwapExtension: { - open: (extensionId: string) => void; - close: () => void; getExperience: () => Promise; getGenerationContext: () => Promise; setSwapValue: (value: string) => void; @@ -37,51 +35,6 @@ export class FragmentSwapExtensionServiceError extends Error { * Manages swap field extension functionality for swapping field content */ export class FragmentSwapExtensionService { - /** - * Opens the swap field extension dialog - * @param connection - The guest connection to the host - * @param extensionId - The ID of the extension to open - * @throws Error if connection is missing - */ - static open(connection: any, extensionId: string): void { - if (!connection) { - throw new FragmentSwapExtensionServiceError( - "Connection is required to open swap field extension", - ); - } - - try { - // @ts-ignore Remote API is handled through postMessage - connection.host.api.fragmentSwapExtension.open(extensionId); - } catch (error) { - throw new FragmentSwapExtensionServiceError( - "Failed to open swap field extension", - ); - } - } - - /** - * Closes the swap field extension dialog - * @param connection - The guest connection to the host - * @throws Error if connection is missing - */ - static close(connection: any): void { - if (!connection) { - throw new FragmentSwapExtensionServiceError( - "Connection is required to close fragment swap extension", - ); - } - - try { - // @ts-ignore Remote API is handled through postMessage - connection.host.api.fragmentSwapExtension.close(); - } catch (error) { - throw new FragmentSwapExtensionServiceError( - "Failed to close fragment swap extension", - ); - } - } - /** * Gets the current field context from the host * @param connection - The guest connection to the host diff --git a/tests/services/fragment-swap-extension-service.test.ts b/tests/services/fragment-swap-extension-service.test.ts index ceb3ef8..7ad525f 100644 --- a/tests/services/fragment-swap-extension-service.test.ts +++ b/tests/services/fragment-swap-extension-service.test.ts @@ -19,16 +19,12 @@ import { GuestUI } from "@adobe/uix-guest"; import { GenerationContext } from "../../src/types/generationContext/GenerationContext"; type ConnectionMocks = { - openMock?: jest.Mock; - closeMock?: jest.Mock; getExperienceMock?: jest.Mock; getGenerationContextMock?: jest.Mock; setSwapValueMock?: jest.Mock; }; const createMockConnection = ({ - openMock, - closeMock, getExperienceMock, getGenerationContextMock, setSwapValueMock, @@ -37,8 +33,6 @@ const createMockConnection = ({ host: { api: { fragmentSwapExtension: { - open: openMock || jest.fn(), - close: closeMock || jest.fn(), getExperience: getExperienceMock || jest.fn(), getGenerationContext: getGenerationContextMock || jest.fn(), setSwapValue: setSwapValueMock || jest.fn(), @@ -79,93 +73,6 @@ describe("FragmentSwapExtensionService", () => { userPrompt: "test-user-prompt", }; - describe("open", () => { - it("should open fragment swap extension successfully", () => { - const mockOpen = jest.fn(); - const mockConnection = createMockConnection({ openMock: mockOpen }); - const extensionId = "test-extension-id"; - - FragmentSwapExtensionService.open(mockConnection, extensionId); - - expect(mockOpen).toHaveBeenCalledWith(extensionId); - expect(mockOpen).toHaveBeenCalledTimes(1); - }); - - it("should throw FragmentSwapExtensionServiceError if connection is missing", () => { - const extensionId = "test-extension-id"; - - // @ts-ignore Testing null case explicitly - expect(() => FragmentSwapExtensionService.open(null, extensionId)).toThrow( - FragmentSwapExtensionServiceError, - ); - // @ts-ignore Testing null case explicitly - expect(() => FragmentSwapExtensionService.open(null, extensionId)).toThrow( - "Connection is required to open swap field extension", - ); - }); - - it("should throw FragmentSwapExtensionServiceError on API failure", () => { - const mockOpen = jest.fn().mockImplementation(() => { - throw new Error("API Error"); - }); - const mockConnection = createMockConnection({ openMock: mockOpen }); - const extensionId = "test-extension-id"; - - expect(() => - FragmentSwapExtensionService.open(mockConnection, extensionId), - ).toThrow(FragmentSwapExtensionServiceError); - expect(() => - FragmentSwapExtensionService.open(mockConnection, extensionId), - ).toThrow("Failed to open swap field extension"); - }); - - it("should handle empty extensionId", () => { - const mockOpen = jest.fn(); - const mockConnection = createMockConnection({ openMock: mockOpen }); - const extensionId = ""; - - FragmentSwapExtensionService.open(mockConnection, extensionId); - - expect(mockOpen).toHaveBeenCalledWith(extensionId); - }); - }); - - describe("close", () => { - it("should close fragment swap extension successfully", () => { - const mockClose = jest.fn(); - const mockConnection = createMockConnection({ closeMock: mockClose }); - - FragmentSwapExtensionService.close(mockConnection); - - expect(mockClose).toHaveBeenCalledTimes(1); - }); - - it("should throw FragmentSwapExtensionServiceError if connection is missing", () => { - // @ts-ignore Testing null case explicitly - expect(() => FragmentSwapExtensionService.close(null)).toThrow( - FragmentSwapExtensionServiceError, - ); - // @ts-ignore Testing null case explicitly - expect(() => FragmentSwapExtensionService.close(null)).toThrow( - "Connection is required to close fragment swap extension", - ); - }); - - it("should throw FragmentSwapExtensionServiceError on API failure", () => { - const mockClose = jest.fn().mockImplementation(() => { - throw new Error("API Error"); - }); - const mockConnection = createMockConnection({ closeMock: mockClose }); - - expect(() => - FragmentSwapExtensionService.close(mockConnection), - ).toThrow(FragmentSwapExtensionServiceError); - expect(() => - FragmentSwapExtensionService.close(mockConnection), - ).toThrow("Failed to close fragment swap extension"); - }); - }); - describe("getExperience", () => { it("should fetch experience", async () => { const mockGetExperience = jest