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
a85e11f7
Commit
a85e11f7
authored
Apr 07, 2022
by
Sean Arnold
Committed by
Andrew Fontaine
Apr 07, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move incident metrics logic to shared location
parent
f3c54c92
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
196 additions
and
80 deletions
+196
-80
app/assets/javascripts/issues/show/components/incidents/incident_tabs.vue
...cripts/issues/show/components/incidents/incident_tabs.vue
+4
-3
app/assets/javascripts/vue_shared/components/metric_images/metric_images_tab.vue
...vue_shared/components/metric_images/metric_images_tab.vue
+6
-8
app/assets/javascripts/vue_shared/components/metric_images/metric_images_table.vue
...e_shared/components/metric_images/metric_images_table.vue
+0
-0
app/assets/javascripts/vue_shared/components/metric_images/store/actions.js
...ipts/vue_shared/components/metric_images/store/actions.js
+85
-0
app/assets/javascripts/vue_shared/components/metric_images/store/index.js
...cripts/vue_shared/components/metric_images/store/index.js
+3
-3
app/assets/javascripts/vue_shared/components/metric_images/store/mutation_types.js
...e_shared/components/metric_images/store/mutation_types.js
+0
-0
app/assets/javascripts/vue_shared/components/metric_images/store/mutations.js
...ts/vue_shared/components/metric_images/store/mutations.js
+2
-2
app/assets/javascripts/vue_shared/components/metric_images/store/state.js
...cripts/vue_shared/components/metric_images/store/state.js
+2
-2
ee/app/assets/javascripts/issues/show/components/incidents/incident_metric_tab.vue
.../issues/show/components/incidents/incident_metric_tab.vue
+17
-0
ee/app/assets/javascripts/issues/show/components/incidents/service.js
...s/javascripts/issues/show/components/incidents/service.js
+20
-7
ee/spec/frontend/issues/show/components/incidents/incident_tabs_spec.js
...nd/issues/show/components/incidents/incident_tabs_spec.js
+1
-0
ee/spec/frontend/issues/show/components/incidents/service_spec.js
...frontend/issues/show/components/incidents/service_spec.js
+11
-6
locale/gitlab.pot
locale/gitlab.pot
+12
-12
spec/frontend/issues/show/components/incidents/incident_tabs_spec.js
...nd/issues/show/components/incidents/incident_tabs_spec.js
+1
-0
spec/frontend/vue_shared/components/metric_images/__snapshots__/metric_images_table_spec.js.snap
...ric_images/__snapshots__/metric_images_table_spec.js.snap
+0
-0
spec/frontend/vue_shared/components/metric_images/metric_images_tab_spec.js
...shared/components/metric_images/metric_images_tab_spec.js
+10
-11
spec/frontend/vue_shared/components/metric_images/metric_images_table_spec.js
...ared/components/metric_images/metric_images_table_spec.js
+3
-3
spec/frontend/vue_shared/components/metric_images/mock_data.js
...frontend/vue_shared/components/metric_images/mock_data.js
+0
-0
spec/frontend/vue_shared/components/metric_images/store/actions_spec.js
...vue_shared/components/metric_images/store/actions_spec.js
+16
-20
spec/frontend/vue_shared/components/metric_images/store/mutations_spec.js
...e_shared/components/metric_images/store/mutations_spec.js
+3
-3
No files found.
app/assets/javascripts/issues/show/components/incidents/incident_tabs.vue
View file @
a85e11f7
...
...
@@ -17,12 +17,13 @@ export default {
GlTab
,
GlTabs
,
HighlightBar
,
MetricsTab
:
()
=>
import
(
'
ee_component/issues/show/components/incidents/metrics_tab.vue
'
),
TimelineTab
:
()
=>
import
(
'
ee_component/issues/show/components/incidents/timeline_events_tab.vue
'
),
IncidentMetricTab
:
()
=>
import
(
'
ee_component/issues/show/components/incidents/incident_metric_tab.vue
'
),
},
mixins
:
[
glFeatureFlagsMixin
()],
inject
:
[
'
fullPath
'
,
'
iid
'
,
'
uploadMetricsFeatureAvailable
'
],
inject
:
[
'
fullPath
'
,
'
iid
'
],
apollo
:
{
alert
:
{
query
:
getAlert
,
...
...
@@ -93,7 +94,7 @@ export default {
<highlight-bar
:alert=
"alert"
/>
<description-component
v-bind=
"$attrs"
/>
</gl-tab>
<
metrics-tab
v-if=
"uploadMetricsFeatureAvailable"
data-testid=
"metrics-tab"
/>
<
incident-metric-tab
/>
<gl-tab
v-if=
"alert"
class=
"alert-management-details"
...
...
ee/app/assets/javascripts/issues/show/components/incidents/metric
s_tab.vue
→
app/assets/javascripts/vue_shared/components/metric_images/metric_image
s_tab.vue
View file @
a85e11f7
...
...
@@ -3,8 +3,7 @@ import { GlFormGroup, GlFormInput, GlLoadingIcon, GlModal, GlTab } from '@gitlab
import
{
mapState
,
mapActions
}
from
'
vuex
'
;
import
{
__
,
s__
}
from
'
~/locale
'
;
import
UploadDropzone
from
'
~/vue_shared/components/upload_dropzone/upload_dropzone.vue
'
;
import
MetricsImage
from
'
./metrics_image.vue
'
;
import
createStore
from
'
./store
'
;
import
MetricImagesTable
from
'
~/vue_shared/components/metric_images/metric_images_table.vue
'
;
export
default
{
components
:
{
...
...
@@ -13,7 +12,7 @@ export default {
GlLoadingIcon
,
GlModal
,
GlTab
,
Metric
sImag
e
,
Metric
ImagesTabl
e
,
UploadDropzone
,
},
inject
:
[
'
canUpdate
'
,
'
projectId
'
,
'
iid
'
],
...
...
@@ -25,7 +24,6 @@ export default {
modalUrlText
:
''
,
};
},
store
:
createStore
(),
computed
:
{
...
mapState
([
'
metricImages
'
,
'
isLoadingMetricImages
'
,
'
isUploadingImage
'
]),
actionPrimaryProps
()
{
...
...
@@ -41,11 +39,11 @@ export default {
},
},
mounted
()
{
this
.
setInitialData
({
issue
Iid
:
this
.
iid
,
projectId
:
this
.
projectId
});
this
.
fetch
Metric
Images
();
this
.
setInitialData
({
model
Iid
:
this
.
iid
,
projectId
:
this
.
projectId
});
this
.
fetchImages
();
},
methods
:
{
...
mapActions
([
'
fetch
Metric
Images
'
,
'
uploadImage
'
,
'
setInitialData
'
]),
...
mapActions
([
'
fetchImages
'
,
'
uploadImage
'
,
'
setInitialData
'
]),
clearInputs
()
{
this
.
modalVisible
=
false
;
this
.
modalUrl
=
''
;
...
...
@@ -111,7 +109,7 @@ export default {
<gl-form-input
id=
"upload-url-input"
v-model=
"modalUrl"
/>
</gl-form-group>
</gl-modal>
<metric
s-imag
e
v-for=
"metric in metricImages"
:key=
"metric.id"
v-bind=
"metric"
/>
<metric
-images-tabl
e
v-for=
"metric in metricImages"
:key=
"metric.id"
v-bind=
"metric"
/>
<upload-dropzone
v-if=
"canUpdate"
:drop-description-message=
"$options.i18n.dropDescription"
...
...
ee/app/assets/javascripts/issues/show/components/incidents/metrics_imag
e.vue
→
app/assets/javascripts/vue_shared/components/metric_images/metric_images_tabl
e.vue
View file @
a85e11f7
File moved
ee/app/assets/javascripts/issues/show/components/incident
s/store/actions.js
→
app/assets/javascripts/vue_shared/components/metric_image
s/store/actions.js
View file @
a85e11f7
import
createFlash
from
'
~/flash
'
;
import
{
s__
}
from
'
~/locale
'
;
import
{
deleteMetricImage
,
getMetricImages
,
uploadMetricImage
,
updateMetricImage
,
}
from
'
../service
'
;
import
*
as
types
from
'
./mutation_types
'
;
export
const
fetch
MetricImages
=
async
({
state
,
commit
})
=>
{
export
const
fetch
ImagesFactory
=
(
service
)
=>
async
({
state
,
commit
})
=>
{
commit
(
types
.
REQUEST_METRIC_IMAGES
);
const
{
issueIid
,
projectId
}
=
state
;
const
{
modelIid
,
projectId
}
=
state
;
try
{
const
response
=
await
getMetricImages
({
id
:
projectId
,
issue
Iid
});
const
response
=
await
service
.
getMetricImages
({
id
:
projectId
,
model
Iid
});
commit
(
types
.
RECEIVE_METRIC_IMAGES_SUCCESS
,
response
);
}
catch
(
error
)
{
commit
(
types
.
RECEIVE_METRIC_IMAGES_ERROR
);
createFlash
({
message
:
s__
(
'
Incident
s|There was an issue loading metric images.
'
)
});
createFlash
({
message
:
s__
(
'
MetricImage
s|There was an issue loading metric images.
'
)
});
}
};
export
const
uploadImage
=
async
({
state
,
commit
},
{
files
,
url
,
urlText
})
=>
{
export
const
uploadImageFactory
=
(
service
)
=>
async
(
{
state
,
commit
},
{
files
,
url
,
urlText
},
)
=>
{
commit
(
types
.
REQUEST_METRIC_UPLOAD
);
const
{
issue
Iid
,
projectId
}
=
state
;
const
{
model
Iid
,
projectId
}
=
state
;
try
{
const
response
=
await
uploadMetricImage
({
const
response
=
await
service
.
uploadMetricImage
({
file
:
files
.
item
(
0
),
id
:
projectId
,
issue
Iid
,
model
Iid
,
url
,
urlText
,
});
commit
(
types
.
RECEIVE_METRIC_UPLOAD_SUCCESS
,
response
);
}
catch
(
error
)
{
commit
(
types
.
RECEIVE_METRIC_UPLOAD_ERROR
);
createFlash
({
message
:
s__
(
'
Incident
s|There was an issue uploading your image.
'
)
});
createFlash
({
message
:
s__
(
'
MetricImage
s|There was an issue uploading your image.
'
)
});
}
};
export
const
updateImage
=
async
({
state
,
commit
},
{
imageId
,
url
,
urlText
})
=>
{
export
const
updateImageFactory
=
(
service
)
=>
async
(
{
state
,
commit
},
{
imageId
,
url
,
urlText
},
)
=>
{
commit
(
types
.
REQUEST_METRIC_UPLOAD
);
const
{
issue
Iid
,
projectId
}
=
state
;
const
{
model
Iid
,
projectId
}
=
state
;
try
{
const
response
=
await
updateMetricImage
({
issue
Iid
,
const
response
=
await
service
.
updateMetricImage
({
model
Iid
,
id
:
projectId
,
imageId
,
url
,
...
...
@@ -58,21 +57,29 @@ export const updateImage = async ({ state, commit }, { imageId, url, urlText })
commit
(
types
.
RECEIVE_METRIC_UPDATE_SUCCESS
,
response
);
}
catch
(
error
)
{
commit
(
types
.
RECEIVE_METRIC_UPLOAD_ERROR
);
createFlash
({
message
:
s__
(
'
Incident
s|There was an issue updating your image.
'
)
});
createFlash
({
message
:
s__
(
'
MetricImage
s|There was an issue updating your image.
'
)
});
}
};
export
const
deleteImage
=
async
({
state
,
commit
},
imageId
)
=>
{
const
{
issue
Iid
,
projectId
}
=
state
;
export
const
deleteImage
Factory
=
(
service
)
=>
async
({
state
,
commit
},
imageId
)
=>
{
const
{
model
Iid
,
projectId
}
=
state
;
try
{
await
deleteMetricImage
({
imageId
,
id
:
projectId
,
issue
Iid
});
await
service
.
deleteMetricImage
({
imageId
,
id
:
projectId
,
model
Iid
});
commit
(
types
.
RECEIVE_METRIC_DELETE_SUCCESS
,
imageId
);
}
catch
(
error
)
{
createFlash
({
message
:
s__
(
'
Incident
s|There was an issue deleting the image.
'
)
});
createFlash
({
message
:
s__
(
'
MetricImage
s|There was an issue deleting the image.
'
)
});
}
};
export
const
setInitialData
=
({
commit
},
data
)
=>
{
commit
(
types
.
SET_INITIAL_DATA
,
data
);
};
export
default
(
service
)
=>
({
fetchImages
:
fetchImagesFactory
(
service
),
uploadImage
:
uploadImageFactory
(
service
),
updateImage
:
updateImageFactory
(
service
),
deleteImage
:
deleteImageFactory
(
service
),
setInitialData
,
});
ee/app/assets/javascripts/issues/show/components/incident
s/store/index.js
→
app/assets/javascripts/vue_shared/components/metric_image
s/store/index.js
View file @
a85e11f7
import
Vue
from
'
vue
'
;
import
Vuex
from
'
vuex
'
;
import
*
as
actions
from
'
./actions
'
;
import
actionsFactory
from
'
./actions
'
;
import
mutations
from
'
./mutations
'
;
import
createState
from
'
./state
'
;
Vue
.
use
(
Vuex
);
export
default
(
initialState
)
=>
export
default
(
initialState
,
service
)
=>
new
Vuex
.
Store
({
actions
,
actions
:
actionsFactory
(
service
)
,
mutations
,
state
:
createState
(
initialState
),
});
ee/app/assets/javascripts/issues/show/components/incident
s/store/mutation_types.js
→
app/assets/javascripts/vue_shared/components/metric_image
s/store/mutation_types.js
View file @
a85e11f7
File moved
ee/app/assets/javascripts/issues/show/components/incident
s/store/mutations.js
→
app/assets/javascripts/vue_shared/components/metric_image
s/store/mutations.js
View file @
a85e11f7
...
...
@@ -32,8 +32,8 @@ export default {
const
metricIndex
=
state
.
metricImages
.
findIndex
((
image
)
=>
image
.
id
===
imageId
);
state
.
metricImages
.
splice
(
metricIndex
,
1
);
},
[
types
.
SET_INITIAL_DATA
](
state
,
{
issue
Iid
,
projectId
})
{
state
.
issueIid
=
issue
Iid
;
[
types
.
SET_INITIAL_DATA
](
state
,
{
model
Iid
,
projectId
})
{
state
.
modelIid
=
model
Iid
;
state
.
projectId
=
projectId
;
},
};
ee/app/assets/javascripts/issues/show/components/incident
s/store/state.js
→
app/assets/javascripts/vue_shared/components/metric_image
s/store/state.js
View file @
a85e11f7
export
default
({
issue
Iid
,
projectId
}
=
{})
=>
({
export
default
({
model
Iid
,
projectId
}
=
{})
=>
({
// Initial state
issue
Iid
,
model
Iid
,
projectId
,
// View state
...
...
ee/app/assets/javascripts/issues/show/components/incidents/incident_metric_tab.vue
0 → 100644
View file @
a85e11f7
<
script
>
import
MetricImagesTab
from
'
~/vue_shared/components/metric_images/metric_images_tab.vue
'
;
import
service
from
'
ee_component/issues/show/components/incidents/service
'
;
import
createStore
from
'
~/vue_shared/components/metric_images/store
'
;
export
default
{
components
:
{
MetricImagesTab
,
},
inject
:
[
'
uploadMetricsFeatureAvailable
'
],
store
:
createStore
({},
service
),
};
</
script
>
<
template
>
<metric-images-tab
v-if=
"uploadMetricsFeatureAvailable"
data-testid=
"metrics-tab"
/>
</
template
>
ee/app/assets/javascripts/issues/show/components/incidents/service.js
View file @
a85e11f7
import
Api
from
'
ee/api
'
;
import
{
convertObjectPropsToCamelCase
}
from
'
~/lib/utils/common_utils
'
;
function
replaceModelIId
(
payload
=
{})
{
const
{
modelIid
,
...
rest
}
=
payload
;
return
{
issueIid
:
modelIid
,
...
rest
};
}
export
const
getMetricImages
=
async
(
payload
)
=>
{
const
response
=
await
Api
.
fetchIssueMetricImages
(
payload
);
const
apiPayload
=
replaceModelIId
(
payload
);
const
response
=
await
Api
.
fetchIssueMetricImages
(
apiPayload
);
return
convertObjectPropsToCamelCase
(
response
.
data
,
{
deep
:
true
});
};
export
const
uploadMetricImage
=
async
(
payload
)
=>
{
const
response
=
await
Api
.
uploadIssueMetricImage
(
payload
);
const
apiPayload
=
replaceModelIId
(
payload
);
const
response
=
await
Api
.
uploadIssueMetricImage
(
apiPayload
);
return
convertObjectPropsToCamelCase
(
response
.
data
);
};
export
const
updateMetricImage
=
async
(
payload
)
=>
{
const
response
=
await
Api
.
updateIssueMetricImage
(
payload
);
const
apiPayload
=
replaceModelIId
(
payload
);
const
response
=
await
Api
.
updateIssueMetricImage
(
apiPayload
);
return
convertObjectPropsToCamelCase
(
response
.
data
);
};
export
const
deleteMetricImage
=
async
(
payload
)
=>
{
const
response
=
await
Api
.
deleteMetricImage
(
payload
);
const
apiPayload
=
replaceModelIId
(
payload
);
const
response
=
await
Api
.
deleteMetricImage
(
apiPayload
);
return
convertObjectPropsToCamelCase
(
response
.
data
);
};
export
default
{
getMetricImages
,
uploadMetricImage
,
updateMetricImage
,
deleteMetricImage
,
};
ee/spec/frontend/issues/show/components/incidents/incident_tabs_spec.js
View file @
a85e11f7
...
...
@@ -28,6 +28,7 @@ describe('Incident Tabs component', () => {
provide
:
{
fullPath
:
''
,
iid
:
''
,
projectId
:
''
,
uploadMetricsFeatureAvailable
:
true
,
glFeatures
:
{
incidentTimeline
:
true
,
incidentTimelineEvents
:
true
},
},
...
...
ee/spec/frontend/issues/show/components/incidents/service_spec.js
View file @
a85e11f7
import
{
fileList
,
fileListRaw
}
from
'
jest/vue_shared/components/metric_images/mock_data
'
;
import
Api
from
'
ee/api
'
;
import
{
getMetricImages
,
uploadMetricImage
,
updateMetricImage
,
deleteMetricImage
,
}
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
(),
}));
jest
.
mock
(
'
ee/api
'
);
describe
(
'
Incidents service
'
,
()
=>
{
it
(
'
fetches metric images
'
,
async
()
=>
{
...
...
@@ -36,4 +33,12 @@ describe('Incidents service', () => {
expect
(
Api
.
updateIssueMetricImage
).
toHaveBeenCalled
();
expect
(
result
).
toEqual
(
fileList
[
0
]);
});
it
(
'
deletes a metric image
'
,
async
()
=>
{
Api
.
deleteMetricImage
.
mockResolvedValue
({
data
:
''
});
const
result
=
await
deleteMetricImage
();
expect
(
Api
.
deleteMetricImage
).
toHaveBeenCalled
();
expect
(
result
).
toEqual
({});
});
});
locale/gitlab.pot
View file @
a85e11f7
...
...
@@ -19913,18 +19913,6 @@ msgstr ""
msgid "Incidents|Must start with http or https"
msgstr ""
msgid "Incidents|There was an issue deleting the image."
msgstr ""
msgid "Incidents|There was an issue loading metric images."
msgstr ""
msgid "Incidents|There was an issue updating your image."
msgstr ""
msgid "Incidents|There was an issue uploading your image."
msgstr ""
msgid "Incident|Add new timeline event"
msgstr ""
...
...
@@ -23871,6 +23859,18 @@ msgstr ""
msgid "MetricChart|There is too much data to calculate. Please change your selection."
msgstr ""
msgid "MetricImages|There was an issue deleting the image."
msgstr ""
msgid "MetricImages|There was an issue loading metric images."
msgstr ""
msgid "MetricImages|There was an issue updating your image."
msgstr ""
msgid "MetricImages|There was an issue uploading your image."
msgstr ""
msgid "Metrics"
msgstr ""
...
...
spec/frontend/issues/show/components/incidents/incident_tabs_spec.js
View file @
a85e11f7
...
...
@@ -34,6 +34,7 @@ describe('Incident Tabs component', () => {
provide
:
{
fullPath
:
''
,
iid
:
''
,
projectId
:
''
,
uploadMetricsFeatureAvailable
:
true
,
glFeatures
:
{
incidentTimeline
:
true
,
incidentTimelineEvents
:
true
},
},
...
...
ee/spec/frontend/issues/show/components/incidents/__snapshots__/metrics_imag
e_spec.js.snap
→
spec/frontend/vue_shared/components/metric_images/__snapshots__/metric_images_tabl
e_spec.js.snap
View file @
a85e11f7
File moved
ee/spec/frontend/issues/show/components/incidents/metric
s_tab_spec.js
→
spec/frontend/vue_shared/components/metric_images/metric_image
s_tab_spec.js
View file @
a85e11f7
...
...
@@ -3,31 +3,30 @@ import { shallowMount } from '@vue/test-utils';
import
Vue
from
'
vue
'
;
import
merge
from
'
lodash/merge
'
;
import
Vuex
from
'
vuex
'
;
import
MetricsImage
from
'
ee/issues/show/components/incidents/metrics_image.vue
'
;
import
MetricsTab
from
'
ee/issues/show/components/incidents/metrics_tab.vue
'
;
import
{
getMetricImages
}
from
'
ee/issues/show/components/incidents/service
'
;
import
createStore
from
'
ee/issues/show/components/incidents/store
'
;
import
MetricImagesTable
from
'
~/vue_shared/components/metric_images/metric_images_table.vue
'
;
import
MetricImagesTab
from
'
~/vue_shared/components/metric_images/metric_images_tab.vue
'
;
import
createStore
from
'
~/vue_shared/components/metric_images/store
'
;
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
import
UploadDropzone
from
'
~/vue_shared/components/upload_dropzone/upload_dropzone.vue
'
;
import
{
fileList
,
initialData
}
from
'
./mock_data
'
;
jest
.
mock
(
'
ee/issues/show/components/incidents/service
'
,
()
=>
(
{
const
service
=
{
getMetricImages
:
jest
.
fn
(),
}
))
;
};
const
mockEvent
=
{
preventDefault
:
jest
.
fn
()
};
Vue
.
use
(
Vuex
);
describe
(
'
Metrics tab
'
,
()
=>
{
describe
(
'
Metric
image
s tab
'
,
()
=>
{
let
wrapper
;
let
store
;
const
mountComponent
=
(
options
=
{})
=>
{
store
=
createStore
();
store
=
createStore
(
{},
service
);
wrapper
=
shallowMount
(
MetricsTab
,
Metric
Image
sTab
,
merge
(
{
store
,
...
...
@@ -54,7 +53,7 @@ describe('Metrics tab', () => {
});
const
findUploadDropzone
=
()
=>
wrapper
.
findComponent
(
UploadDropzone
);
const
findImages
=
()
=>
wrapper
.
findAllComponents
(
Metric
sImag
e
);
const
findImages
=
()
=>
wrapper
.
findAllComponents
(
Metric
ImagesTabl
e
);
const
findModal
=
()
=>
wrapper
.
findComponent
(
GlModal
);
const
submitModal
=
()
=>
findModal
().
vm
.
$emit
(
'
primary
'
,
mockEvent
);
const
cancelModal
=
()
=>
findModal
().
vm
.
$emit
(
'
hidden
'
);
...
...
@@ -81,7 +80,7 @@ describe('Metrics tab', () => {
describe
(
'
onLoad action
'
,
()
=>
{
it
(
'
should load images
'
,
async
()
=>
{
getMetricImages
.
mockImplementation
(()
=>
Promise
.
resolve
(
fileList
));
service
.
getMetricImages
.
mockImplementation
(()
=>
Promise
.
resolve
(
fileList
));
mountComponent
();
...
...
ee/spec/frontend/issues/show/components/incidents/metrics_imag
e_spec.js
→
spec/frontend/vue_shared/components/metric_images/metric_images_tabl
e_spec.js
View file @
a85e11f7
...
...
@@ -3,8 +3,8 @@ import { shallowMount, mount } from '@vue/test-utils';
import
Vue
from
'
vue
'
;
import
merge
from
'
lodash/merge
'
;
import
Vuex
from
'
vuex
'
;
import
MetricsImage
from
'
ee/issues/show/components/incidents/metrics_image.vu
e
'
;
import
createStore
from
'
ee/issues/show/components/incidents/stor
e
'
;
import
createStore
from
'
~/vue_shared/components/metric_images/stor
e
'
;
import
MetricsImageTable
from
'
~/vue_shared/components/metric_images/metric_images_table.vu
e
'
;
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
const
defaultProps
=
{
...
...
@@ -25,7 +25,7 @@ describe('Metrics upload item', () => {
store
=
createStore
();
wrapper
=
mountMethod
(
MetricsImage
,
MetricsImage
Table
,
merge
(
{
store
,
...
...
ee/spec/frontend/issues/show/components/incident
s/mock_data.js
→
spec/frontend/vue_shared/components/metric_image
s/mock_data.js
View file @
a85e11f7
File moved
ee/spec/frontend/issues/show/components/incident
s/store/actions_spec.js
→
spec/frontend/vue_shared/components/metric_image
s/store/actions_spec.js
View file @
a85e11f7
import
Vue
from
'
vue
'
;
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
'
;
import
*
as
actions
from
'
ee/issues/show/components/incidents/store/actions
'
;
import
*
as
types
from
'
ee/issues/show/components/incidents/store/mutation_types
'
;
import
actionsFactory
from
'
~/vue_shared/components/metric_images/store/actions
'
;
import
*
as
types
from
'
~/vue_shared/components/metric_images/store/mutation_types
'
;
import
createStore
from
'
~/vue_shared/components/metric_images/store
'
;
import
testAction
from
'
helpers/vuex_action_helper
'
;
import
createFlash
from
'
~/flash
'
;
import
{
convertObjectPropsToCamelCase
}
from
'
~/lib/utils/common_utils
'
;
import
{
fileList
,
initialData
}
from
'
../mock_data
'
;
jest
.
mock
(
'
~/flash
'
);
jest
.
mock
(
'
ee/issues/show/components/incidents/service
'
,
()
=>
(
{
const
service
=
{
getMetricImages
:
jest
.
fn
(),
uploadMetricImage
:
jest
.
fn
(),
updateMetricImage
:
jest
.
fn
(),
deleteMetricImage
:
jest
.
fn
(),
}));
};
const
actions
=
actionsFactory
(
service
);
const
defaultState
=
{
issueIid
:
1
,
...
...
@@ -44,9 +40,9 @@ describe('Metrics tab store actions', () => {
describe
(
'
fetching metric images
'
,
()
=>
{
it
(
'
should call success action when fetching metric images
'
,
()
=>
{
getMetricImages
.
mockImplementation
(()
=>
Promise
.
resolve
(
fileList
));
service
.
getMetricImages
.
mockImplementation
(()
=>
Promise
.
resolve
(
fileList
));
testAction
(
actions
.
fetch
Metric
Images
,
null
,
state
,
[
testAction
(
actions
.
fetchImages
,
null
,
state
,
[
{
type
:
types
.
REQUEST_METRIC_IMAGES
},
{
type
:
types
.
RECEIVE_METRIC_IMAGES_SUCCESS
,
...
...
@@ -56,10 +52,10 @@ describe('Metrics tab store actions', () => {
});
it
(
'
should call error action when fetching metric images with an error
'
,
async
()
=>
{
getMetricImages
.
mockImplementation
(()
=>
Promise
.
reject
());
service
.
getMetricImages
.
mockImplementation
(()
=>
Promise
.
reject
());
await
testAction
(
actions
.
fetch
Metric
Images
,
actions
.
fetchImages
,
null
,
state
,
[{
type
:
types
.
REQUEST_METRIC_IMAGES
},
{
type
:
types
.
RECEIVE_METRIC_IMAGES_ERROR
}],
...
...
@@ -81,7 +77,7 @@ describe('Metrics tab store actions', () => {
};
it
(
'
should call success action when uploading an image
'
,
()
=>
{
uploadMetricImage
.
mockImplementation
(()
=>
Promise
.
resolve
(
fileList
[
0
]));
service
.
uploadMetricImage
.
mockImplementation
(()
=>
Promise
.
resolve
(
fileList
[
0
]));
testAction
(
actions
.
uploadImage
,
payload
,
state
,
[
{
type
:
types
.
REQUEST_METRIC_UPLOAD
},
...
...
@@ -93,7 +89,7 @@ describe('Metrics tab store actions', () => {
});
it
(
'
should call error action when failing to upload an image
'
,
async
()
=>
{
uploadMetricImage
.
mockImplementation
(()
=>
Promise
.
reject
());
service
.
uploadMetricImage
.
mockImplementation
(()
=>
Promise
.
reject
());
await
testAction
(
actions
.
uploadImage
,
...
...
@@ -113,7 +109,7 @@ describe('Metrics tab store actions', () => {
};
it
(
'
should call success action when updating an image
'
,
()
=>
{
updateMetricImage
.
mockImplementation
(()
=>
Promise
.
resolve
());
service
.
updateMetricImage
.
mockImplementation
(()
=>
Promise
.
resolve
());
testAction
(
actions
.
updateImage
,
payload
,
state
,
[
{
type
:
types
.
REQUEST_METRIC_UPLOAD
},
...
...
@@ -124,7 +120,7 @@ describe('Metrics tab store actions', () => {
});
it
(
'
should call error action when failing to update an image
'
,
async
()
=>
{
updateMetricImage
.
mockImplementation
(()
=>
Promise
.
reject
());
service
.
updateMetricImage
.
mockImplementation
(()
=>
Promise
.
reject
());
await
testAction
(
actions
.
updateImage
,
...
...
@@ -141,7 +137,7 @@ describe('Metrics tab store actions', () => {
const
payload
=
fileList
[
0
].
id
;
it
(
'
should call success action when deleting an image
'
,
()
=>
{
deleteMetricImage
.
mockImplementation
(()
=>
Promise
.
resolve
());
service
.
deleteMetricImage
.
mockImplementation
(()
=>
Promise
.
resolve
());
testAction
(
actions
.
deleteImage
,
payload
,
state
,
[
{
...
...
ee/spec/frontend/issues/show/components/incidents/store/mutation
_spec.js
→
spec/frontend/vue_shared/components/metric_images/store/mutations
_spec.js
View file @
a85e11f7
import
{
cloneDeep
}
from
'
lodash
'
;
import
*
as
types
from
'
ee/issues/show/components/incident
s/store/mutation_types
'
;
import
mutations
from
'
ee/issues/show/components/incident
s/store/mutations
'
;
import
*
as
types
from
'
~/vue_shared/components/metric_image
s/store/mutation_types
'
;
import
mutations
from
'
~/vue_shared/components/metric_image
s/store/mutations
'
;
import
{
initialData
}
from
'
../mock_data
'
;
const
defaultState
=
{
...
...
@@ -140,7 +140,7 @@ describe('Metric images mutations', () => {
});
it
(
'
should unset the loading state
'
,
()
=>
{
expect
(
state
.
issueIid
).
toBe
(
initialData
.
issue
Iid
);
expect
(
state
.
modelIid
).
toBe
(
initialData
.
model
Iid
);
expect
(
state
.
projectId
).
toBe
(
initialData
.
projectId
);
});
});
...
...
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