Skip to content

Commit

Permalink
Merge branch 'master' into jmfrancois/chore/upgrade-testing-library
Browse files Browse the repository at this point in the history
  • Loading branch information
jmainguytalend authored Nov 8, 2023
2 parents 14ea1a4 + 841be39 commit 5b4db8d
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 74 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-turtles-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@talend/utils': minor
---

TDOPS-5386 - remove phone validation as not in use
6 changes: 6 additions & 0 deletions packages/design-system/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @talend/design-system

## 8.1.1

### Patch Changes

- 6816365dc: fix: binding in forms

## 8.1.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/design-system/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@talend/design-system",
"version": "8.1.0",
"version": "8.1.1",
"description": "Talend Design System",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const AffixSelect = forwardRef((props: AffixSelectPropsType, ref: Ref<HTMLSelect
const fieldID = useId(affixId, 'field-');

function AffixSelectComponent(
selectProps: Omit<SelectNoWrapperProps, 'hasError' | 'name' | 'children' | 'label'>,
selectProps: Omit<SelectNoWrapperProps, 'hasError' | 'children' | 'label'>,
) {
return (
<SelectNoWrapper id={fieldID} {...selectProps} isAffix isSuffix={isSuffix} ref={ref}>
Expand All @@ -25,7 +25,7 @@ const AffixSelect = forwardRef((props: AffixSelectPropsType, ref: Ref<HTMLSelect
}
return (
<FieldPrimitive label={label} name={name} id={fieldID} fieldId={fieldID} hideLabel>
<AffixSelectComponent {...rest} />
<AffixSelectComponent name={name} {...rest} />
</FieldPrimitive>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const Datalist = forwardRef(
<InputPrimitive
{...rest}
list={datalistListId}
name={name}
required={required}
hasError={hasError || false}
disabled={!!disabled}
readOnly={!!readOnly}
value={value}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ const InputCopy = forwardRef(
<InputPrimitive
{...rest}
id={inputId}
name={name}
required={required}
ref={inputRef}
value={value}
defaultValue={defaultValue}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,14 @@ const FieldFile = forwardRef(
hideLabel={hideLabel}
required={required}
>
<InputFile {...rest} id={fieldID} ref={ref} />
<InputFile
{...rest}
name={name}
required={required}
hasError={hasError || false}
id={fieldID}
ref={ref}
/>
</FieldPrimitive>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ const Field = forwardRef((props: InputFieldProps, ref: Ref<HTMLInputElement>) =>
<InputPrimitive
{...rest}
id={fieldID}
name={name}
required={required}
type={type}
ref={ref}
hasError={hasError || false}
name={name}
required={required}
/>
</FieldPrimitive>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ const Select = forwardRef((props: SelectProps, ref: Ref<HTMLSelectElement | HTML
defaultValue={defaultValue}
hasError={hasError || false}
name={name}
label={label}
required={required}
label={label}
id={fieldID}
{...rest}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const Textarea = forwardRef((props: InputTextareaProps, ref: Ref<HTMLTextAreaEle
{...rest}
required={required}
id={fieldID}
name={name}
ref={ref}
/>
</FieldPrimitive>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ exports[`Form should render a11y html 1`] = `
<input
class="theme-inputFile__input theme-input"
id="field--mocked-uuid-3"
name="file"
type="file"
/>
<div
Expand Down Expand Up @@ -228,6 +229,7 @@ exports[`Form should render a11y html 1`] = `
<textarea
class="theme-textarea"
id="field--mocked-uuid-8"
name="textarea"
/>
</div>
<div
Expand Down
55 changes: 14 additions & 41 deletions packages/utils/src/validation/methods.test.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,40 @@
import { validFirstName, validLastName, validEmail, validPhone } from './methods';
import {
validNames,
invalidNames,
validEmails,
invalidEmails,
validPhones,
invalidPhones,
} from './testValues';
import { validFirstName, validLastName, validEmail } from './methods';
import { validNames, invalidNames, validEmails, invalidEmails } from './testValues';

describe('methods', () => {
describe('validFirstName', () => {
// Test valid values
test.each(validNames)(
'"%s" should be an acceptable first name',
(value: string) => expect(validFirstName(value)).toBe(true),
test.each(validNames)('"%s" should be an acceptable first name', (value: string) =>
expect(validFirstName(value)).toBe(true),
);

// Test invalid values
test.each(invalidNames)(
'"%s" should not be an acceptable first name',
(value: string) => expect(validFirstName(value)).toBe(false),
test.each(invalidNames)('"%s" should not be an acceptable first name', (value: string) =>
expect(validFirstName(value)).toBe(false),
);
});

describe('validLastName', () => {
// Test valid values
test.each(validNames)(
'"%s" should be an acceptable last name',
(value: string) => expect(validLastName(value)).toBe(true),
test.each(validNames)('"%s" should be an acceptable last name', (value: string) =>
expect(validLastName(value)).toBe(true),
);

// Test invalid values
test.each(invalidNames)(
'"%s" should not be an acceptable last name',
(value: string) => expect(validLastName(value)).toBe(false),
test.each(invalidNames)('"%s" should not be an acceptable last name', (value: string) =>
expect(validLastName(value)).toBe(false),
);
});

describe('validEmail', () => {
// Test valid values
test.each(validEmails)(
'"%s" should be an acceptable email',
(value: string) => expect(validEmail(value)).toBe(true),
test.each(validEmails)('"%s" should be an acceptable email', (value: string) =>
expect(validEmail(value)).toBe(true),
);

// Test invalid values
test.each(invalidEmails)(
'"%s" should not be an acceptable email',
(value: string) => expect(validEmail(value)).toBe(false),
);
});

describe('validPhone', () => {
// Test valid values
test.each(validPhones)(
'"%s" should be an acceptable phone',
(value: string) => expect(validPhone(value)).toBe(true),
);

// Test invalid values
test.each(invalidPhones)(
'"%s" should not be an acceptable phone',
(value: string) => expect(validPhone(value)).toBe(false),
test.each(invalidEmails)('"%s" should not be an acceptable email', (value: string) =>
expect(validEmail(value)).toBe(false),
);
});
});
9 changes: 1 addition & 8 deletions packages/utils/src/validation/methods.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NAME, EMAIL, DOMAIN, PHONE } from './regexp';
import { NAME, EMAIL, DOMAIN } from './regexp';

/**
* Build a validation method along a given regular expression
Expand Down Expand Up @@ -36,10 +36,3 @@ export const validEmail: Function = getValidationMethod(EMAIL);
* @returns {boolean}
*/
export const validDomain: Function = getValidationMethod(DOMAIN);

/**
* Check that a given value is a valid phone number
* @param {string} value
* @returns {boolean}
*/
export const validPhone: Function = getValidationMethod(PHONE);
7 changes: 0 additions & 7 deletions packages/utils/src/validation/regexp.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
/* eslint-disable no-useless-escape */

export const PHONE =
/^((?:\+[\d().-]*\d[\d().-]*|[0-9A-F*#().-]*[0-9A-F*#][0-9A-F*#().-]*(?:;[a-z\d-]+(?:=(?:[a-z\d\[\]\/:&+$_!~*'().-]|%[\dA-F]{2})+)?)*;phone-context=(?:\+[\d().-]*\d[\d().-]*|(?:[a-z0-9]\.|[a-z0-9][a-z0-9-]*[a-z0-9]\.)*(?:[a-z]|[a-z][a-z0-9-]*[a-z0-9])))(?:;[a-z\d-]+(?:=(?:[a-z\d\[\]\/:&+$_!~*'().-]|%[\dA-F]{2})+)?)*(?:,(?:\+[\d().-]*\d[\d().-]*|[0-9A-F*#().-]*[0-9A-F*#][0-9A-F*#().-]*(?:;[a-z\d-]+(?:=(?:[a-z\d\[\]\/:&+$_!~*'().-]|%[\dA-F]{2})+)?)*;?)*)*)$/;

export const EMAIL =
/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;

export const NAME = /^[^\~!@#$%^&*()|+=?;:",<>\{\}\[\]\\\/¤¨£°§]*$/i;

export const DOMAIN = /^[^\~!#$%^&*()|+=?;:",<>\{\}\[\]\\\/¤¨£°§]*$/i;

/* eslint-enable no-useless-escape */
11 changes: 0 additions & 11 deletions packages/utils/src/validation/testValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,3 @@ export const validEmails: Array<string> = [
];

export const invalidEmails: Array<string> = ['john', 'john@', 'john @', 'john\\@re'];

// Phones
export const validPhones: Array<string> = ['+33102030405'];

export const invalidPhones: Array<string> = [
'john',
'john@',
'john @',
'[email protected]',
'Fred',
];

0 comments on commit 5b4db8d

Please sign in to comment.