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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
69f9ec77
Commit
69f9ec77
authored
Dec 20, 2018
by
Winnie Hellmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move ajax_cache_spec.js to Jest
parent
ee0a007f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
54 deletions
+31
-54
spec/frontend/lib/utils/ajax_cache_spec.js
spec/frontend/lib/utils/ajax_cache_spec.js
+31
-54
No files found.
spec/
javascripts
/lib/utils/ajax_cache_spec.js
→
spec/
frontend
/lib/utils/ajax_cache_spec.js
View file @
69f9ec77
...
@@ -94,68 +94,54 @@ describe('AjaxCache', () => {
...
@@ -94,68 +94,54 @@ describe('AjaxCache', () => {
beforeEach
(()
=>
{
beforeEach
(()
=>
{
mock
=
new
MockAdapter
(
axios
);
mock
=
new
MockAdapter
(
axios
);
spyOn
(
axios
,
'
get
'
).
and
.
callThrough
(
);
jest
.
spyOn
(
axios
,
'
get
'
);
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
mock
.
restore
();
mock
.
restore
();
});
});
it
(
'
stores and returns data from Ajax call if cache is empty
'
,
done
=>
{
it
(
'
stores and returns data from Ajax call if cache is empty
'
,
()
=>
{
mock
.
onGet
(
dummyEndpoint
).
reply
(
200
,
dummyResponse
);
mock
.
onGet
(
dummyEndpoint
).
reply
(
200
,
dummyResponse
);
AjaxCache
.
retrieve
(
dummyEndpoint
)
return
AjaxCache
.
retrieve
(
dummyEndpoint
).
then
(
data
=>
{
.
then
(
data
=>
{
expect
(
data
).
toEqual
(
dummyResponse
);
expect
(
data
).
toEqual
(
dummyResponse
);
expect
(
AjaxCache
.
internalStorage
[
dummyEndpoint
]).
toEqual
(
dummyResponse
);
expect
(
AjaxCache
.
internalStorage
[
dummyEndpoint
]).
toEqual
(
dummyResponse
);
});
})
.
then
(
done
)
.
catch
(
fail
);
});
});
it
(
'
makes no Ajax call if request is pending
'
,
done
=>
{
it
(
'
makes no Ajax call if request is pending
'
,
()
=>
{
mock
.
onGet
(
dummyEndpoint
).
reply
(
200
,
dummyResponse
);
mock
.
onGet
(
dummyEndpoint
).
reply
(
200
,
dummyResponse
);
AjaxCache
.
retrieve
(
dummyEndpoint
)
return
Promise
.
all
([
.
then
(
done
)
AjaxCache
.
retrieve
(
dummyEndpoint
),
.
catch
(
fail
);
AjaxCache
.
retrieve
(
dummyEndpoint
),
]).
then
(()
=>
{
AjaxCache
.
retrieve
(
dummyEndpoint
)
expect
(
axios
.
get
).
toHaveBeenCalledTimes
(
1
);
.
then
(
done
)
});
.
catch
(
fail
);
expect
(
axios
.
get
.
calls
.
count
()).
toBe
(
1
);
});
});
it
(
'
returns undefined if Ajax call fails and cache is empty
'
,
done
=>
{
it
(
'
returns undefined if Ajax call fails and cache is empty
'
,
()
=>
{
const
errorMessage
=
'
Network Error
'
;
const
errorMessage
=
'
Network Error
'
;
mock
.
onGet
(
dummyEndpoint
).
networkError
();
mock
.
onGet
(
dummyEndpoint
).
networkError
();
AjaxCache
.
retrieve
(
dummyEndpoint
)
expect
.
assertions
(
2
);
.
then
(
data
=>
fail
(
`Received unexpected data:
${
JSON
.
stringify
(
data
)}
`
))
return
AjaxCache
.
retrieve
(
dummyEndpoint
).
catch
(
error
=>
{
.
catch
(
error
=>
{
expect
(
error
.
message
).
toBe
(
`
${
dummyEndpoint
}
:
${
errorMessage
}
`
);
expect
(
error
.
message
).
toBe
(
`
${
dummyEndpoint
}
:
${
errorMessage
}
`
);
expect
(
error
.
textStatus
).
toBe
(
errorMessage
);
expect
(
error
.
textStatus
).
toBe
(
errorMessage
);
});
done
();
})
.
catch
(
fail
);
});
});
it
(
'
makes no Ajax call if matching data exists
'
,
done
=>
{
it
(
'
makes no Ajax call if matching data exists
'
,
()
=>
{
AjaxCache
.
internalStorage
[
dummyEndpoint
]
=
dummyResponse
;
AjaxCache
.
internalStorage
[
dummyEndpoint
]
=
dummyResponse
;
mock
.
onGet
(
dummyEndpoint
).
reply
(()
=>
{
fail
(
new
Error
(
'
expected no Ajax call!
'
));
});
AjaxCache
.
retrieve
(
dummyEndpoint
)
return
AjaxCache
.
retrieve
(
dummyEndpoint
).
then
(
data
=>
{
.
then
(
data
=>
{
expect
(
data
).
toBe
(
dummyResponse
);
expect
(
data
).
toBe
(
dummyResponse
);
expect
(
axios
.
get
).
not
.
toHaveBeenCalled
();
})
});
.
then
(
done
)
.
catch
(
fail
);
});
});
it
(
'
makes Ajax call even if matching data exists when forceRequest parameter is provided
'
,
done
=>
{
it
(
'
makes Ajax call even if matching data exists when forceRequest parameter is provided
'
,
()
=>
{
const
oldDummyResponse
=
{
const
oldDummyResponse
=
{
important
:
'
old dummy data
'
,
important
:
'
old dummy data
'
,
};
};
...
@@ -164,21 +150,12 @@ describe('AjaxCache', () => {
...
@@ -164,21 +150,12 @@ describe('AjaxCache', () => {
mock
.
onGet
(
dummyEndpoint
).
reply
(
200
,
dummyResponse
);
mock
.
onGet
(
dummyEndpoint
).
reply
(
200
,
dummyResponse
);
// Call without forceRetrieve param
return
Promise
.
all
([
AjaxCache
.
retrieve
(
dummyEndpoint
)
AjaxCache
.
retrieve
(
dummyEndpoint
),
.
then
(
data
=>
{
AjaxCache
.
retrieve
(
dummyEndpoint
,
true
),
expect
(
data
).
toBe
(
oldDummyResponse
);
]).
then
(
data
=>
{
})
expect
(
data
).
toEqual
([
oldDummyResponse
,
dummyResponse
]);
.
then
(
done
)
});
.
catch
(
fail
);
// Call with forceRetrieve param
AjaxCache
.
retrieve
(
dummyEndpoint
,
true
)
.
then
(
data
=>
{
expect
(
data
).
toEqual
(
dummyResponse
);
})
.
then
(
done
)
.
catch
(
fail
);
});
});
});
});
});
});
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