-
-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Custom Data and Custom Fields (#1096)
* save ppf admin changes * fixed failing tests * restoring EventCard test * coverage increase * increased coverage some more * increase orgprofilefieldsettings' coverage
- Loading branch information
Showing
16 changed files
with
653 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
60 changes: 60 additions & 0 deletions
60
src/components/EditCustomFieldDropDown/EditCustomFieldDropDown.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,60 @@ | ||
import type { Dispatch, SetStateAction } from 'react'; | ||
import React from 'react'; | ||
import { act, render } from '@testing-library/react'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import EditOrgCustomFieldDropDown from './EditCustomFieldDropDown'; | ||
import type { InterfaceCustomFieldData } from 'components/OrgProfileFieldSettings/OrgProfileFieldSettings'; | ||
import userEvent from '@testing-library/user-event'; | ||
import availableFieldTypes from 'utils/fieldTypes'; | ||
|
||
async function wait(ms = 100): Promise<void> { | ||
await act(() => { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, ms); | ||
}); | ||
}); | ||
} | ||
|
||
describe('Testing Custom Field Dropdown', () => { | ||
test('Component Should be rendered properly', async () => { | ||
const customFieldData = { | ||
type: 'Number', | ||
name: 'Age', | ||
}; | ||
|
||
const setCustomFieldData: Dispatch< | ||
SetStateAction<InterfaceCustomFieldData> | ||
> = (val) => { | ||
{ | ||
val; | ||
} | ||
}; | ||
const props = { | ||
customFieldData: customFieldData as InterfaceCustomFieldData, | ||
setCustomFieldData: setCustomFieldData, | ||
parentContainerStyle: 'parentContainerStyle', | ||
btnStyle: 'btnStyle', | ||
btnTextStyle: 'btnTextStyle', | ||
}; | ||
|
||
const { getByTestId, getByText } = render( | ||
<BrowserRouter> | ||
<EditOrgCustomFieldDropDown {...props} /> | ||
</BrowserRouter> | ||
); | ||
|
||
expect(getByText('Number')).toBeInTheDocument(); | ||
|
||
act(() => { | ||
userEvent.click(getByTestId('toggleBtn')); | ||
}); | ||
|
||
await wait(); | ||
|
||
availableFieldTypes.forEach(async (_, index) => { | ||
act(() => { | ||
userEvent.click(getByTestId(`dropdown-btn-${index}`)); | ||
}); | ||
}); | ||
}); | ||
}); |
53 changes: 53 additions & 0 deletions
53
src/components/EditCustomFieldDropDown/EditCustomFieldDropDown.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,53 @@ | ||
import React from 'react'; | ||
import type { SetStateAction, Dispatch } from 'react'; | ||
import { Dropdown } from 'react-bootstrap'; | ||
import availableFieldTypes from 'utils/fieldTypes'; | ||
import type { InterfaceCustomFieldData } from 'components/OrgProfileFieldSettings/OrgProfileFieldSettings'; | ||
|
||
interface InterfaceEditCustomFieldDropDownProps { | ||
customFieldData: InterfaceCustomFieldData; | ||
setCustomFieldData: Dispatch<SetStateAction<InterfaceCustomFieldData>>; | ||
parentContainerStyle?: string; | ||
btnStyle?: string; | ||
btnTextStyle?: string; | ||
} | ||
[]; | ||
|
||
const EditOrgCustomFieldDropDown = ( | ||
props: InterfaceEditCustomFieldDropDownProps | ||
): JSX.Element => { | ||
return ( | ||
<Dropdown | ||
title="Edit Custom Field" | ||
className={`${props?.parentContainerStyle ?? ''}`} | ||
> | ||
<Dropdown.Toggle | ||
variant="outline-success" | ||
className={`${props?.btnStyle ?? ''}`} | ||
data-testid="toggleBtn" | ||
> | ||
{props.customFieldData.type || 'None'} | ||
</Dropdown.Toggle> | ||
<Dropdown.Menu> | ||
{availableFieldTypes.map((customFieldType, index: number) => ( | ||
<Dropdown.Item | ||
key={`dropdown-item-${index}`} | ||
className={`dropdown-item`} | ||
data-testid={`dropdown-btn-${index}`} | ||
onClick={(): void => { | ||
props.setCustomFieldData({ | ||
...props.customFieldData, | ||
type: customFieldType, | ||
}); | ||
}} | ||
disabled={props.customFieldData.type == customFieldType} | ||
> | ||
{customFieldType} | ||
</Dropdown.Item> | ||
))} | ||
</Dropdown.Menu> | ||
</Dropdown> | ||
); | ||
}; | ||
|
||
export default EditOrgCustomFieldDropDown; |
24 changes: 24 additions & 0 deletions
24
src/components/OrgProfileFieldSettings/OrgProfileFieldSettings.module.css
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,24 @@ | ||
.customDataTable { | ||
width: 100%; | ||
border-collapse: collapse; | ||
} | ||
|
||
.customDataTable th, | ||
.customDataTable td { | ||
padding: 8px; | ||
text-align: left; | ||
} | ||
|
||
.customDataTable th { | ||
background-color: #f2f2f2; | ||
} | ||
form { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 10px; | ||
} | ||
|
||
.saveButton { | ||
width: 10em; | ||
align-self: self-end; | ||
} |
Oops, something went wrong.