Skip to content

Commit

Permalink
Flow and format
Browse files Browse the repository at this point in the history
  • Loading branch information
collinpreston committed Jun 3, 2024
1 parent db8290a commit 0f18583
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 56 deletions.
38 changes: 23 additions & 15 deletions frontend/public/src/components/forms/AddlProfileFieldsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,29 @@ const getInitialValues = (user: User) => ({
email: user.email,
legal_address: user.legal_address,
user_profile: {
gender: user.user_profile.gender || "",
addl_field_flag: user.user_profile.addl_field_flag,
company: user.user_profile.company || "",
company_size: user.user_profile.company_size || null,
highest_education: user.user_profile.highest_education || null,
industry: user.user_profile.industry || null,
job_function: user.user_profile.job_function || null,
job_title: user.user_profile.job_title || null,
leadership_level: user.user_profile.leadership_level || null,
year_of_birth: user.user_profile.year_of_birth || null,
years_experience: user.user_profile.years_experience || null,
type_is_professional: user.user_profile.type_is_professional || false,
type_is_student: user.user_profile.type_is_student || false,
type_is_educator: user.user_profile.type_is_educator || false,
type_is_other: user.user_profile.type_is_other || false
gender: (user.user_profile && user.user_profile.gender) || "",
addl_field_flag: user.user_profile && user.user_profile.addl_field_flag,
company: (user.user_profile && user.user_profile.company) || "",
company_size: (user.user_profile && user.user_profile.company_size) || null,
highest_education:
(user.user_profile && user.user_profile.highest_education) || null,
industry: (user.user_profile && user.user_profile.industry) || null,
job_function: (user.user_profile && user.user_profile.job_function) || null,
job_title: (user.user_profile && user.user_profile.job_title) || null,
leadership_level:
(user.user_profile && user.user_profile.leadership_level) || null,
year_of_birth:
(user.user_profile && user.user_profile.year_of_birth) || null,
years_experience:
(user.user_profile && user.user_profile.years_experience) || null,
type_is_professional:
(user.user_profile && user.user_profile.type_is_professional) || false,
type_is_student:
(user.user_profile && user.user_profile.type_is_student) || false,
type_is_educator:
(user.user_profile && user.user_profile.type_is_educator) || false,
type_is_other:
(user.user_profile && user.user_profile.type_is_other) || false
}
})

Expand Down
26 changes: 15 additions & 11 deletions frontend/public/src/components/forms/EditProfileForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,21 @@ const getInitialValues = (user: User) => ({
email: user.email,
legal_address: user.legal_address,
user_profile: {
gender: user.user_profile.gender || null,
addl_field_flag: user.user_profile.addl_field_flag,
company: user.user_profile.company || "",
company_size: user.user_profile.company_size || null,
highest_education: user.user_profile.highest_education || null,
industry: user.user_profile.industry || null,
job_function: user.user_profile.job_function || null,
job_title: user.user_profile.job_title || null,
leadership_level: user.user_profile.leadership_level || null,
year_of_birth: user.user_profile.year_of_birth || null,
years_experience: user.user_profile.years_experience || null
gender: (user.user_profile && user.user_profile.gender) || null,
addl_field_flag: user.user_profile && user.user_profile.addl_field_flag,
company: (user.user_profile && user.user_profile.company) || "",
company_size: (user.user_profile && user.user_profile.company_size) || null,
highest_education:
(user.user_profile && user.user_profile.highest_education) || null,
industry: (user.user_profile && user.user_profile.industry) || null,
job_function: (user.user_profile && user.user_profile.job_function) || null,
job_title: (user.user_profile && user.user_profile.job_title) || null,
leadership_level:
(user.user_profile && user.user_profile.leadership_level) || null,
year_of_birth:
(user.user_profile && user.user_profile.year_of_birth) || null,
years_experience:
(user.user_profile && user.user_profile.years_experience) || null
}
})

Expand Down
2 changes: 1 addition & 1 deletion frontend/public/src/lib/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const passwordField = yup
.required()
.label("Password")

export const changeEmailFormValidation = currentEmail =>
export const changeEmailFormValidation = (currentEmail: EmailFormValues) =>
yup.object().shape({
email: yup
.string()
Expand Down
30 changes: 1 addition & 29 deletions frontend/public/src/lib/validation_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { ValidationError } from "yup"
import {
changePasswordFormValidation,
resetPasswordFormValidation,
passwordFieldRegex,
usernameFieldRegex
passwordFieldRegex
} from "./validation"

describe("validation utils", () => {
Expand Down Expand Up @@ -74,31 +73,4 @@ describe("validation utils", () => {
})
})
})

describe("Validation Regex", () => {
const passwordRegex = new RegExp(passwordFieldRegex)
const usernameRegex = new RegExp(usernameFieldRegex)
;[
["", false],
["pass", false],
["passwor", false],
["password123", true],
["password", false]
].forEach(([value, regexMatch]) => {
it("password regex pattern matching.", () => {
assert.equal(passwordRegex.test(value), regexMatch)
})
})
;[
["", false],
[" ", false],
["ab", false],
["0123456789012345678901234567890", false],
["ábc-dèf-123", true]
].forEach(([value, regexMatch]) => {
it("username regex pattern matching.", () => {
assert.equal(usernameRegex.test(value), regexMatch)
})
})
})
})

0 comments on commit 0f18583

Please sign in to comment.