-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
12180 default section for component config (#12232)
* initial commit * adding header stuff * test * Moving datamodel button * Addig component for handling edit id * Moving the content * deleting console.log * removing broken tests * adding one test * adding properties header tests * writing more tests * fixing feecback from PR
- Loading branch information
WilliamThorenfeldt
authored
Feb 9, 2024
1 parent
97fef76
commit e6b8382
Showing
22 changed files
with
401 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...c/components/Properties/PropertiesHeader/DataModelBindingRow/DataModelBindingRow.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import React from 'react'; | ||
import { act, screen } from '@testing-library/react'; | ||
import { DataModelBindingRow, type DataModelBindingRowProps } from './DataModelBindingRow'; | ||
import { FormContext } from '../../../../containers/FormContext'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { formContextProviderMock } from '../../../../testing/formContextMocks'; | ||
import { component1Mock, component1IdMock } from '../../../../testing/layoutMock'; | ||
import { renderWithProviders } from '../../../../testing/mocks'; | ||
import { textMock } from '../../../../../../../testing/mocks/i18nMock'; | ||
|
||
const mockSchema = { | ||
properties: { | ||
dataModelBindings: { | ||
properties: { | ||
simpleBinding: { | ||
description: 'Description for simpleBinding', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const mockSchemaUndefined = { | ||
properties: { | ||
dataModelBindings: { | ||
properties: undefined, | ||
}, | ||
}, | ||
}; | ||
|
||
const mockHandleComponentUpdate = jest.fn(); | ||
|
||
const defaultProps: DataModelBindingRowProps = { | ||
schema: mockSchema, | ||
component: component1Mock, | ||
formId: component1IdMock, | ||
handleComponentUpdate: mockHandleComponentUpdate, | ||
}; | ||
|
||
describe('DataModelBindingRow', () => { | ||
afterEach(jest.clearAllMocks); | ||
|
||
it('renders EditDataModelBindings component when schema is present', () => { | ||
renderProperties({ form: component1Mock, formId: component1IdMock }); | ||
|
||
const datamodelButton = screen.getByRole('button', { | ||
name: textMock('ux_editor.modal_properties_data_model_link'), | ||
}); | ||
expect(datamodelButton).toBeInTheDocument(); | ||
}); | ||
|
||
it('does not render EditDataModelBindings component when schema.properties is undefined', () => { | ||
renderProperties( | ||
{ form: component1Mock, formId: component1IdMock }, | ||
{ schema: mockSchemaUndefined }, | ||
); | ||
|
||
const datamodelButton = screen.queryByRole('button', { | ||
name: textMock('ux_editor.modal_properties_data_model_link'), | ||
}); | ||
expect(datamodelButton).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('calls handleComponentUpdate when EditDataModelBindings component is updated', async () => { | ||
const user = userEvent.setup(); | ||
renderProperties({ form: component1Mock, formId: component1IdMock }); | ||
|
||
const datamodelButton = screen.getByRole('button', { | ||
name: textMock('ux_editor.modal_properties_data_model_link'), | ||
}); | ||
expect( | ||
screen.queryByRole('button', { name: textMock('general.delete') }), | ||
).not.toBeInTheDocument(); | ||
|
||
await act(() => user.click(datamodelButton)); | ||
|
||
const deleteButton = screen.getByRole('button', { | ||
name: textMock('general.delete'), | ||
}); | ||
expect(deleteButton).toBeInTheDocument(); | ||
|
||
await act(() => user.click(deleteButton)); | ||
expect(mockHandleComponentUpdate).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
const renderProperties = ( | ||
formContextProps: Partial<FormContext> = {}, | ||
props: Partial<DataModelBindingRowProps> = {}, | ||
) => { | ||
return renderWithProviders( | ||
<FormContext.Provider | ||
value={{ | ||
...formContextProviderMock, | ||
...formContextProps, | ||
}} | ||
> | ||
<DataModelBindingRow {...defaultProps} {...props} /> | ||
</FormContext.Provider>, | ||
); | ||
}; |
41 changes: 41 additions & 0 deletions
41
...or/src/components/Properties/PropertiesHeader/DataModelBindingRow/DataModelBindingRow.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React from 'react'; | ||
import { EditDataModelBindings } from '../../../config/editModal/EditDataModelBindings'; | ||
import type { FormComponent } from '../../../../types/FormComponent'; | ||
|
||
export type DataModelBindingRowProps = { | ||
schema: any; | ||
component: FormComponent; | ||
formId: string; | ||
handleComponentUpdate: (component: FormComponent) => void; | ||
}; | ||
|
||
export const DataModelBindingRow = ({ | ||
schema, | ||
component, | ||
formId, | ||
handleComponentUpdate, | ||
}: DataModelBindingRowProps): React.JSX.Element => { | ||
const { dataModelBindings } = schema.properties; | ||
|
||
return ( | ||
dataModelBindings?.properties && ( | ||
<> | ||
{Object.keys(dataModelBindings?.properties).map((propertyKey: string) => { | ||
return ( | ||
<EditDataModelBindings | ||
key={`${component.id}-datamodel-${propertyKey}`} | ||
component={component} | ||
handleComponentChange={handleComponentUpdate} | ||
editFormId={formId} | ||
helpText={dataModelBindings?.properties[propertyKey]?.description} | ||
renderOptions={{ | ||
key: propertyKey, | ||
label: propertyKey !== 'simpleBinding' ? propertyKey : undefined, | ||
}} | ||
/> | ||
); | ||
})} | ||
</> | ||
) | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
...ackages/ux-editor/src/components/Properties/PropertiesHeader/DataModelBindingRow/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { DataModelBindingRow } from './DataModelBindingRow'; |
14 changes: 7 additions & 7 deletions
14
...ents/config/editModal/EditComponentId.tsx → ...EditComponentIdRow/EditComponentIdRow.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...packages/ux-editor/src/components/Properties/PropertiesHeader/EditComponentIdRow/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { EditComponentIdRow } from './EditComponentIdRow'; |
Oops, something went wrong.