Skip to content

Commit

Permalink
fix: cover uncovered tests areas & fix fieldset nesting & fix datetim…
Browse files Browse the repository at this point in the history
…e input fp-68
  • Loading branch information
what1s1ove committed Dec 9, 2023
1 parent 82eeaae commit 0f7044e
Show file tree
Hide file tree
Showing 18 changed files with 440 additions and 332 deletions.
6 changes: 2 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ PS. _The library works perfectly with any framework. Just use a valid [HTMLFormE
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="url"` || `string` |
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="tel"` || `string` |
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="color"` || `string` |
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="datetime-local"` || `string` |
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="radio"` || `string` |
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="hidden"` || `string` |
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="number"` || `number` |
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="range"` || `number` |
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="checkbox"` || `boolean` |
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="date"` || [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="time"` || [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="datetime-local"` || [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="month"` || [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="week"` || [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) |
| [HTMLInputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement) | `type="file"` || [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) or `null` |
Expand All @@ -93,7 +93,5 @@ PS. _The library works perfectly with any framework. Just use a valid [HTMLFormE
| [HTMLSelectElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement) | `multiple` || `Array<string>` |
| [HTMLOutputElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLOutputElement) ||| `string` |
| [HTMLFieldsetElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFieldsetElement) ||| `Object<name: string, value: unknown>` (recursive values of nested elements) |
| [HTMLButtonElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement) | `type="button"` |||
| [HTMLButtonElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement) | `type="submit"` |||
| [HTMLButtonElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement) | `type="reset"` |||
| [HTMLButtonElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement) ||||
| [HTMLObjectElement](https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement) ||||

This file was deleted.

1 change: 0 additions & 1 deletion src/libs/constants/constants.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export { BANNED_CONTROL_TYPES } from './banned-control-types.constant.js';
export { BANNED_FORM_OPERATIONAL_CONTROL_ELEMENTS } from './banned-form-operational-control-elements.constant.js';
2 changes: 1 addition & 1 deletion src/libs/enums/control-type.enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const ControlType = /** @type {const} */ ({
URL: 'url',
TEL: 'tel',
COLOR: 'color',
DATETIME_LOCAL: 'datetime-local',
RADIO: 'radio',
HIDDEN: 'hidden',

Expand All @@ -16,7 +17,6 @@ const ControlType = /** @type {const} */ ({

DATE: 'date',
TIME: 'time',
DATETIME_LOCAL: 'datetime-local',
MONTH: 'month',
WEEK: 'week',

Expand Down
6 changes: 6 additions & 0 deletions src/libs/maps/element-name-to-element-instance.map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const bannedElementNameToElementInstance = /** @type {const} */ ({
button: HTMLButtonElement,
object: HTMLObjectElement,
});

export { bannedElementNameToElementInstance };
1 change: 1 addition & 0 deletions src/libs/maps/maps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { bannedElementNameToElementInstance } from './element-name-to-element-instance.map.js';
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const getFormControlPayload = (controlNode) => {
case ControlType.URL:
case ControlType.TEL:
case ControlType.COLOR:
case ControlType.DATETIME_LOCAL:
case ControlType.RADIO:
case ControlType.HIDDEN:
case ControlType.TEXTAREA:
Expand Down Expand Up @@ -84,7 +85,6 @@ const getFormControlPayload = (controlNode) => {
}
case ControlType.DATE:
case ControlType.TIME:
case ControlType.DATETIME_LOCAL:
case ControlType.MONTH:
case ControlType.WEEK: {
return getInputDateValue(
Expand Down Expand Up @@ -113,7 +113,7 @@ const getFormControlPayload = (controlNode) => {
}

throw new FormPayloadError({
message: 'Unknown control type.',
message: `Unsupported control type${controlNode.type}.`,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
*/
const checkIsReferToAnotherNode = (currentNode, ...checkNodes) => {
return checkNodes.some((checkNode) => {
const hasElements = 'elements' in checkNode;
const hasElements =
'elements' in checkNode && checkNode.elements.length > 0;

if (!hasElements) {
return false;
}

return Boolean(checkNode.elements.namedItem(currentNode.name));
return [...checkNode.elements].some((element) =>
element.contains(currentNode),
);
});
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
BANNED_CONTROL_TYPES,
BANNED_FORM_OPERATIONAL_CONTROL_ELEMENTS,
} from '../../../../libs/constants/constants.js';
import { BANNED_CONTROL_TYPES } from '../../../../libs/constants/constants.js';
import { bannedElementNameToElementInstance } from '../../../../libs/maps/maps.js';

/** @typedef {import('../../../../libs/types/types.js').HTMLFormControlElement} HTMLFormControlElement */
/** @typedef {import('../../../../libs/types/types.js').HTMLFormOperationalControlElement} HTMLFormOperationalControlElement */
Expand Down Expand Up @@ -30,13 +28,13 @@ const checkControlFunctionMap = /** @type {const} */ ({
* @returns {boolean}
*/
checkIsAllowedElement(element) {
const isObjectNode = BANNED_FORM_OPERATIONAL_CONTROL_ELEMENTS.some(
(node) => {
return element instanceof node;
},
);
const isSameNode = Object.values(
bannedElementNameToElementInstance,
).some((node) => {
return element instanceof node;
});

return !isObjectNode;
return !isSameNode;
},
});

Expand Down
Loading

0 comments on commit 0f7044e

Please sign in to comment.