Skip to content

Commit

Permalink
[EN-4026] chore(inputs): fixed jest tests and fixed error messages if…
Browse files Browse the repository at this point in the history
… they are too long
  • Loading branch information
emile-bex committed Aug 20, 2023
1 parent 4d9f50f commit 2946dc0
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 41 deletions.
4 changes: 2 additions & 2 deletions cypress/e2e/admin.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,10 @@ describe('Admin', () => {
});
cy.wait('@organizationListPage');
// test if all organizations are in the table
cy.fixture('organization-search-res').then((organizations) => {
cy.fixture('organization-search-res').then((orgs) => {
cy.get('[data-testid="organization-list"]')
.find('tr')
.should('have.length', organizations.length);
.should('have.length', orgs.length);
});
});

Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/parcours-orienter.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ describe('Parcours Orienter', () => {
cy.intercept('POST', '/contact/contactUs', {
statusCode: 201,
}).as('postContact');
cy.intercept('GET', '/cv/shares', { total: 184222 });
});

it('Ouvrir la popup du formulaire', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export function MemberDesktop({
<TdDesktop>
<StyledCheckBoxCellContent>
<CheckBox
removeMargin
useOutsideOfForm
id={`member-${member.id}-check`}
name={`member-${member.id}-check`}
value={checked}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function MemberMobile({
name={`member-${member.id}-check`}
value={checked}
onChange={handleCheckBox}
removeMargin
useOutsideOfForm
disabled={userCandidate?.hidden}
/>
)}
Expand Down
20 changes: 13 additions & 7 deletions src/components/forms/FormWithValidation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
isFormFieldGroup,
isFormFieldInput,
isFormFieldMultiple,
isFormFieldRadio,
isFormFieldText,
} from './FormSchema';
import { StyledForm } from './Forms.styles';
Expand Down Expand Up @@ -109,6 +110,7 @@ export function FormWithValidation<S extends FormSchema<AnyCantFix>>({
if (shouldHide) {
return null;
}

const title =
typeof field.title === 'function'
? field.title(getValues)
Expand Down Expand Up @@ -139,15 +141,15 @@ export function FormWithValidation<S extends FormSchema<AnyCantFix>>({
<li key={i}>
<InputsContainer
fields={childrenFields.map((childrenField) => {
if (isFormFieldText(childrenField)) {
const shouldHideField = childrenField.hide
? childrenField.hide(getValues)
: childrenField.hidden;
const shouldHideField = childrenField.hide
? childrenField.hide(getValues)
: childrenField.hidden;

if (shouldHideField) {
return null;
}
if (shouldHideField) {
return null;
}

if (isFormFieldText(childrenField)) {
const title =
typeof childrenField.title === 'function'
? childrenField.title(getValues)
Expand Down Expand Up @@ -217,6 +219,10 @@ export function FormWithValidation<S extends FormSchema<AnyCantFix>>({
}

if (isFormFieldInput(field)) {
// Condition because Radio Async needs to be rendered to make request and check if it should be hidden or not
if (!isFormFieldRadio(field) && shouldHide) {
return null;
}
return (
<li key={i}>
<GenericField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export const StyledErrorMessage = styled.div`
color: ${COLORS.darkOrange};
font-size: 12px;
line-height: 12px;
position: absolute;
bottom: 12px;
display: flex;
align-items: flex-start;
min-height: 30px;
> * {
padding-top: 5px;
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ export const FieldErrorMessage = ({
error,
className,
}: FieldErrorMessageProps) => {
if (error?.message) {
return (
<StyledErrorMessage className={className}>
{error.message}
</StyledErrorMessage>
);
}
return null;
return (
<StyledErrorMessage className={className}>
<span>{error?.message ? error.message : ''}</span>
</StyledErrorMessage>
);
};
1 change: 1 addition & 0 deletions src/components/forms/schemas/formCandidateInscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function hideIfNoInfoCo(
return !city?.length || !filteredOptions;
}

// TODO FIX
export const formCandidateInscription: FormSchema<FormCandidateInscriptionSchema> =
{
id: 'form-candidate-inscription',
Expand Down
1 change: 1 addition & 0 deletions src/components/forms/schemas/formInterestLinkedOut.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const formInterestLinkedOut: FormSchema<{
component: 'text-input',
title: 'Prénom*',
isRequired: true,
maxLength: 30,
},
{
id: 'email',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ jest.mock('@react-hook/window-size', () => {
};
});

jest.mock('src/components/forms/schemas/formInterestLinkedOut', () => {
return {
formInterestLinkedOut: {
id: 'form-interest',
fields: [],
},
};
});
jest.mock('react-modal');
jest.mock('src/api/index');
jest.mock('src/components/modals/Modal', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const NewsletterPartial = ({
<CheckBox
id={tagConst}
name={tagConst}
removeMargin
useOutsideOfForm
value={tagConst === status}
title={label}
onChange={() => {
Expand All @@ -113,7 +113,7 @@ export const NewsletterPartial = ({
<CheckBox
id={tagConst}
name={tagConst}
removeMargin
useOutsideOfForm
value={tagConst === zone}
title={label}
onChange={() => {
Expand Down
4 changes: 0 additions & 4 deletions src/components/utils/Inputs/CheckBox/CheckBox.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ export const StyledCheckbox = styled.div`
${() => commonInputContainerStyles}
justify-content: center;
.checkbox-label {
margin-bottom: ${({ removeMargin }) => {
return removeMargin ? 0 : 30;
}}px;
display: flex;
align-items: center;
justify-content: flex-start;
Expand Down
7 changes: 3 additions & 4 deletions src/components/utils/Inputs/CheckBox/CheckBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FieldErrorMessage } from 'src/components/forms/fields/FieldErrorMessage
import { StyledCheckbox } from 'src/components/utils/Inputs/CheckBox/CheckBox.styles';

interface CheckBoxProps extends CommonInputProps<boolean, HTMLInputElement> {
removeMargin?: boolean;
useOutsideOfForm?: boolean;
}

export function CheckBox({
Expand All @@ -16,7 +16,7 @@ export function CheckBox({
disabled = false,
hidden = false,
value = false,
removeMargin = false,
useOutsideOfForm = false,
error,
inputRef,
}: Omit<CheckBoxProps, 'title'> & { title?: string | JSX.Element }) {
Expand All @@ -27,7 +27,6 @@ export function CheckBox({
return (
<StyledCheckbox
disabled={disabled}
removeMargin={removeMargin}
onClick={(e) => {
e.stopPropagation();
}}
Expand All @@ -51,7 +50,7 @@ export function CheckBox({
<span className="checkmark" />
{title && <span className="label">{title}</span>}
</label>
<FieldErrorMessage error={error} />
{!useOutsideOfForm && <FieldErrorMessage error={error} />}
</StyledCheckbox>
);
}
9 changes: 5 additions & 4 deletions src/components/utils/Inputs/Inputs.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const commonInputStyles = css`
padding: 4px 0;
min-height: 30px;
box-sizing: border-box;
margin-bottom: 30px;
`;

export const StyledInputLabel = styled.label`
Expand All @@ -56,10 +55,8 @@ export const StyledInputLabel = styled.label`
export const StyledAnnotations = styled.div`
display: flex;
justify-content: space-between;
position: absolute;
bottom: 12px;
width: 100%;
align-items: center;
align-items: flex-start;
`;

export const StyledAnnotationsErrorMessage = styled(FieldErrorMessage)`
Expand All @@ -75,4 +72,8 @@ export const StyledLimit = styled.div`
line-height: 12px;
text-align: right;
align-self: flex-end;
min-height: 30px;
> * {
padding-top: 5px;
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const StyledSelectContainer = styled.div`
width: 100%;
border: none;
position: relative;
margin-bottom: 30px;
.placeholder,
.selected-value {
${() => commonInputStyles}
Expand Down
1 change: 0 additions & 1 deletion src/components/utils/Inputs/Selects/Selects.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const StyledSelectContainer = styled.div`
${() => commonInputContainerStyles}
`;
export const StyledSelect = styled.div`
margin-bottom: 30px;
& .Select__control--is-disabled {
background-color: ${COLORS.lightgray} !important;
Expand Down
4 changes: 2 additions & 2 deletions src/components/utils/Inputs/TextArea/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ export function TextArea({
</div>
{maxLines && (
<StyledLimit warning={remainingLines === 0}>
{remainingLines} ligne(s) restante(s)
<span>{remainingLines} ligne(s) restante(s)</span>
</StyledLimit>
)}
{!maxLines && maxLength && (
<StyledLimit warning={remainingCharacters === 0}>
{remainingCharacters} caractère(s) restant(s)
<span>{remainingCharacters} caractère(s) restant(s)</span>
</StyledLimit>
)}
</StyledAnnotations>
Expand Down
3 changes: 1 addition & 2 deletions src/components/utils/Inputs/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { ChangeEvent } from 'react';
import { StyledErrorMessage } from '../../../forms/fields/FieldErrorMessage/FieldErrorMessage.styles';
import {
StyledAnnotations,
StyledAnnotationsErrorMessage,
Expand Down Expand Up @@ -68,7 +67,7 @@ export function TextInput({
<StyledAnnotationsErrorMessage error={error} />
</div>
<StyledLimit warning={remainingCharacters === 0}>
{remainingCharacters} caractère(s) restant(s)
<span>{remainingCharacters} caractère(s) restant(s)</span>
</StyledLimit>
</StyledAnnotations>
) : (
Expand Down

0 comments on commit 2946dc0

Please sign in to comment.