-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new util isPrefixName, update form availability
- Loading branch information
Showing
7 changed files
with
216 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import checkCompositeName from "./check-composite-name"; | ||
|
||
export default function findNearestNameFromArray(name: string, array: string[]): string | undefined { | ||
let answer = ""; | ||
export default function findNearestNameFromArray<T extends string>(name: string, array: T[]): T | undefined { | ||
let answer: T | undefined; | ||
|
||
array.forEach(n => { | ||
|
||
if (!checkCompositeName(n, name)) return; | ||
if (n.length > answer.length) answer = n; | ||
if (n.length > (answer?.length || 0)) answer = n; | ||
}) | ||
|
||
return answer.length === 0 ? undefined: answer | ||
return answer?.length ? answer : undefined | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* @description Return true if the prefix is some parent of provided field name. | ||
* @example address.city.name address -> true | ||
* @example user.type.index user.type -> true | ||
* @example position.city.type city -> false | ||
* */ | ||
export default function isPrefixName(fieldName: string, prefix: string) { | ||
return (new RegExp(`^${prefix}\.`)).test(fieldName); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import Form from "../../../src/classes/Form"; | ||
|
||
describe("Test for check disabled/enabled state", () => { | ||
/* | ||
it('should be enable by default', function () { | ||
const form = new Form(); | ||
expect(form.disabled).toBe(false) | ||
}); | ||
it('should be disabled = true, after invoke form.disable', function () { | ||
const form = new Form() | ||
form.disable(); | ||
expect(form.disabled).toBe(true) | ||
}); | ||
it('should be disabled = false, after invoke disable and then enable', function () { | ||
const form = new Form() | ||
form.disable(); | ||
form.enable(); | ||
expect(form.disabled).toBe(false) | ||
}); | ||
it("should disabled just one field, not full form", () => {}) | ||
it("Field should be disable if parent is disabled", () => {}) | ||
it("Field should be enable if grandparent is disabled, but parent is enable", () => {}) | ||
it("Should disabled in child", () => {}) | ||
it("Should enable in child", () => {}) | ||
it("Disable full form", () => {}) | ||
it("Enable full form", () => {}) | ||
it("Disable child form", () => {}) | ||
it("Enable child form", () => {}) | ||
it("Field should be enable in child form.", () => {}) | ||
it("Field should be disable in child form.", () => {}); | ||
it("Enable parent form should clean all disable fields", () => {}) | ||
*/ | ||
}) |
2 changes: 1 addition & 1 deletion
2
...tils/find-nearest-name-from-array.spec.ts → ...tils/find-nearest-name-from-array.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import isPrefixName from "./../../../src/utils/is-prefix-name"; | ||
|
||
describe("Is prefix name", () => { | ||
test("Simple name", () => { | ||
expect(isPrefixName("address.city.name", "address")).toBe(true) | ||
}) | ||
test("Multi name name", () => { | ||
expect(isPrefixName("user.type.index", "user.type")).toBe(true) | ||
}) | ||
test("Should return false if second param is not prefix", () => { | ||
expect(isPrefixName("position.city.type", "city")).toBe(false) | ||
}) | ||
}) |