Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Frontend
Commits
69f17ec3
Commit
69f17ec3
authored
3 years ago
by
Erwan Rouchet
Committed by
Bastien Abadie
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Filter bar unit tests
parent
8f8c11a2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1078
Filter bar unit tests
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
js/filterbar.js
+17
-15
17 additions, 15 deletions
js/filterbar.js
test/filterbar.js
+1154
-0
1154 additions, 0 deletions
test/filterbar.js
with
1171 additions
and
15 deletions
js/filterbar.js
+
17
−
15
View file @
69f17ec3
...
...
@@ -35,7 +35,7 @@ export class Filter {
*/
constructor
(
name
,
options
=
{})
{
this
.
name
=
name
this
.
displayName
=
options
.
displayName
??
name
.
charAt
(
0
).
toUpperCase
()
+
name
.
slice
(
1
).
toLowerCase
().
replace
(
'
_
'
,
'
'
)
this
.
displayName
=
options
.
displayName
??
name
.
charAt
(
0
).
toUpperCase
()
+
name
.
slice
(
1
).
toLowerCase
().
replace
(
/_/g
,
'
'
)
this
.
placeholder
=
options
.
placeholder
??
'
Filter value
'
this
.
operatorName
=
options
.
operatorName
this
.
operatorPlaceholder
=
options
.
operatorPlaceholder
??
'
Select an operator
'
...
...
@@ -101,7 +101,7 @@ export class Filter {
* A simple name filter, allowing any value.
* @extends {Filter<string>}
*/
class
NameFilter
extends
Filter
{
export
class
NameFilter
extends
Filter
{
constructor
()
{
super
(
'
name
'
,
{
operators
:
{
eq
:
'
contains
'
}
})
}
...
...
@@ -112,7 +112,7 @@ class NameFilter extends Filter {
* @typedef {{id: string, slug: string, display_name: string, folder: boolean}} ElementType
* @extends {Filter<ElementType>}
*/
class
TypeFilter
extends
Filter
{
export
class
TypeFilter
extends
Filter
{
constructor
(
store
)
{
super
(
'
type
'
)
this
.
store
=
store
...
...
@@ -153,7 +153,7 @@ class TypeFilter extends Filter {
* @typedef {boolean | MLClass} BestClass
* @extends {Filter<BestClass>}
*/
class
BestClassFilter
extends
Filter
{
export
class
BestClassFilter
extends
Filter
{
constructor
(
store
)
{
super
(
'
best_class
'
)
this
.
store
=
store
...
...
@@ -188,11 +188,14 @@ class BestClassFilter extends Filter {
}
async
validate
(
input
)
{
const
validInputs
=
{
'
any best class
'
:
true
,
'
no best class
'
:
false
,
...
Object
.
fromEntries
((
await
this
.
fetchClasses
()).
map
(
mlclass
=>
[
mlclass
.
name
.
toLowerCase
(),
mlclass
]))
}
// Early returns for simple values with no API request necessary
if
(
input
.
toLowerCase
()
===
'
any best class
'
)
return
true
if
(
input
.
toLowerCase
()
===
'
no best class
'
)
return
false
const
validInputs
=
Object
.
fromEntries
(
(
await
this
.
fetchClasses
())
.
map
(
mlclass
=>
[
mlclass
.
name
.
toLowerCase
(),
mlclass
])
)
const
found
=
validInputs
[
input
.
toLowerCase
()]
if
(
found
)
return
found
throw
new
Error
(
`Unknown class '
${
input
}
'`
)
...
...
@@ -218,7 +221,7 @@ class BestClassFilter extends Filter {
* @typedef {{id: string, worker: {id: string, name: string}, revision: {hash: string}}} WorkerVersion
* @extends {Filter<WorkerVersion | boolean>}
*/
class
WorkerVersionFilter
extends
Filter
{
export
class
WorkerVersionFilter
extends
Filter
{
constructor
(
store
)
{
super
(
'
worker_version
'
)
this
.
store
=
store
...
...
@@ -266,7 +269,7 @@ class WorkerVersionFilter extends Filter {
* but allows any name to be typed, to handle metadatas created by workers or admins.
* @extends {Filter<string>}
*/
class
MetadataNameFilter
extends
Filter
{
export
class
MetadataNameFilter
extends
Filter
{
constructor
(
store
)
{
super
(
'
metadata_name
'
)
this
.
store
=
store
...
...
@@ -290,8 +293,8 @@ class MetadataNameFilter extends Filter {
* Allows filtering with arithmetic operators, in which case the value must be a number.
* @extends {Filter<string | number>}
*/
class
MetadataValueFilter
extends
Filter
{
constructor
(
store
)
{
export
class
MetadataValueFilter
extends
Filter
{
constructor
()
{
super
(
'
metadata_value
'
,
{
operators
:
{
eq
:
'
=
'
,
...
...
@@ -303,7 +306,6 @@ class MetadataValueFilter extends Filter {
},
operatorName
:
'
metadata_operator
'
})
this
.
store
=
store
}
deserialize
(
input
,
operator
)
{
...
...
@@ -324,7 +326,7 @@ class MetadataValueFilter extends Filter {
* Filter methods that are common to every strictly boolean filter
* @extends {Filter<boolean>}
*/
class
BooleanFilter
extends
Filter
{
export
class
BooleanFilter
extends
Filter
{
autocomplete
()
{
return
[
true
,
false
]
}
...
...
This diff is collapsed.
Click to expand it.
test/filterbar.js
0 → 100644
+
1154
−
0
View file @
69f17ec3
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment