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(v1.7.0): Improvement to only show items with values in review #7630

Merged
merged 2 commits into from
Oct 10, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- "Choose a new password" form now allows the user to submit the form using the "Enter/Return" key [#5502](https://github.com/opencrvs/opencrvs-core/issues/5502)
- Dropdown options now flow to multiple rows in forms [#7653](https://github.com/opencrvs/opencrvs-core/pull/7653)
- Only render units/postfix when field has a value [#7055](https://github.com/opencrvs/opencrvs-core/issues/7055)
- Only show items with values in review [#5192](https://github.com/opencrvs/opencrvs-core/pull/5192)

## 1.6.0 Release candidate

Expand Down
165 changes: 164 additions & 1 deletion packages/client/src/views/RegisterForm/review/ReviewSection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
LOCATION_SEARCH_INPUT,
DATE,
DOCUMENT_UPLOADER_WITH_OPTION,
IForm
IForm,
TEXT
// MarriageSection
} from '@client/forms'
import { Event as DeclarationEvent, RegStatus } from '@client/utils/gateway'
Expand Down Expand Up @@ -608,6 +609,168 @@ describe('when in device of large viewport', () => {
expect(text).not.toContain('inches')
})
})

describe('when form has empty field in a group', () => {
let reviewSectionComponent: ReactWrapper<{}, {}>

beforeAll(() => {
vi.resetAllMocks()
})

beforeEach(async () => {
vi.spyOn(profileSelectors, 'getScope').mockReturnValue(['register'])
const form = {
sections: [
{
id: 'registration',
viewType: 'hidden',
name: {
defaultMessage: 'Registration',
description: 'Form section name for Registration',
id: 'form.section.declaration.name'
},
groups: []
},
{
id: 'child',
viewType: 'form' as ViewType,
title: formMessages.childTitle,
name: formMessages.childTitle,
groups: [
{
id: 'child-view-group',
fields: [
{
name: 'addressLine1Placeofbirth',
type: TEXT,
required: false,
validator: [],
previewGroup: 'address',
label: {
defaultMessage: 'TestAddress 1',
id: 'test1'
}
},
{
name: 'addressLine2Placeofbirth',
type: TEXT,
required: false,
validator: [],
previewGroup: 'address',
label: {
defaultMessage: 'TestAddress 2',
id: 'test2'
}
},
{
name: 'addressLine3Placeofbirth',
type: TEXT,
required: false,
validator: [],
previewGroup: 'address',
label: {
defaultMessage: 'TestAddress 3',
id: 'test3'
}
}
]
}
]
},
{
id: 'documents',
name: formMessages.documentsName,
title: formMessages.documentsTitle,
viewType: 'form' as ViewType,
groups: [
{
id: 'documents-view-group',
fields: [
{
name: 'uploadDocForMother',
extraValue: 'MOTHER',
type: DOCUMENT_UPLOADER_WITH_OPTION,
label: formMessages.uploadDocForMother,
required: true,
validator: [],
options: [
{
label: formMessages.docTypeBirthCert,
value: 'BIRTH_CERTIFICATE'
}
]
}
]
}
]
},
{
id: 'preview',
viewType: 'preview',
name: {
defaultMessage: 'Preview',
description: 'Form section name for Preview',
id: 'register.form.section.preview.name'
},
title: {
defaultMessage: 'Preview',
description: 'Form section title for Preview',
id: 'register.form.section.preview.title'
},
groups: [
{
id: 'preview-view-group',
fields: []
}
]
}
]
} satisfies IForm

const data = {
child: {
addressLine1Placeofbirth: 'District 9',
addressLine2Placeofbirth: '',
addressLine3Placeofbirth: 'Suburb 7'
},
documents: {}
}

const simpleDraft = createReviewDeclaration(
uuid(),
data,
DeclarationEvent.Birth
)

const testComponent = await createTestComponent(
<ReviewSection
form={form}
pageRoute={REVIEW_EVENT_PARENT_FORM_PAGE}
draft={simpleDraft}
rejectDeclarationClickEvent={mockHandler}
submitClickEvent={mockHandler}
userDetails={userDetails}
/>,
{ store, history }
)
reviewSectionComponent = testComponent
})

it('renders only fields with values', () => {
const addressList = reviewSectionComponent.find({
'data-test-id': 'row-value-TestAddress'
})

const innerHtml = addressList
.children()
.map((n) => n.html())
.join('')

const addressLines = innerHtml.split('<br>')

expect(addressLines.length).toBe(2)
})
})
})

describe('when in device of small viewport', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ class ReviewSectionComp extends React.Component<FullProps, State> {
.map((field) =>
this.getValueOrError(section, draft.data, field, errorsOnFields)
)
.filter((value) => value)
.filter((value) => value.props.children)
let completeValue = values[0]
values.shift()
values.forEach(
Expand Down Expand Up @@ -1146,7 +1146,7 @@ class ReviewSectionComp extends React.Component<FullProps, State> {
true
)
)
.filter((value) => value)
.filter((value) => value.props.children)
let previousCompleteValue = <Deleted>{previousValues[0]}</Deleted>
previousValues.shift()
previousValues.forEach(
Expand Down
Loading