Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { AsyncStatePhase } from '../../lib/asyncState';
import type { RecordList } from '../../lib/lists/RecordList';

type AutoCompleteUnitProps = {
id?: string;
disabled?: boolean;
value: string | undefined;
error?: string;
Expand All @@ -20,6 +21,7 @@ type AutoCompleteUnitProps = {
};

const AutoCompleteUnit = ({
id,
value,
disabled = false,
error,
Expand All @@ -46,6 +48,7 @@ const AutoCompleteUnit = ({

return (
<PaginatedSelectFiltered
id={id}
data-qa='autocomplete-unit'
error={error}
filter={unitsFilter}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function EditDepartment({ data, id, title, allowedToForwardData }: EditDepartmen
const requestTagBeforeClosingChatField = useId();
const chatClosingTagsField = useId();
const allowReceiveForwardOffline = useId();
const unitFieldId = useId();

return (
<Page flexDirection='row'>
Expand Down Expand Up @@ -358,16 +359,21 @@ function EditDepartment({ data, id, title, allowedToForwardData }: EditDepartmen
</Field>

<Field>
<FieldLabel required={isUnitRequired}>{t('Unit')}</FieldLabel>
<FieldLabel htmlFor={unitFieldId} required={isUnitRequired}>
{t('Unit')}
</FieldLabel>
<FieldRow>
<Controller
name='unit'
control={control}
rules={{ required: isUnitRequired }}
rules={{ required: isUnitRequired ? t('Required_field', { field: t('Unit') }) : false }}
render={({ field: { value, onChange } }) => (
<AutoCompleteUnit
disabled={!!initialValues.unit}
haveNone
id={unitFieldId}
error={errors.unit?.message as string}
aria-describedby={`${unitFieldId}-error`}
value={value}
onChange={onChange}
onLoadItems={(list) => {
Expand All @@ -378,6 +384,11 @@ function EditDepartment({ data, id, title, allowedToForwardData }: EditDepartmen
)}
/>
</FieldRow>
{errors.unit && (
<FieldError aria-live='assertive' id={`${unitFieldId}-error`}>
{errors.unit?.message}
</FieldError>
)}
</Field>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ test.describe.serial('OC - Monitor Role', () => {
await poOmnichannelDepartments.findOption(unitB.name).click();
});

await test.step('expect unit field to be required', async () => {
await poOmnichannelDepartments.inputUnit.click();
await poOmnichannelDepartments.findOption('None').click();
await expect(poOmnichannelDepartments.btnSave).toBeDisabled();
await expect(poOmnichannelDepartments.errorMessage('Unit required')).toBeVisible();
await poOmnichannelDepartments.inputUnit.click();
await poOmnichannelDepartments.findOption(unitB.name).click();
await expect(poOmnichannelDepartments.btnSave).toBeEnabled();
});

await test.step('expect to save department', async () => {
await poOmnichannelDepartments.btnEnabled.click();
await poOmnichannelDepartments.btnSave.click();
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/tests/e2e/utils/omnichannel/units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const createOrUpdateUnit = async (
msg: 'method',
id: '34',
method: 'livechat:saveUnit',
params: [id, { name: name || faker.commerce.department(), visibility: visibility || 'public' }, monitors, departments],
params: [id, { name: name || faker.string.uuid(), visibility: visibility || 'public' }, monitors, departments],
}),
});

Expand Down
Loading