Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EDT-1549] set/resetPlaceholder methods #480

27 changes: 27 additions & 0 deletions packages/sdk/src/controllers/VariableController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,33 @@ export class VariableController {
return res.setVariableLabel(id, label).then((result) => getEditorResponseData<null>(result));
};

/**
* Internal private method to set/reset a placeholder for a variable
*/
private setPlaceholderInternal = async (id: string, placeholder: string | null) => {
const res = await this.#editorAPI;
return res.setVariablePlaceholder(id, placeholder).then((result) => getEditorResponseData<null>(result));
};

/**
* This method sets a new placeholder for a variable
* @param id id of the variable
* @param placeholder placeholder of the variable
* @returns
*/
setPlaceholder = async (id: string, placeholder: string) => {
return this.setPlaceholderInternal(id, placeholder);
};

/**
* This method resets a placeholder for a variable
* @param id id of the variable
* @returns
*/
resetPlaceholder = async (id: string) => {
return this.setPlaceholderInternal(id, null);
};

/**
* This method sets a new type for a variable
* @param id id of the variable
Expand Down
14 changes: 14 additions & 0 deletions packages/sdk/src/tests/controllers/VariableController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('VariableController', () => {
addVariable: async () => getEditorResponseData(castToEditorResponse(null)),
removeVariables: async () => getEditorResponseData(castToEditorResponse(null)),
setVariableLabel: async () => getEditorResponseData(castToEditorResponse(null)),
setVariablePlaceholder: async () => getEditorResponseData(castToEditorResponse(null)),
setVariableType: async () => getEditorResponseData(castToEditorResponse(null)),
setListVariableItems: async () => getEditorResponseData(castToEditorResponse(null)),
setVariableValue: async () => getEditorResponseData(castToEditorResponse(null)),
Expand Down Expand Up @@ -89,6 +90,7 @@ describe('VariableController', () => {
jest.spyOn(mockEditorApi, 'addVariable');
jest.spyOn(mockEditorApi, 'removeVariables');
jest.spyOn(mockEditorApi, 'setVariableLabel');
jest.spyOn(mockEditorApi, 'setVariablePlaceholder');
jest.spyOn(mockEditorApi, 'setVariableType');
jest.spyOn(mockEditorApi, 'setListVariableItems');
jest.spyOn(mockEditorApi, 'setVariableValue');
Expand Down Expand Up @@ -155,6 +157,18 @@ describe('VariableController', () => {
expect(mockEditorApi.setVariableLabel).toHaveBeenCalledWith('3', 'newLabel');
});

it('set variable placeholder', async () => {
await mockedVariableController.setPlaceholder('3', 'newPlaceholder');
expect(mockEditorApi.setVariablePlaceholder).toHaveBeenCalledTimes(1);
expect(mockEditorApi.setVariablePlaceholder).toHaveBeenCalledWith('3', 'newPlaceholder');
});

it('reset variable placeholder', async () => {
await mockedVariableController.resetPlaceholder('3');
expect(mockEditorApi.setVariablePlaceholder).toHaveBeenCalledTimes(1);
expect(mockEditorApi.setVariablePlaceholder).toHaveBeenCalledWith('3', null);
});

it('set variable type', async () => {
await mockedVariableController.setType('3', VariableType.group);
expect(mockEditorApi.setVariableType).toHaveBeenCalledTimes(1);
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/types/VariableTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface Variable {
isReadonly: boolean;
isRequired: boolean;
occurrences: number;
placeholder?: string | null;
}

export interface ImageVariable extends Variable {
Expand Down
Loading