Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
a899612b
Commit
a899612b
authored
Jul 09, 2020
by
Micael Bergeron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests around the search autocomplete results
parent
3a40cdf2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
1 deletion
+77
-1
spec/frontend/search_autocomplete_spec.js
spec/frontend/search_autocomplete_spec.js
+77
-1
No files found.
spec/frontend/search_autocomplete_spec.js
View file @
a899612b
...
...
@@ -4,6 +4,8 @@ import $ from 'jquery';
import
'
~/gl_dropdown
'
;
import
initSearchAutocomplete
from
'
~/search_autocomplete
'
;
import
'
~/lib/utils/common_utils
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
AxiosMockAdapter
from
'
axios-mock-adapter
'
;
describe
(
'
Search autocomplete dropdown
'
,
()
=>
{
let
widget
=
null
;
...
...
@@ -16,6 +18,7 @@ describe('Search autocomplete dropdown', () => {
const
projectMRsPath
=
'
/gitlab-org/gitlab-foss/-/merge_requests
'
;
const
groupIssuesPath
=
'
/groups/gitlab-org/-/issues
'
;
const
groupMRsPath
=
'
/groups/gitlab-org/-/merge_requests
'
;
const
autocompletePath
=
'
/search/autocomplete
'
;
const
projectName
=
'
GitLab Community Edition
'
;
const
groupName
=
'
Gitlab Org
'
;
...
...
@@ -111,7 +114,7 @@ describe('Search autocomplete dropdown', () => {
window
.
gon
.
current_user_id
=
userId
;
window
.
gon
.
current_username
=
userName
;
return
(
widget
=
initSearchAutocomplete
());
return
(
widget
=
initSearchAutocomplete
(
{
autocompletePath
}
));
});
afterEach
(()
=>
{
...
...
@@ -181,6 +184,79 @@ describe('Search autocomplete dropdown', () => {
expect
(
submitSpy
).
not
.
toHaveBeenCalled
();
});
describe
(
'
show autocomplete results
'
,
()
=>
{
beforeEach
(()
=>
{
widget
.
enableAutocomplete
();
const
axiosMock
=
new
AxiosMockAdapter
(
axios
);
const
autocompleteUrl
=
new
RegExp
(
autocompletePath
);
axiosMock
.
onGet
(
autocompleteUrl
).
reply
(
200
,
[
{
category
:
'
Projects
'
,
id
:
1
,
value
:
'
Gitlab Test
'
,
label
:
'
Gitlab Org / Gitlab Test
'
,
url
:
'
/gitlab-org/gitlab-test
'
,
avatar_url
:
''
,
},
{
category
:
'
Groups
'
,
id
:
1
,
value
:
'
Gitlab Org
'
,
label
:
'
Gitlab Org
'
,
url
:
'
/gitlab-org
'
,
avatar_url
:
''
,
},
]);
});
function
triggerAutocomplete
()
{
return
new
Promise
(
resolve
=>
{
const
dropdown
=
widget
.
searchInput
.
data
(
'
glDropdown
'
);
const
filterCallback
=
dropdown
.
filter
.
options
.
callback
;
dropdown
.
filter
.
options
.
callback
=
jest
.
fn
(
data
=>
{
filterCallback
(
data
);
resolve
();
});
widget
.
searchInput
.
val
(
'
Gitlab
'
);
widget
.
searchInput
.
triggerHandler
(
'
input
'
);
});
}
it
(
'
suggest Projects
'
,
done
=>
{
// eslint-disable-next-line promise/catch-or-return
triggerAutocomplete
().
finally
(()
=>
{
const
list
=
widget
.
wrap
.
find
(
'
.dropdown-menu
'
).
find
(
'
ul
'
);
const
link
=
"
a[href$='/gitlab-org/gitlab-test']
"
;
expect
(
list
.
find
(
link
).
length
).
toBe
(
1
);
done
();
});
// Make sure jest properly acknowledge the `done` invocation
jest
.
runOnlyPendingTimers
();
});
it
(
'
suggest Groups
'
,
done
=>
{
// eslint-disable-next-line promise/catch-or-return
triggerAutocomplete
().
finally
(()
=>
{
const
list
=
widget
.
wrap
.
find
(
'
.dropdown-menu
'
).
find
(
'
ul
'
);
const
link
=
"
a[href$='/gitlab-org']
"
;
expect
(
list
.
find
(
link
).
length
).
toBe
(
1
);
done
();
});
// Make sure jest properly acknowledge the `done` invocation
jest
.
runOnlyPendingTimers
();
});
});
describe
(
'
disableAutocomplete
'
,
()
=>
{
beforeEach
(()
=>
{
widget
.
enableAutocomplete
();
...
...
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