Skip to content

Commit e9134a1

Browse files
mwclemyClement Mwimo
andauthored
feat: migrate @kyper/button and @kyper/select to MXUI and remove unused SelectionBox component
* feat: use MXUI Select component for property type manual account * added the test * added a test for property type * add the build step in ci * using TextField for select * test if selecting an option works * add required error validation test * add required prop to select --------- Co-authored-by: Clement Mwimo <clement.mwimo@mx.com>
1 parent 1612e82 commit e9134a1

3 files changed

Lines changed: 65 additions & 7 deletions

File tree

.github/workflows/build.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Build
2+
3+
on: pull_request
4+
5+
jobs:
6+
build:
7+
name: Build
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v4
13+
14+
- name: Set up NodeJS
15+
uses: actions/setup-node@v4
16+
with:
17+
node-version: 'lts/Iron'
18+
check-latest: true
19+
20+
- name: Install dependencies
21+
run: npm ci
22+
23+
- name: Build
24+
run: npm run build

src/views/manualAccount/ManualAccountForm-test.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const accountTypeButtonName: Record<number, string> = {
1919
[AccountTypes.SAVINGS]: 'Savings',
2020
[AccountTypes.LOAN]: 'Loan',
2121
[AccountTypes.CREDIT_CARD]: 'Credit Card',
22+
[AccountTypes.PROPERTY]: 'Property',
2223
}
2324

2425
const buildMockApi = (apiOverrides: Partial<typeof baseApiValue> = {}) => ({
@@ -111,6 +112,17 @@ describe('<ManualAccountForm />', () => {
111112

112113
expect(screen.getByLabelText(/interest rate/i)).toBeInTheDocument()
113114
})
115+
116+
it('renders the property type select field and allows selecting a value', async () => {
117+
const { user } = await renderManualAccountForm({ accountType: AccountTypes.PROPERTY })
118+
119+
expect(screen.getByLabelText(/property type/i)).toBeInTheDocument()
120+
121+
await user.click(screen.getByLabelText(/property type/i))
122+
await user.click(await screen.findByRole('option', { name: 'Vehicle' }))
123+
124+
expect(screen.getByRole('combobox', { name: /property type/i })).toHaveTextContent('Vehicle')
125+
})
114126
})
115127

116128
describe('Personal and Business Selection', () => {
@@ -172,6 +184,18 @@ describe('<ManualAccountForm />', () => {
172184
expect((await screen.findAllByText(/is required/i)).length).toBeGreaterThan(0)
173185
expect(mockApi.createAccount).not.toHaveBeenCalled()
174186
})
187+
188+
it('shows a required error for property type when saving without selecting a value', async () => {
189+
const { user, mockApi } = await renderManualAccountForm({
190+
accountType: AccountTypes.PROPERTY,
191+
})
192+
193+
await user.type(screen.getByLabelText(/account name/i), 'My Property')
194+
await user.click(screen.getByTestId('save-manual-account-button'))
195+
196+
expect(await screen.findByText('Property type is required')).toBeInTheDocument()
197+
expect(mockApi.createAccount).not.toHaveBeenCalled()
198+
})
175199
})
176200

177201
describe('Form Submission', () => {

src/views/manualAccount/ManualAccountForm.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import _startsWith from 'lodash/startsWith'
99
import _isEmpty from 'lodash/isEmpty'
1010

1111
import Button from '@mui/material/Button'
12+
import MenuItem from '@mui/material/MenuItem'
1213
import { Text } from '@mxenabled/mxui'
1314
import { MessageBox } from '@kyper/messagebox'
1415
import { useTokens } from '@kyper/tokenprovider'
15-
import { Select, SelectionBox, TextField } from 'src/privacy/input'
16+
import { SelectionBox, TextField } from 'src/privacy/input'
1617

1718
import { __ } from 'src/utilities/Intl'
1819
import { fadeOut } from 'src/utilities/Animation'
@@ -307,15 +308,24 @@ export const ManualAccountForm = React.forwardRef<HTMLInputElement, ManualAccoun
307308
} else if (field.type === 'Select') {
308309
return (
309310
<div key={i} style={styles.selectInput}>
310-
<Select
311-
data-test="select-input"
312-
errorText={errors[field.name]}
313-
items={field.options}
311+
<TextField
312+
error={!!errors[field.name]}
313+
fullWidth={true}
314+
helperText={errors[field.name]}
315+
inputProps={{ 'data-test': 'select-input' }}
314316
label={field.label}
315317
name={field.name}
316318
onChange={handleTextInputChange}
317-
placeholder={__('Select a value')}
318-
/>
319+
required={field.validation?.required || false}
320+
select={true}
321+
value={values[field.name]}
322+
>
323+
{field.options?.map((option) => (
324+
<MenuItem key={option.value} value={option.value}>
325+
{option.label}
326+
</MenuItem>
327+
))}
328+
</TextField>
319329
</div>
320330
)
321331
} else {

0 commit comments

Comments
 (0)