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

Make end of tour date optional #4476

Merged
merged 4 commits into from
Sep 13, 2023
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
11 changes: 7 additions & 4 deletions client/src/components/CustomDateInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const CustomDateInput = ({
withTime,
value,
onChange,
onBlur
onBlur,
canClearSelection
}) => {
const inputRef = useRef()
const rightElement = showIcon && CalendarIcon(inputRef.current)
Expand Down Expand Up @@ -75,7 +76,7 @@ const CustomDateInput = ({
placeholder={inputFormat}
maxDate={maxDate}
minDate={moment().subtract(100, "years").startOf("year").toDate()}
canClearSelection={false}
canClearSelection={canClearSelection}
showActionsBar
closeOnSelection={!withTime}
timePickerProps={timePickerProps}
Expand All @@ -98,14 +99,16 @@ CustomDateInput.propTypes = {
PropTypes.instanceOf(Date)
]),
onChange: PropTypes.func,
onBlur: PropTypes.func
onBlur: PropTypes.func,
canClearSelection: PropTypes.bool
}
CustomDateInput.defaultProps = {
disabled: false,
showIcon: true,
maxDate: moment().add(20, "years").endOf("year").toDate(),
placement: "auto",
withTime: false
withTime: false,
canClearSelection: false
}

export default CustomDateInput
4 changes: 1 addition & 3 deletions client/src/models/Person.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ export default class Person extends Model {
if (Person.isPrincipal({ role })) {
return schema
} else {
schema = schema.required(
`You must provide the ${Settings.fields.person.endOfTourDate}`
)
// endOfTourDate is not required but if there is, it must be greater than today
if (Person.isPendingVerification({ pendingVerification })) {
schema = schema.test(
"end-of-tour-date",
Expand Down
4 changes: 3 additions & 1 deletion client/src/pages/people/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,9 @@ const PersonForm = ({
value={values.endOfTourDate}
onChange={value => setFieldValue("endOfTourDate", value)}
onBlur={() => setFieldTouched("endOfTourDate")}
widget={<CustomDateInput id="endOfTourDate" />}
widget={
<CustomDateInput id="endOfTourDate" canClearSelection />
}
>
{isAdvisor && endOfTourDateInPast && (
<Alert variant="warning">
Expand Down
23 changes: 5 additions & 18 deletions client/tests/webdriver/baseSpecs/createNewPerson.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe("Create new Person form page", () => {
)
// Don't logout, next test continues…
})
it("Should not save if endOfTourDate is not filled in", async() => {
it("Should save even if endOfTourDate is not filled in", async() => {
// Continue on the same page to prevent "Are you sure you wish to navigate away from the page" warning
await (
await CreatePerson.getLastName()
Expand All @@ -181,12 +181,6 @@ describe("Create new Person form page", () => {
await (
await CreatePerson.getEmailAddress()
).setValue(VALID_PERSON_ADVISOR.emailAddress)
await (await CreatePerson.getLastName()).click()
let errorMessage = await browser.$(
"input#emailAddress + div.invalid-feedback"
)
// element should *not* be visible!
await errorMessage.waitForDisplayed({ timeout: 1000, reverse: true })
gjvoosten marked this conversation as resolved.
Show resolved Hide resolved
await (
await CreatePerson.getRank()
).selectByAttribute(
Expand All @@ -205,20 +199,13 @@ describe("Create new Person form page", () => {
"value",
await CreatePerson.getRandomOption(await CreatePerson.getCountry())
)
// This makes sure the help-block is displayed after form submit
await (await CreatePerson.getEndOfTourDate()).setValue("")
await (await CreatePerson.getLastName()).click()
errorMessage = await (await CreatePerson.getEndOfTourDate())
.$("..")
.$("..")
.$("..")
.$("..")
.$("div.invalid-feedback")
await errorMessage.waitForExist()
await errorMessage.waitForDisplayed()
expect(await errorMessage.getText()).to.equal(
"You must provide the End of tour"
const errorMessage = await browser.$(
"input#emailAddress + div.invalid-feedback"
)
// element should *not* be visible!
await errorMessage.waitForDisplayed({ timeout: 1000, reverse: true })
// Don't logout, next test continues…
})

Expand Down