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
e53d8c73
Commit
e53d8c73
authored
Jan 13, 2021
by
Payton Burdette
Committed by
Nicolò Maria Mezzopera
Jan 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor spec to use mock apollo client
Ensure that apollo is tested with all use cases.
parent
bbf8d5fc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
18 deletions
+44
-18
spec/frontend/artifacts_settings/components/keep_latest_artifact_checkbox_spec.js
...settings/components/keep_latest_artifact_checkbox_spec.js
+44
-18
No files found.
spec/frontend/artifacts_settings/components/keep_latest_artifact_checkbox_spec.js
View file @
e53d8c73
import
{
GlFormCheckbox
,
GlLink
}
from
'
@gitlab/ui
'
;
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
{
shallowMount
,
createLocalVue
}
from
'
@vue/test-utils
'
;
import
VueApollo
from
'
vue-apollo
'
;
import
createMockApollo
from
'
jest/helpers/mock_apollo_helper
'
;
import
KeepLatestArtifactCheckbox
from
'
~/artifacts_settings/keep_latest_artifact_checkbox.vue
'
;
import
GetKeepLatestArtifactProjectSetting
from
'
~/artifacts_settings/graphql/queries/get_keep_latest_artifact_project_setting.query.graphql
'
;
import
UpdateKeepLatestArtifactProjectSetting
from
'
~/artifacts_settings/graphql/mutations/update_keep_latest_artifact_project_setting.mutation.graphql
'
;
const
localVue
=
createLocalVue
();
localVue
.
use
(
VueApollo
);
const
keepLatestArtifactMock
=
{
data
:
{
project
:
{
ciCdSettings
:
{
keepLatestArtifact
:
true
},
},
},
};
const
keepLatestArtifactMockResponse
=
{
data
:
{
ciCdSettingsUpdate
:
{
errors
:
[],
__typename
:
'
CiCdSettingsUpdatePayload
'
}
},
};
describe
(
'
Keep latest artifact checkbox
'
,
()
=>
{
let
wrapper
;
let
apolloProvider
;
let
requestHandlers
;
const
mutate
=
jest
.
fn
().
mockResolvedValue
();
const
fullPath
=
'
gitlab-org/gitlab
'
;
const
helpPagePath
=
'
/help/ci/pipelines/job_artifacts
'
;
const
findCheckbox
=
()
=>
wrapper
.
find
(
GlFormCheckbox
);
const
findHelpLink
=
()
=>
wrapper
.
find
(
GlLink
);
const
createComponent
=
()
=>
{
const
createComponent
=
(
handlers
)
=>
{
requestHandlers
=
{
keepLatestArtifactQueryHandler
:
jest
.
fn
().
mockResolvedValue
(
keepLatestArtifactMock
),
keepLatestArtifactMutationHandler
:
jest
.
fn
()
.
mockResolvedValue
(
keepLatestArtifactMockResponse
),
...
handlers
,
};
apolloProvider
=
createMockApollo
([
[
GetKeepLatestArtifactProjectSetting
,
requestHandlers
.
keepLatestArtifactQueryHandler
],
[
UpdateKeepLatestArtifactProjectSetting
,
requestHandlers
.
keepLatestArtifactMutationHandler
],
]);
wrapper
=
shallowMount
(
KeepLatestArtifactCheckbox
,
{
provide
:
{
fullPath
,
helpPagePath
,
},
mocks
:
{
$apollo
:
{
mutate
,
},
},
localVue
,
apolloProvider
,
});
};
...
...
@@ -34,6 +63,7 @@ describe('Keep latest artifact checkbox', () => {
afterEach
(()
=>
{
wrapper
.
destroy
();
wrapper
=
null
;
apolloProvider
=
null
;
});
it
(
'
displays the checkbox and the help link
'
,
()
=>
{
...
...
@@ -42,21 +72,17 @@ describe('Keep latest artifact checkbox', () => {
});
it
(
'
sets correct setting value in checkbox with query result
'
,
async
()
=>
{
await
wrapper
.
setData
({
keepLatestArtifact
:
true
});
await
wrapper
.
vm
.
$nextTick
();
expect
(
wrapper
.
element
).
toMatchSnapshot
();
});
it
(
'
calls mutation on artifact setting change with correct payload
'
,
()
=>
{
findCheckbox
().
vm
.
$emit
(
'
change
'
,
false
);
const
expected
=
{
mutation
:
UpdateKeepLatestArtifactProjectSetting
,
variables
:
{
fullPath
,
keepLatestArtifact
:
false
,
},
};
expect
(
mutate
).
toHaveBeenCalledWith
(
expected
);
expect
(
requestHandlers
.
keepLatestArtifactMutationHandler
).
toHaveBeenCalledWith
({
fullPath
,
keepLatestArtifact
:
false
,
});
});
});
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