Skip to content

Commit 2abb8ce

Browse files
Georgi2704Georgi2704
andauthored
Changes needed for the cim send email form wizard (#821)
* Changes needed for the cim send email form wizard * Added string unit tests * Change in unit tests descriptions --------- Co-authored-by: Georgi2704 <[email protected]>
1 parent 479e7a0 commit 2abb8ce

File tree

6 files changed

+61
-21
lines changed

6 files changed

+61
-21
lines changed

packages/orchestrator-ui-components/src/api/index.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import { ProductDefinition } from '@/types';
2424

2525
import { getAxiosInstance } from './axios';
2626

27-
const CIM_FORMS_ENDPOINT = 'surf/cim/forms/';
2827
const PROCESS_ENDPOINT = 'processes/';
2928
const PRODUCTS_ENDPOINT = 'products/';
29+
const FORMS_ENDPOINT = 'surf/forms/';
3030

3131
export class BaseApiClient {
3232
private _axiosInstance: AxiosInstance;
@@ -105,14 +105,20 @@ export class BaseApiClient {
105105
};
106106
}
107107

108-
abstract class ApiClientInterface extends BaseApiClient {
109-
abstract cimStartForm: (
108+
export class ApiClient extends BaseApiClient {
109+
startForm = (
110110
formKey: string,
111111
userInputs: object[],
112-
) => Promise<object>;
113-
}
112+
): Promise<{ id: string }> => {
113+
return this.postPutJson(
114+
`${FORMS_ENDPOINT}${formKey}`,
115+
userInputs,
116+
'post',
117+
false,
118+
true,
119+
);
120+
};
114121

115-
export class ApiClient extends ApiClientInterface {
116122
startProcess = (
117123
workflowName: string,
118124
processInput: object,
@@ -142,18 +148,6 @@ export class ApiClient extends ApiClientInterface {
142148
productById = (productId: string): Promise<ProductDefinition> => {
143149
return this.fetchJson(`${PRODUCTS_ENDPOINT}${productId}`);
144150
};
145-
cimStartForm = (
146-
formKey: string,
147-
userInputs: object[],
148-
): Promise<{ id: string }> => {
149-
return this.postPutJson(
150-
`${CIM_FORMS_ENDPOINT}${formKey}`,
151-
userInputs,
152-
'post',
153-
false,
154-
true,
155-
);
156-
};
157151
prefix_filters = (): Promise<IpPrefix[]> => {
158152
return this.fetchJson('surf/ipam/prefix_filters');
159153
};

packages/orchestrator-ui-components/src/components/WfoForms/CreateForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function CreateForm(props: IProps) {
3535

3636
const submit = useCallback(
3737
(userInputs: object[]) => {
38-
return apiClient.cimStartForm(formKey, userInputs).then((form) => {
38+
return apiClient.startForm(formKey, userInputs).then((form) => {
3939
handleSubmit(form);
4040
});
4141
},
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export * from './CreateForm';
21
export * from './AutoFields';
32
export * from './UserInputForm';
43
export * from './UserInputFormWizard';
54
export * from './formFields';
5+
export * from './CreateForm';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './types';
2+
export * from './forms';

packages/orchestrator-ui-components/src/utils/string.spec.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { camelToHuman, removeSuffix, upperCaseFirstChar } from './strings';
1+
import {
2+
camelToHuman,
3+
removeSuffix,
4+
snakeToHuman,
5+
snakeToKebab,
6+
upperCaseFirstChar,
7+
} from './strings';
28

39
describe('upperCaseFirstChar()', () => {
410
it("Doesn't crash on an empty string but returns empty string", () => {
@@ -68,3 +74,33 @@ describe('camelToHuman()', () => {
6874
expect(result).toEqual('A Quick Brown Fox');
6975
});
7076
});
77+
78+
describe('snakeToHuman()', () => {
79+
it('Returns an empty string when input is an empty string', () => {
80+
const result = snakeToHuman('');
81+
expect(result).toEqual('');
82+
});
83+
it('Returns two words from a single underscore snake case word', () => {
84+
const result = snakeToHuman('hello_world');
85+
expect(result).toEqual('hello world');
86+
});
87+
it('Returns multiple words from a multiple underscore snake case word', () => {
88+
const result = snakeToHuman('quick_brown_fox');
89+
expect(result).toEqual('quick brown fox');
90+
});
91+
});
92+
93+
describe('snakeToKebab()', () => {
94+
it('Returns an empty string when input is an empty string', () => {
95+
const result = snakeToKebab('');
96+
expect(result).toEqual('');
97+
});
98+
it('Returns kebab case word from a single underscore snake case word', () => {
99+
const result = snakeToKebab('hello_world');
100+
expect(result).toEqual('hello-world');
101+
});
102+
it('Returns kebab case word from a multiple underscore snake case word', () => {
103+
const result = snakeToKebab('quick_brown_fox');
104+
expect(result).toEqual('quick-brown-fox');
105+
});
106+
});

packages/orchestrator-ui-components/src/utils/strings.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@ export const camelToHuman = (value: string): string => {
1313
const result = value.replace(/([A-Z])/g, ' $1').trimStart();
1414
return result.charAt(0).toUpperCase() + result.slice(1);
1515
};
16+
17+
export const snakeToHuman = (value: string): string => {
18+
const result = value.replace(/_/g, ' ');
19+
return result.charAt(0) + result.slice(1);
20+
};
21+
22+
export const snakeToKebab = (value: string): string => {
23+
return value.replace(/_/g, '-');
24+
};

0 commit comments

Comments
 (0)