Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
g1
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
76
Issues
76
List
Boards
Labels
Service Desk
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cto
g1
Commits
c03d30c9
Commit
c03d30c9
authored
Feb 15, 2019
by
Tejesh
🖖
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TST: add tests for unique values filtering
parent
ce490141
Pipeline
#76896
failed with stage
in 1 minute and 28 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
8 deletions
+75
-8
src/formhandler.js
src/formhandler.js
+7
-2
test/test-formhandler-unique.html
test/test-formhandler-unique.html
+68
-6
No files found.
src/formhandler.js
View file @
c03d30c9
...
...
@@ -225,8 +225,12 @@ function modalHandler($this) {
})
.
on
(
'
shown.bs.modal
'
,
'
.formhandler-unique-table-modal
'
,
function
(
e
)
{
var
$el
=
$
(
e
.
relatedTarget
)
var
template_data
=
$this
.
data
(
'
formhandler
'
)
var
col
=
$el
.
closest
(
'
[data-col]
'
).
data
(
'
col
'
)
// if content already rendered for current col, and same col modal is opened
if
(
currentKey
==
col
&&
$
.
trim
(
$
(
'
.fh-unique
'
,
$this
).
html
()))
return
var
template_data
=
$this
.
data
(
'
formhandler
'
)
currentKey
=
col
// render checkboxes for unique items of column
var
unique_values
=
_
.
find
(
template_data
.
options
.
columns
,
function
(
item
){
return
item
.
name
==
col
}).
unique
...
...
@@ -252,7 +256,7 @@ function modalHandler($this) {
$
(
'
.fh-unique
'
,
$
(
'
.formhandler-unique-table-modal
'
,
$this
)).
html
(
''
).
append
(
modal_content
)
checkbox_state_toggle_selectall
(
'
.fh-select-all
'
,
true
)()
$
(
'
.fh-unique-values
'
,
$this
).
trigger
(
'
refresh
'
).
on
(
'
click
'
,
checkbox_state_toggle_selectall
(
'
.fh-select-all
'
,
true
))
$
(
'
.fh-unique-values
'
,
$this
).
on
(
'
change
'
,
checkbox_state_toggle_selectall
(
'
.fh-select-all
'
,
true
))
$
(
'
.fh-select-all
'
,
$this
).
on
(
'
change
'
,
checkbox_state_toggle_selectall
(
'
.fh-label-unique-values:not(.d-none) input.fh-unique-values
'
,
false
))
function
checkbox_state_toggle_selectall
(
selector
,
checked
)
{
...
...
@@ -270,6 +274,7 @@ function modalHandler($this) {
if
(
jQuery
.
fn
.
search
)
{
$
(
'
.formhandler-unique-table-modal
'
).
search
()
$
(
'
input[type="search"]
'
,
$this
).
trigger
(
'
search
'
)
$
(
'
input[type="search"]
'
,
$this
).
on
(
'
shown.g.search
'
,
checkbox_state_toggle_selectall
(
'
.fh-select-all
'
,
true
))
}
else
{
$
(
'
input[type="search"]
'
,
$this
).
remove
()
...
...
test/test-formhandler-unique.html
View file @
c03d30c9
...
...
@@ -30,7 +30,14 @@
</script>
<div
class=
"unique-filters"
></div>
<script>
var
$this
=
$
(
'
.unique-filters
'
)
tape
(
'
g1.formhandler() test filter by unique values and clearing same key filters
'
,
function
(
test
)
{
var
stripes_unique_values
=
[
'
Verticalfffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
'
,
'
Horizontal
'
,
'
Diagonal
'
]
$
(
'
.unique-filters
'
).
formhandler
({
src
:
'
/formhandler-data
'
,
columns
:
[{
...
...
@@ -38,11 +45,7 @@
},
{
name
:
'
Stripes
'
,
unique
:
[
'
Verticalfffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
'
,
'
Horizontal
'
,
'
Diagonal
'
],
unique
:
stripes_unique_values
,
editable
:
{
input
:
'
select
'
,
options
:
[
...
...
@@ -59,7 +62,66 @@
]
})
.
on
(
'
load
'
,
function
()
{
// test for search & checkbox ALL state management
var
$this
=
$
(
'
.unique-filters
'
)
// when modal "Filter by Values..." is clicked,
// template inside should be rendered with checkbox & labels
$
(
'
[data-target="#fh-unique-modal-0"]
'
,
$this
).
first
().
click
()
test
.
equals
(
$
(
'
.fh-unique label
'
).
length
,
stripes_unique_values
.
length
+
1
)
// when clicked "cancel" and again clicked "Filter by Values...", template again should be rendered with checkbox & labels
$
(
'
data-dismiss="modal"
'
,
$
(
'
.unique-filters formhandler-unique-table-modal
'
)).
click
()
$
(
'
[data-target="#fh-unique-modal-0"]
'
,
$this
).
first
().
click
()
test
.
equals
(
$
(
'
.fh-unique label
'
).
length
,
stripes_unique_values
.
length
+
1
)
// when clicked a label/checkbox, and clicked cancel,
$
(
'
.fh-label-unique-values input
'
).
first
().
click
()
$
(
'
data-dismiss="modal"
'
,
$
(
'
.unique-filters formhandler-unique-table-modal
'
)).
click
()
// and reclicked "Filter by Values", template must be rendered with checkobx selected
$
(
'
[data-target="#fh-unique-modal-0"]
'
,
$this
).
first
().
click
()
test
.
ok
(
$
(
'
.fh-label-unique-values input
'
).
first
().
prop
(
'
checked
'
),
true
)
// on click cancel, and clicked other column modal, contents must be for that column and not prev column
$
(
'
[data-target="#fh-unique-modal-0"]
'
,
$this
).
last
().
click
()
test
.
ok
(
$
(
'
.fh-label-unique-values input
'
).
length
,
0
)
// on changing search input, d-none class must be added to non-matched items
$
(
'
input[type="search"]
'
,
$this
).
val
(
'
Diag
'
).
change
().
trigger
(
'
search
'
)
test
.
equals
(
$
(
'
.fh-unique .fh-label-unique-values:not(.d-none)
'
,
$this
).
length
,
1
)
// on clearing search, no item should have d-none class
$
(
'
input[type="search"]
'
,
$this
).
val
(
''
).
change
().
trigger
(
'
search
'
)
test
.
equals
(
$
(
'
.fh-unique .fh-label-unique-values:not(.d-none)
'
,
$this
).
length
,
stripes_unique_values
.
length
)
// on click of "All", all checkboxes must be checked
$
(
'
.fh-select-all
'
,
$this
).
click
()
test
.
equals
(
$
(
'
.fh-unique-values:checked
'
,
$this
).
length
,
stripes_unique_values
.
length
)
// on click of a checkbox, All must be deselected and except that checkbox, other values must remain selected
$
(
'
.fh-label-unique-values input
'
).
first
().
click
()
test
.
notOk
(
$
(
'
.fh-select-all
'
,
$this
).
prop
(
'
checked
'
))
test
.
equals
(
$
(
'
.fh-unique-values:checked
'
,
$this
).
length
,
stripes_unique_values
.
length
-
1
)
// on click of "All", all checkboxes must be checked
$
(
'
.fh-select-all
'
,
$this
).
click
()
test
.
equals
(
$
(
'
.fh-unique-values:checked
'
,
$this
).
length
,
stripes_unique_values
.
length
)
// on click of "ALl" again, all checkboxes must be deselected
$
(
'
.fh-select-all
'
,
$this
).
click
()
test
.
equals
(
$
(
'
.fh-unique-values:checked
'
,
$this
).
length
,
0
)
// on changing search input, and clicking on All and clearing search input, only few checkboxes get checked and All is deselected
$
(
'
input[type="search"]
'
,
$this
).
val
(
'
Diag
'
).
change
().
trigger
(
'
search
'
)
$
(
'
.fh-select-all
'
,
$this
).
click
()
$
(
'
input[type="search"]
'
,
$this
).
val
(
''
).
change
().
trigger
(
'
search
'
)
test
.
equals
(
$
(
'
.fh-unique-values:checked
'
,
$this
).
length
,
1
)
test
.
equals
(
$
(
'
.fh-unique .fh-label-unique-values:not(.d-none)
'
,
$this
).
length
,
3
)
test
.
notOk
(
$
(
'
.fh-select-all
'
,
$this
).
prop
(
'
checked
'
))
// on click of "All", all checkboxes must be selected
$
(
'
.fh-select-all
'
,
$this
).
click
()
test
.
equals
(
$
(
'
.fh-unique-values:checked
'
,
$this
).
length
,
stripes_unique_values
.
length
)
test
.
ok
(
$
(
'
.fh-select-all
'
,
$this
).
prop
(
'
checked
'
))
test
.
end
()
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment