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
54 changes: 0 additions & 54 deletions docs/api/classes/FragmentSwapExtensionService.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)\>
Expand Down Expand Up @@ -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`
Expand Down
26 changes: 2 additions & 24 deletions docs/api/interfaces/FragmentSwapExtensionApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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`
Expand Down
47 changes: 0 additions & 47 deletions src/services/fragment-swap-extension-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Experience>;
getGenerationContext: () => Promise<GenerationContext>;
setSwapValue: (value: string) => void;
Expand All @@ -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
Expand Down
93 changes: 0 additions & 93 deletions tests/services/fragment-swap-extension-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand Down Expand Up @@ -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
Expand Down
Loading