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
a32000a3
Commit
a32000a3
authored
Sep 04, 2020
by
Natalia Tepluhina
Committed by
Illya Klymov
Sep 04, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Abstract mocking Apollo client to helper method
parent
7e0e3508
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
33 deletions
+35
-33
spec/frontend/design_management/pages/index_apollo_spec.js
spec/frontend/design_management/pages/index_apollo_spec.js
+12
-33
spec/frontend/helpers/mock_apollo_helper.js
spec/frontend/helpers/mock_apollo_helper.js
+23
-0
No files found.
spec/frontend/design_management/pages/index_apollo_spec.js
View file @
a32000a3
import
{
shallowMount
,
createLocalVue
}
from
'
@vue/test-utils
'
;
import
{
createMockClient
}
from
'
mock-apollo-client
'
;
import
VueApollo
from
'
vue-apollo
'
;
import
VueRouter
from
'
vue-router
'
;
import
VueDraggable
from
'
vuedraggable
'
;
import
{
InMemoryCache
}
from
'
apollo-cache-inmemory
'
;
import
Design
from
'
~/design_management/components/list/item.vue
'
;
import
createRouter
from
'
~/design_management/router
'
;
import
getDesignListQuery
from
'
~/design_management/graphql/queries/get_design_list.query.graphql
'
;
import
permissionsQuery
from
'
~/design_management/graphql/queries/design_permissions.query.graphql
'
;
import
moveDesignMutation
from
'
~/design_management/graphql/mutations/move_design.mutation.graphql
'
;
import
{
deprecatedCreateFlash
as
createFlash
}
from
'
~/flash
'
;
import
createMockApollo
from
'
../../helpers/mock_apollo_helper
'
;
import
Index
from
'
~/design_management/pages/index.vue
'
;
import
{
designListQueryResponse
,
...
...
@@ -39,8 +38,7 @@ const designToMove = {
describe
(
'
Design management index page with Apollo mock
'
,
()
=>
{
let
wrapper
;
let
mockClient
;
let
apolloProvider
;
let
fakeApollo
;
let
moveDesignHandler
;
async
function
moveDesigns
(
localWrapper
)
{
...
...
@@ -56,41 +54,23 @@ describe('Design management index page with Apollo mock', () => {
});
}
const
fragmentMatcher
=
{
match
:
()
=>
true
};
const
cache
=
new
InMemoryCache
({
fragmentMatcher
,
addTypename
:
false
,
});
const
findDesigns
=
()
=>
wrapper
.
findAll
(
Design
);
function
createComponent
({
moveHandler
=
jest
.
fn
().
mockResolvedValue
(
moveDesignMutationResponse
),
})
{
mockClient
=
createMockClient
({
cache
});
mockClient
.
setRequestHandler
(
getDesignListQuery
,
jest
.
fn
().
mockResolvedValue
(
designListQueryResponse
),
);
mockClient
.
setRequestHandler
(
permissionsQuery
,
jest
.
fn
().
mockResolvedValue
(
permissionsQueryResponse
),
);
moveDesignHandler
=
moveHandler
;
mockClient
.
setRequestHandler
(
moveDesignMutation
,
moveDesignHandler
);
apolloProvider
=
new
VueApollo
({
defaultClient
:
mockClient
,
})
;
const
requestHandlers
=
[
[
getDesignListQuery
,
jest
.
fn
().
mockResolvedValue
(
designListQueryResponse
)],
[
permissionsQuery
,
jest
.
fn
().
mockResolvedValue
(
permissionsQueryResponse
)],
[
moveDesignMutation
,
moveDesignHandler
]
,
]
;
fakeApollo
=
createMockApollo
(
requestHandlers
);
wrapper
=
shallowMount
(
Index
,
{
localVue
,
apolloProvider
,
apolloProvider
:
fakeApollo
,
router
,
stubs
:
{
VueDraggable
},
});
...
...
@@ -99,8 +79,6 @@ describe('Design management index page with Apollo mock', () => {
afterEach
(()
=>
{
wrapper
.
destroy
();
wrapper
=
null
;
mockClient
=
null
;
apolloProvider
=
null
;
});
it
(
'
has a design with id 1 as a first one
'
,
async
()
=>
{
...
...
@@ -152,8 +130,9 @@ describe('Design management index page with Apollo mock', () => {
await
moveDesigns
(
wrapper
);
await
jest
.
runOnlyPendingTimers
();
await
wrapper
.
vm
.
$nextTick
();
await
wrapper
.
vm
.
$nextTick
();
// kick off the DOM update
await
jest
.
runOnlyPendingTimers
();
// kick off the mocked GQL stuff (promises)
await
wrapper
.
vm
.
$nextTick
();
// kick off the DOM update for flash
expect
(
createFlash
).
toHaveBeenCalledWith
(
'
Something went wrong when reordering designs. Please try again
'
,
...
...
spec/frontend/helpers/mock_apollo_helper.js
0 → 100644
View file @
a32000a3
import
{
InMemoryCache
}
from
'
apollo-cache-inmemory
'
;
import
{
createMockClient
}
from
'
mock-apollo-client
'
;
import
VueApollo
from
'
vue-apollo
'
;
export
default
(
handlers
=
[])
=>
{
const
fragmentMatcher
=
{
match
:
()
=>
true
};
const
cache
=
new
InMemoryCache
({
fragmentMatcher
,
addTypename
:
false
,
});
const
mockClient
=
createMockClient
({
cache
});
if
(
Array
.
isArray
(
handlers
))
{
handlers
.
forEach
(([
query
,
value
])
=>
mockClient
.
setRequestHandler
(
query
,
value
));
}
else
{
throw
new
Error
(
'
You should pass an array of handlers to mock Apollo client
'
);
}
const
apolloProvider
=
new
VueApollo
({
defaultClient
:
mockClient
});
return
apolloProvider
;
};
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