-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): update testing and add query url
What's New: - Implementing testing - add support setFiltered, setSorted and setQuery
- Loading branch information
Showing
12 changed files
with
484 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// jest.config.ts | ||
|
||
export default async (): Promise<any> => { | ||
return { | ||
moduleDirectories: ['node_modules', 'src'], | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,71 @@ | ||
interface ArrayQueryOptions { | ||
keyId?: string | ||
keyValue?: string | ||
filterValue?: { | ||
only?: any[] | ||
exclude?: any[] | ||
} | ||
} | ||
|
||
interface Queries { | ||
[key: string]: any | ||
} | ||
|
||
class ArrayQuery { | ||
private keyId: string | ||
|
||
private keyValue: string | ||
|
||
private options: ArrayQueryOptions | ||
|
||
private queries: Queries[] = [] | ||
|
||
constructor(options?: ArrayQueryOptions) { | ||
this.options = options || {} | ||
|
||
const { keyId = 'id', keyValue = 'value' } = this.options | ||
this.keyId = keyId | ||
this.keyValue = keyValue | ||
} | ||
|
||
count(id: string) { | ||
return this.getQueries().filter((q) => q[this.keyId] === id).length | ||
} | ||
|
||
setQuery(id: string, value: any) { | ||
const { filterValue: { exclude, only } = {} } = this.options | ||
// prevent duplication | ||
this.remove(id) | ||
|
||
if (only && !only.includes(value)) { | ||
return | ||
} | ||
|
||
if (exclude && exclude.includes(value)) { | ||
return | ||
} | ||
|
||
this.queries.push({ | ||
[this.keyId]: id, | ||
[this.keyValue]: value, | ||
}) | ||
} | ||
|
||
getQueries() { | ||
return this.queries | ||
} | ||
|
||
find(id: string) { | ||
return this.queries.find((query) => query[this.keyId] === id) | ||
} | ||
|
||
remove(id: string) { | ||
this.queries = this.queries.filter((query) => query[this.keyId] !== id) | ||
} | ||
|
||
stringify() { | ||
return JSON.stringify(this.queries) | ||
} | ||
} | ||
|
||
export default ArrayQuery |
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,27 @@ | ||
import ArrayQuery from 'helpers/QueryUrl/ArrayQuery' | ||
|
||
class QueryUrl { | ||
public filtered: ArrayQuery | ||
|
||
public sorted: ArrayQuery | ||
|
||
constructor() { | ||
this.filtered = new ArrayQuery({ | ||
keyId: 'id', | ||
keyValue: 'value', | ||
filterValue: { | ||
exclude: [undefined, ''], | ||
}, | ||
}) | ||
|
||
this.sorted = new ArrayQuery({ | ||
keyId: 'id', | ||
keyValue: 'desc', | ||
filterValue: { | ||
only: [true, false], | ||
}, | ||
}) | ||
} | ||
} | ||
|
||
export default QueryUrl |
Oops, something went wrong.