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
1772216f
Commit
1772216f
authored
Feb 09, 2022
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for update metric image JS changes
parent
36e1e7cb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
2 deletions
+67
-2
ee/app/assets/javascripts/issues/show/components/incidents/store/mutations.js
...ripts/issues/show/components/incidents/store/mutations.js
+1
-1
ee/spec/frontend/issues/show/components/incidents/service_spec.js
...frontend/issues/show/components/incidents/service_spec.js
+14
-1
ee/spec/frontend/issues/show/components/incidents/store/actions_spec.js
...nd/issues/show/components/incidents/store/actions_spec.js
+33
-0
ee/spec/frontend/issues/show/components/incidents/store/mutation_spec.js
...d/issues/show/components/incidents/store/mutation_spec.js
+19
-0
No files found.
ee/app/assets/javascripts/issues/show/components/incidents/store/mutations.js
View file @
1772216f
...
...
@@ -25,7 +25,7 @@ export default {
state
.
isUploadingImage
=
false
;
const
metricIndex
=
state
.
metricImages
.
findIndex
((
img
)
=>
img
.
id
===
image
.
id
);
if
(
metricIndex
>=
0
)
{
state
.
metricImages
.
splice
(
metricIndex
,
1
,
image
)
state
.
metricImages
.
splice
(
metricIndex
,
1
,
image
)
;
}
},
[
types
.
RECEIVE_METRIC_DELETE_SUCCESS
](
state
,
imageId
)
{
...
...
ee/spec/frontend/issues/show/components/incidents/service_spec.js
View file @
1772216f
import
Api
from
'
ee/api
'
;
import
{
getMetricImages
,
uploadMetricImage
}
from
'
ee/issues/show/components/incidents/service
'
;
import
{
getMetricImages
,
uploadMetricImage
,
updateMetricImage
,
}
from
'
ee/issues/show/components/incidents/service
'
;
import
{
fileList
,
fileListRaw
}
from
'
./mock_data
'
;
jest
.
mock
(
'
ee/api
'
,
()
=>
({
fetchIssueMetricImages
:
jest
.
fn
(),
uploadIssueMetricImage
:
jest
.
fn
(),
updateIssueMetricImage
:
jest
.
fn
(),
}));
describe
(
'
Incidents service
'
,
()
=>
{
...
...
@@ -23,4 +28,12 @@ describe('Incidents service', () => {
expect
(
Api
.
uploadIssueMetricImage
).
toHaveBeenCalled
();
expect
(
result
).
toEqual
(
fileList
[
0
]);
});
it
(
'
updates a metric image
'
,
async
()
=>
{
Api
.
updateIssueMetricImage
.
mockResolvedValue
({
data
:
fileListRaw
[
0
]
});
const
result
=
await
updateMetricImage
();
expect
(
Api
.
updateIssueMetricImage
).
toHaveBeenCalled
();
expect
(
result
).
toEqual
(
fileList
[
0
]);
});
});
ee/spec/frontend/issues/show/components/incidents/store/actions_spec.js
View file @
1772216f
...
...
@@ -3,6 +3,7 @@ import Vuex from 'vuex';
import
{
getMetricImages
,
uploadMetricImage
,
updateMetricImage
,
deleteMetricImage
,
}
from
'
ee/issues/show/components/incidents/service
'
;
import
createStore
from
'
ee/issues/show/components/incidents/store
'
;
...
...
@@ -17,6 +18,7 @@ jest.mock('~/flash');
jest
.
mock
(
'
ee/issues/show/components/incidents/service
'
,
()
=>
({
getMetricImages
:
jest
.
fn
(),
uploadMetricImage
:
jest
.
fn
(),
updateMetricImage
:
jest
.
fn
(),
deleteMetricImage
:
jest
.
fn
(),
}));
...
...
@@ -104,6 +106,37 @@ describe('Metrics tab store actions', () => {
});
});
describe
(
'
updating metric images
'
,
()
=>
{
const
payload
=
{
url
:
'
test_url
'
,
urlText
:
'
url text
'
,
};
it
(
'
should call success action when updating an image
'
,
()
=>
{
updateMetricImage
.
mockImplementation
(()
=>
Promise
.
resolve
());
testAction
(
actions
.
updateImage
,
payload
,
state
,
[
{
type
:
types
.
REQUEST_METRIC_UPLOAD
},
{
type
:
types
.
RECEIVE_METRIC_UPDATE_SUCCESS
,
},
]);
});
it
(
'
should call error action when failing to update an image
'
,
async
()
=>
{
updateMetricImage
.
mockImplementation
(()
=>
Promise
.
reject
());
await
testAction
(
actions
.
updateImage
,
payload
,
state
,
[{
type
:
types
.
REQUEST_METRIC_UPLOAD
},
{
type
:
types
.
RECEIVE_METRIC_UPLOAD_ERROR
}],
[],
);
expect
(
createFlash
).
toHaveBeenCalled
();
});
});
describe
(
'
deleting a metric image
'
,
()
=>
{
const
payload
=
fileList
[
0
].
id
;
...
...
ee/spec/frontend/issues/show/components/incidents/store/mutation_spec.js
View file @
1772216f
...
...
@@ -101,6 +101,25 @@ describe('Metric images mutations', () => {
});
});
describe
(
'
RECEIVE_METRIC_UPDATE_SUCCESS
'
,
()
=>
{
const
initialImage
=
testImages
[
0
];
var
newImage
=
Object
.
assign
({},
testImages
[
0
]);
newImage
.
url
=
'
https://www.gitlab.com
'
;
beforeEach
(()
=>
{
createState
({
metricImages
:
[
initialImage
]
});
mutations
[
types
.
RECEIVE_METRIC_UPDATE_SUCCESS
](
state
,
newImage
);
});
it
(
'
should unset the loading state
'
,
()
=>
{
expect
(
state
.
isUploadingImage
).
toBe
(
false
);
});
it
(
'
should replace the existing image with the new one
'
,
()
=>
{
expect
(
state
.
metricImages
).
toMatchObject
([
newImage
]);
});
});
describe
(
'
RECEIVE_METRIC_DELETE_SUCCESS
'
,
()
=>
{
const
deletedImageId
=
testImages
[
1
].
id
;
const
expectedResult
=
[
testImages
[
0
],
testImages
[
2
]];
...
...
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