Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix value set ids #1366

Merged
merged 9 commits into from
Apr 5, 2024
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 @@ -16,6 +16,7 @@ import { groupResourceType, listResourceType, unitOfMeasure } from '../../../../
import userEvent from '@testing-library/user-event';
import * as notifications from '@opensrp/notifications';
import flushPromises from 'flush-promises';
import { fillSearchableSelect } from './test-utils';

jest.mock('@opensrp/notifications', () => ({
__esModule: true,
Expand Down Expand Up @@ -473,50 +474,3 @@ test('#1116 adding new group but list does not exist', async () => {

await flushPromises();
});

export interface SearchableSelectValues {
selectId: string;
searchOptionText: string;
fullOptionText: string;
beforeFilterOptions: string[];
afterFilterOptions: string[];
}

/**
* @param searchableSelectOptions options
*/
export function fillSearchableSelect(searchableSelectOptions: SearchableSelectValues) {
const { selectId, fullOptionText, searchOptionText, beforeFilterOptions, afterFilterOptions } =
searchableSelectOptions;

// simulate value selection for type
const selectComponent = document.querySelector(`input#${selectId}`)!;
fireEvent.mouseDown(selectComponent);

const optionTexts = [
...document.querySelectorAll(
`#${selectId}_list+div.rc-virtual-list .ant-select-item-option-content`
),
].map((option) => {
return option.textContent;
});

expect(optionTexts).toHaveLength(beforeFilterOptions.length);
expect(optionTexts).toEqual(beforeFilterOptions);

// filter searching through members works
userEvent.type(selectComponent, searchOptionText);

// options after search
const afterFilterOptionTexts = [
...document.querySelectorAll(
`#${selectId}_list+div.rc-virtual-list .ant-select-item-option-content`
),
].map((option) => {
return option.textContent;
});

expect(afterFilterOptionTexts).toEqual(afterFilterOptions);

fireEvent.click(document.querySelector(`[title="${fullOptionText}"]`)!);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

export interface SearchableSelectValues {
selectId: string;
searchOptionText: string;
fullOptionText: string;
beforeFilterOptions: string[];
afterFilterOptions: string[];
}

/**
* @param searchableSelectOptions options
*/
export function fillSearchableSelect(searchableSelectOptions: SearchableSelectValues) {
const { selectId, fullOptionText, searchOptionText, beforeFilterOptions, afterFilterOptions } =
searchableSelectOptions;

// simulate value selection for type
const selectComponent = document.querySelector(`input#${selectId}`)!;
fireEvent.mouseDown(selectComponent);

const optionTexts = [
...document.querySelectorAll(
`#${selectId}_list+div.rc-virtual-list .ant-select-item-option-content`
),
].map((option) => {
return option.textContent;
});

expect(optionTexts).toHaveLength(beforeFilterOptions.length);
expect(optionTexts).toEqual(beforeFilterOptions);

// filter searching through members works
userEvent.type(selectComponent, searchOptionText);

// options after search
const afterFilterOptionTexts = [
...document.querySelectorAll(
`#${selectId}_list+div.rc-virtual-list .ant-select-item-option-content`
),
].map((option) => {
return option.textContent;
});

expect(afterFilterOptionTexts).toEqual(afterFilterOptions);

fireEvent.click(document.querySelector(`[title="${fullOptionText}"]`)!);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ exports[`renders correctly: active radio button 1`] = `
/>
`;

exports[`renders correctly: active radio button 2`] = `
<input
checked=""
class="ant-radio-input"
type="radio"
value="true"
/>
`;

exports[`renders correctly: attractive item no radio button 1`] = `
<input
class="ant-radio-input"
Expand All @@ -43,11 +34,3 @@ exports[`renders correctly: disabled radio button 1`] = `
value="false"
/>
`;

exports[`renders correctly: disabled radio button 2`] = `
<input
class="ant-radio-input"
type="radio"
value="false"
/>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import {
import { binaryResourceType, groupResourceType, listResourceType } from '../../../../constants';
import userEvent from '@testing-library/user-event';
import * as notifications from '@opensrp/notifications';
import { fillSearchableSelect } from '../../Default/tests/index.test';
import { photoUploadCharacteristicCode } from '../../../../helpers/utils';
import { cloneDeep } from 'lodash';
import { fillSearchableSelect } from '../../Default/tests/test-utils';

jest.mock('@opensrp/notifications', () => ({
__esModule: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import { useTranslation } from '../../mls';
import { useQueryClient, useMutation } from 'react-query';
import { supplyMgSnomedCode, snomedCodeSystem } from '../../helpers/utils';
import { Rule } from 'rc-field-form/lib/interface';
import {
sendSuccessNotification,
sendErrorNotification,
Expand All @@ -33,6 +32,7 @@ import {
name,
type,
actual,
unicefDonorValueSetId,
} from '../../constants';
import {
getLocationInventoryPayload,
Expand Down Expand Up @@ -149,12 +149,7 @@ const AddLocationInventoryForm = (props: LocationInventoryFormProps) => {
}
};

const validationRules = validationRulesFactory(t);
let serialNumebrRule: Rule[] = [{ required: false }];
if (attractiveProduct) {
serialNumebrRule = validationRules[serialNumber];
}

const validationRules = validationRulesFactory(t, attractiveProduct);
const productQueryFilters = getProductQueryFilters(commodityListId);

return (
Expand All @@ -167,25 +162,25 @@ const AddLocationInventoryForm = (props: LocationInventoryFormProps) => {
}}
initialValues={initialValues}
>
<FormItem id="project" name={product} label={t('Product name')}>
<FormItem id={product} name={product} label={t('Product name')}>
<PaginatedAsyncSelect<IGroup>
baseUrl={fhirBaseURL}
resourceType={groupResourceType}
transformOption={processProductOptions}
extraQueryParams={productQueryFilters}
showSearch={true}
showSearch={false}
placeholder={t('Select product')}
getFullOptionOnChange={productChangeHandler}
disabled={editMode}
/>
</FormItem>

<FormItem id="quantity" name={quantity} label={t('Quantity')}>
<Input placeholder={t('Quantity')} type="number" />
<FormItem id={quantity} name={quantity} label={t('Quantity')}>
<Input min={0} placeholder={t('Quantity')} type="number" />
</FormItem>

<FormItem
id="deliveryDate"
id={deliveryDate}
rules={validationRules[deliveryDate]}
name={deliveryDate}
label={t('Delivery date')}
Expand All @@ -198,7 +193,7 @@ const AddLocationInventoryForm = (props: LocationInventoryFormProps) => {
</FormItem>

<FormItem
id="accounterbilityEndDate"
id={accountabilityEndDate}
name={accountabilityEndDate}
label={t('Accountability end date')}
rules={validationRules[accountabilityEndDate]}
Expand All @@ -225,30 +220,30 @@ const AddLocationInventoryForm = (props: LocationInventoryFormProps) => {
</FormItem>

<FormItem
id="serialNumber"
rules={serialNumebrRule}
id={serialNumber}
rules={validationRules[serialNumber]}
name={serialNumber}
label={t('Serial number')}
>
<Input disabled={!attractiveProduct} type="number" placeholder={t('Serial number')} />
<Input disabled={!attractiveProduct} placeholder={t('Serial number')} />
</FormItem>

<FormItem id={donor} name={donor} label={t('Donor')}>
<ValueSetAsyncSelect
placeholder={t('Select donor')}
showSearch={true}
valueSetId={unicefSectionValueSetId}
valueSetId={unicefDonorValueSetId}
fhirBaseUrl={fhirBaseURL}
/>
</FormItem>

<FormItem
id="poNumber"
id={PONumber}
rules={validationRules[PONumber]}
name={PONumber}
label={t('PO number')}
>
<Input type="number" placeholder={t('PO number')} />
<Input placeholder={t('PO number')} />
</FormItem>

{/* start hidden fields */}
Expand All @@ -272,7 +267,7 @@ const AddLocationInventoryForm = (props: LocationInventoryFormProps) => {
<FormItem {...tailLayout}>
<Space>
<Button type="primary" id="submit-button" disabled={isLoading} htmlType="submit">
{isLoading ? t('Saving') : t('save')}
{isLoading ? t('Saving') : t('Save')}
</Button>
<Button id="cancel-button" onClick={() => history.goBack()}>
{t('Cancel')}
Expand Down
Loading
Loading