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
549fb72e
Commit
549fb72e
authored
Mar 10, 2021
by
Mike Greiling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test for select2_utils axios transport helper
parent
8b787405
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
0 deletions
+100
-0
spec/frontend/lib/utils/select2_utils_spec.js
spec/frontend/lib/utils/select2_utils_spec.js
+100
-0
No files found.
spec/frontend/lib/utils/select2_utils_spec.js
0 → 100644
View file @
549fb72e
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
$
from
'
jquery
'
;
import
{
setHTMLFixture
}
from
'
helpers/fixtures
'
;
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
{
select2AxiosTransport
}
from
'
~/lib/utils/select2_utils
'
;
import
'
select2/select2
'
;
const
TEST_URL
=
'
/test/api/url
'
;
const
TEST_SEARCH_DATA
=
{
extraSearch
:
'
test
'
};
const
TEST_DATA
=
[{
id
:
1
}];
const
TEST_SEARCH
=
'
FOO
'
;
describe
(
'
lib/utils/select2_utils
'
,
()
=>
{
let
mock
;
let
resultsSpy
;
beforeEach
(()
=>
{
setHTMLFixture
(
'
<div><input id="root" /></div>
'
);
mock
=
new
MockAdapter
(
axios
);
resultsSpy
=
jest
.
fn
().
mockReturnValue
({
results
:
[]
});
});
afterEach
(()
=>
{
mock
.
restore
();
});
const
setupSelect2
=
(
input
)
=>
{
input
.
select2
({
ajax
:
{
url
:
TEST_URL
,
quietMillis
:
250
,
transport
:
select2AxiosTransport
,
data
(
search
,
page
)
{
return
{
search
,
page
,
...
TEST_SEARCH_DATA
,
};
},
results
:
resultsSpy
,
},
});
};
const
setupSelect2AndSearch
=
async
()
=>
{
const
$input
=
$
(
'
#root
'
);
setupSelect2
(
$input
);
$input
.
select2
(
'
search
'
,
TEST_SEARCH
);
jest
.
runOnlyPendingTimers
();
await
waitForPromises
();
};
describe
(
'
select2AxiosTransport
'
,
()
=>
{
it
(
'
uses axios to make request
'
,
async
()
=>
{
// setup mock response
const
replySpy
=
jest
.
fn
();
mock
.
onGet
(
TEST_URL
).
reply
((...
args
)
=>
replySpy
(...
args
));
await
setupSelect2AndSearch
();
expect
(
replySpy
).
toHaveBeenCalledWith
(
expect
.
objectContaining
({
url
:
TEST_URL
,
method
:
'
get
'
,
params
:
{
page
:
1
,
search
:
TEST_SEARCH
,
...
TEST_SEARCH_DATA
,
},
}),
);
});
it
.
each
`
headers | pagination
${{}}
|
$
{{
more
:
false
}
}
${{
'
X-PAGE
'
:
'
1
'
,
'
x-next-page
'
:
2
}
} |
${{
more
:
true
}
}
`
(
'
passes results and pagination to results callback, with headers=$headers
'
,
async
({
headers
,
pagination
})
=>
{
mock
.
onGet
(
TEST_URL
).
reply
(
200
,
TEST_DATA
,
headers
);
await
setupSelect2AndSearch
();
expect
(
resultsSpy
).
toHaveBeenCalledWith
(
{
results
:
TEST_DATA
,
pagination
},
1
,
expect
.
anything
(),
);
},
);
});
});
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