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
f13ae2fe
Commit
f13ae2fe
authored
Jul 28, 2020
by
Miguel Rincon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor to remove hardcoded mock data
We can simplify adding data to state by using already existing helpers.
parent
e5b26975
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
77 deletions
+59
-77
spec/frontend/monitoring/fixture_data.js
spec/frontend/monitoring/fixture_data.js
+0
-23
spec/frontend/monitoring/store/getters_spec.js
spec/frontend/monitoring/store/getters_spec.js
+59
-54
No files found.
spec/frontend/monitoring/fixture_data.js
View file @
f13ae2fe
...
@@ -36,29 +36,6 @@ export const dashboardProps = {
...
@@ -36,29 +36,6 @@ export const dashboardProps = {
export
const
metricsDashboardViewModel
=
mapToDashboardViewModel
(
metricsDashboardPayload
);
export
const
metricsDashboardViewModel
=
mapToDashboardViewModel
(
metricsDashboardPayload
);
export
const
metricsDashboardPanelCount
=
22
;
export
const
metricsDashboardPanelCount
=
22
;
export
const
metricResultStatus
=
{
// First metric in fixture `metrics_dashboard/environment_metrics_dashboard.json`
metricId
:
'
NO_DB_response_metrics_nginx_ingress_throughput_status_code
'
,
data
:
{
resultType
:
'
matrix
'
,
result
:
metricsResult
,
},
};
export
const
metricResultPods
=
{
// Second metric in fixture `metrics_dashboard/environment_metrics_dashboard.json`
metricId
:
'
NO_DB_response_metrics_nginx_ingress_latency_pod_average
'
,
data
:
{
resultType
:
'
matrix
'
,
result
:
metricsResult
,
},
};
export
const
metricResultEmpty
=
{
metricId
:
'
NO_DB_response_metrics_nginx_ingress_16_throughput_status_code
'
,
data
:
{
resultType
:
'
matrix
'
,
result
:
[],
},
};
// Graph data
// Graph data
...
...
spec/frontend/monitoring/store/getters_spec.js
View file @
f13ae2fe
...
@@ -11,37 +11,36 @@ import {
...
@@ -11,37 +11,36 @@ import {
storeVariables
,
storeVariables
,
mockLinks
,
mockLinks
,
}
from
'
../mock_data
'
;
}
from
'
../mock_data
'
;
import
{
import
{
metricsDashboardPayload
}
from
'
../fixture_data
'
;
metricsDashboardPayload
,
metricResultStatus
,
metricResultPods
,
metricResultEmpty
,
}
from
'
../fixture_data
'
;
describe
(
'
Monitoring store Getters
'
,
()
=>
{
describe
(
'
Monitoring store Getters
'
,
()
=>
{
let
state
;
const
getMetric
=
({
group
=
0
,
panel
=
0
,
metric
=
0
}
=
{})
=>
state
.
dashboard
.
panelGroups
[
group
].
panels
[
panel
].
metrics
[
metric
];
const
setMetricSuccess
=
({
group
,
panel
,
metric
,
result
=
metricsResult
}
=
{})
=>
{
const
{
metricId
}
=
getMetric
({
group
,
panel
,
metric
});
mutations
[
types
.
RECEIVE_METRIC_RESULT_SUCCESS
](
state
,
{
metricId
,
data
:
{
resultType
:
'
matrix
'
,
result
,
},
});
};
const
setMetricFailure
=
({
group
,
panel
,
metric
}
=
{})
=>
{
const
{
metricId
}
=
getMetric
({
group
,
panel
,
metric
});
mutations
[
types
.
RECEIVE_METRIC_RESULT_FAILURE
](
state
,
{
metricId
,
});
};
describe
(
'
getMetricStates
'
,
()
=>
{
describe
(
'
getMetricStates
'
,
()
=>
{
let
setupState
;
let
setupState
;
let
state
;
let
getMetricStates
;
let
getMetricStates
;
const
setMetricSuccess
=
({
result
=
metricsResult
,
group
=
0
,
panel
=
0
,
metric
=
0
})
=>
{
const
{
metricId
}
=
state
.
dashboard
.
panelGroups
[
group
].
panels
[
panel
].
metrics
[
metric
];
mutations
[
types
.
RECEIVE_METRIC_RESULT_SUCCESS
](
state
,
{
metricId
,
data
:
{
resultType
:
'
matrix
'
,
result
,
},
});
};
const
setMetricFailure
=
({
group
=
0
,
panel
=
0
,
metric
=
0
})
=>
{
const
{
metricId
}
=
state
.
dashboard
.
panelGroups
[
group
].
panels
[
panel
].
metrics
[
metric
];
mutations
[
types
.
RECEIVE_METRIC_RESULT_FAILURE
](
state
,
{
metricId
,
});
};
beforeEach
(()
=>
{
beforeEach
(()
=>
{
setupState
=
(
initState
=
{})
=>
{
setupState
=
(
initState
=
{})
=>
{
state
=
initState
;
state
=
initState
;
...
@@ -81,7 +80,7 @@ describe('Monitoring store Getters', () => {
...
@@ -81,7 +80,7 @@ describe('Monitoring store Getters', () => {
it
(
'
on an empty metric with no result, returns NO_DATA
'
,
()
=>
{
it
(
'
on an empty metric with no result, returns NO_DATA
'
,
()
=>
{
mutations
[
types
.
RECEIVE_METRICS_DASHBOARD_SUCCESS
](
state
,
metricsDashboardPayload
);
mutations
[
types
.
RECEIVE_METRICS_DASHBOARD_SUCCESS
](
state
,
metricsDashboardPayload
);
setMetricSuccess
({
result
:
[],
group
:
2
});
setMetricSuccess
({
group
:
2
,
result
:
[]
});
expect
(
getMetricStates
()).
toEqual
([
metricStates
.
NO_DATA
]);
expect
(
getMetricStates
()).
toEqual
([
metricStates
.
NO_DATA
]);
});
});
...
@@ -147,7 +146,6 @@ describe('Monitoring store Getters', () => {
...
@@ -147,7 +146,6 @@ describe('Monitoring store Getters', () => {
describe
(
'
metricsWithData
'
,
()
=>
{
describe
(
'
metricsWithData
'
,
()
=>
{
let
metricsWithData
;
let
metricsWithData
;
let
setupState
;
let
setupState
;
let
state
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
setupState
=
(
initState
=
{})
=>
{
setupState
=
(
initState
=
{})
=>
{
...
@@ -191,35 +189,39 @@ describe('Monitoring store Getters', () => {
...
@@ -191,35 +189,39 @@ describe('Monitoring store Getters', () => {
it
(
'
an empty metric, returns empty
'
,
()
=>
{
it
(
'
an empty metric, returns empty
'
,
()
=>
{
mutations
[
types
.
RECEIVE_METRICS_DASHBOARD_SUCCESS
](
state
,
metricsDashboardPayload
);
mutations
[
types
.
RECEIVE_METRICS_DASHBOARD_SUCCESS
](
state
,
metricsDashboardPayload
);
mutations
[
types
.
RECEIVE_METRIC_RESULT_SUCCESS
](
state
,
metricResultEmpty
);
setMetricSuccess
({
result
:
[]
}
);
expect
(
metricsWithData
()).
toEqual
([]);
expect
(
metricsWithData
()).
toEqual
([]);
});
});
it
(
'
a metric with results, it returns a metric
'
,
()
=>
{
it
(
'
a metric with results, it returns a metric
'
,
()
=>
{
mutations
[
types
.
RECEIVE_METRICS_DASHBOARD_SUCCESS
](
state
,
metricsDashboardPayload
);
mutations
[
types
.
RECEIVE_METRICS_DASHBOARD_SUCCESS
](
state
,
metricsDashboardPayload
);
mutations
[
types
.
RECEIVE_METRIC_RESULT_SUCCESS
](
state
,
metricResultStatus
);
setMetricSuccess
(
);
expect
(
metricsWithData
()).
toEqual
([
metricResultStatus
.
metricId
]);
expect
(
metricsWithData
()).
toEqual
([
getMetric
()
.
metricId
]);
});
});
it
(
'
multiple metrics with results, it return multiple metrics
'
,
()
=>
{
it
(
'
multiple metrics with results, it return multiple metrics
'
,
()
=>
{
mutations
[
types
.
RECEIVE_METRICS_DASHBOARD_SUCCESS
](
state
,
metricsDashboardPayload
);
mutations
[
types
.
RECEIVE_METRICS_DASHBOARD_SUCCESS
](
state
,
metricsDashboardPayload
);
mutations
[
types
.
RECEIVE_METRIC_RESULT_SUCCESS
](
state
,
metricResultStatus
);
setMetricSuccess
({
panel
:
0
}
);
mutations
[
types
.
RECEIVE_METRIC_RESULT_SUCCESS
](
state
,
metricResultPods
);
setMetricSuccess
({
panel
:
1
}
);
expect
(
metricsWithData
()).
toEqual
([
metricResultStatus
.
metricId
,
metricResultPods
.
metricId
]);
expect
(
metricsWithData
()).
toEqual
([
getMetric
({
panel
:
0
}).
metricId
,
getMetric
({
panel
:
1
}).
metricId
,
]);
});
});
it
(
'
multiple metrics with results, it returns metrics filtered by group
'
,
()
=>
{
it
(
'
multiple metrics with results, it returns metrics filtered by group
'
,
()
=>
{
mutations
[
types
.
RECEIVE_METRICS_DASHBOARD_SUCCESS
](
state
,
metricsDashboardPayload
);
mutations
[
types
.
RECEIVE_METRICS_DASHBOARD_SUCCESS
](
state
,
metricsDashboardPayload
);
mutations
[
types
.
RECEIVE_METRIC_RESULT_SUCCESS
](
state
,
metricResultStatus
);
mutations
[
types
.
RECEIVE_METRIC_RESULT_SUCCESS
](
state
,
metricResultPods
);
setMetricSuccess
({
group
:
1
});
setMetricSuccess
({
group
:
1
,
panel
:
1
});
// First group has metrics
// First group has metrics
expect
(
metricsWithData
(
state
.
dashboard
.
panelGroups
[
1
].
key
)).
toEqual
([
expect
(
metricsWithData
(
state
.
dashboard
.
panelGroups
[
1
].
key
)).
toEqual
([
metricResultStatus
.
metricId
,
getMetric
({
group
:
1
})
.
metricId
,
metricResultPods
.
metricId
,
getMetric
({
group
:
1
,
panel
:
1
})
.
metricId
,
]);
]);
// Second group has no metrics
// Second group has no metrics
...
@@ -229,7 +231,6 @@ describe('Monitoring store Getters', () => {
...
@@ -229,7 +231,6 @@ describe('Monitoring store Getters', () => {
});
});
describe
(
'
filteredEnvironments
'
,
()
=>
{
describe
(
'
filteredEnvironments
'
,
()
=>
{
let
state
;
const
setupState
=
(
initState
=
{})
=>
{
const
setupState
=
(
initState
=
{})
=>
{
state
=
{
state
=
{
...
state
,
...
state
,
...
@@ -284,7 +285,6 @@ describe('Monitoring store Getters', () => {
...
@@ -284,7 +285,6 @@ describe('Monitoring store Getters', () => {
describe
(
'
metricsSavedToDb
'
,
()
=>
{
describe
(
'
metricsSavedToDb
'
,
()
=>
{
let
metricsSavedToDb
;
let
metricsSavedToDb
;
let
state
;
let
mockData
;
let
mockData
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
...
@@ -335,8 +335,6 @@ describe('Monitoring store Getters', () => {
...
@@ -335,8 +335,6 @@ describe('Monitoring store Getters', () => {
});
});
describe
(
'
getCustomVariablesParams
'
,
()
=>
{
describe
(
'
getCustomVariablesParams
'
,
()
=>
{
let
state
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
state
=
{
state
=
{
variables
:
{},
variables
:
{},
...
@@ -367,58 +365,65 @@ describe('Monitoring store Getters', () => {
...
@@ -367,58 +365,65 @@ describe('Monitoring store Getters', () => {
describe
(
'
selectedDashboard
'
,
()
=>
{
describe
(
'
selectedDashboard
'
,
()
=>
{
const
{
selectedDashboard
}
=
getters
;
const
{
selectedDashboard
}
=
getters
;
const
localGetters
=
s
tate
=>
({
const
localGetters
=
localS
tate
=>
({
fullDashboardPath
:
getters
.
fullDashboardPath
(
s
tate
),
fullDashboardPath
:
getters
.
fullDashboardPath
(
localS
tate
),
});
});
it
(
'
returns a dashboard
'
,
()
=>
{
it
(
'
returns a dashboard
'
,
()
=>
{
const
s
tate
=
{
const
localS
tate
=
{
allDashboards
:
dashboardGitResponse
,
allDashboards
:
dashboardGitResponse
,
currentDashboard
:
dashboardGitResponse
[
0
].
path
,
currentDashboard
:
dashboardGitResponse
[
0
].
path
,
customDashboardBasePath
,
customDashboardBasePath
,
};
};
expect
(
selectedDashboard
(
state
,
localGetters
(
state
))).
toEqual
(
dashboardGitResponse
[
0
]);
expect
(
selectedDashboard
(
localState
,
localGetters
(
localState
))).
toEqual
(
dashboardGitResponse
[
0
],
);
});
});
it
(
'
returns a non-default dashboard
'
,
()
=>
{
it
(
'
returns a non-default dashboard
'
,
()
=>
{
const
s
tate
=
{
const
localS
tate
=
{
allDashboards
:
dashboardGitResponse
,
allDashboards
:
dashboardGitResponse
,
currentDashboard
:
dashboardGitResponse
[
1
].
path
,
currentDashboard
:
dashboardGitResponse
[
1
].
path
,
customDashboardBasePath
,
customDashboardBasePath
,
};
};
expect
(
selectedDashboard
(
state
,
localGetters
(
state
))).
toEqual
(
dashboardGitResponse
[
1
]);
expect
(
selectedDashboard
(
localState
,
localGetters
(
localState
))).
toEqual
(
dashboardGitResponse
[
1
],
);
});
});
it
(
'
returns a default dashboard when no dashboard is selected
'
,
()
=>
{
it
(
'
returns a default dashboard when no dashboard is selected
'
,
()
=>
{
const
s
tate
=
{
const
localS
tate
=
{
allDashboards
:
dashboardGitResponse
,
allDashboards
:
dashboardGitResponse
,
currentDashboard
:
null
,
currentDashboard
:
null
,
customDashboardBasePath
,
customDashboardBasePath
,
};
};
expect
(
selectedDashboard
(
state
,
localGetters
(
state
))).
toEqual
(
dashboardGitResponse
[
0
]);
expect
(
selectedDashboard
(
localState
,
localGetters
(
localState
))).
toEqual
(
dashboardGitResponse
[
0
],
);
});
});
it
(
'
returns a default dashboard when dashboard cannot be found
'
,
()
=>
{
it
(
'
returns a default dashboard when dashboard cannot be found
'
,
()
=>
{
const
s
tate
=
{
const
localS
tate
=
{
allDashboards
:
dashboardGitResponse
,
allDashboards
:
dashboardGitResponse
,
currentDashboard
:
'
wrong_path
'
,
currentDashboard
:
'
wrong_path
'
,
customDashboardBasePath
,
customDashboardBasePath
,
};
};
expect
(
selectedDashboard
(
state
,
localGetters
(
state
))).
toEqual
(
dashboardGitResponse
[
0
]);
expect
(
selectedDashboard
(
localState
,
localGetters
(
localState
))).
toEqual
(
dashboardGitResponse
[
0
],
);
});
});
it
(
'
returns null when no dashboards are present
'
,
()
=>
{
it
(
'
returns null when no dashboards are present
'
,
()
=>
{
const
s
tate
=
{
const
localS
tate
=
{
allDashboards
:
[],
allDashboards
:
[],
currentDashboard
:
dashboardGitResponse
[
0
].
path
,
currentDashboard
:
dashboardGitResponse
[
0
].
path
,
customDashboardBasePath
,
customDashboardBasePath
,
};
};
expect
(
selectedDashboard
(
state
,
localGetters
(
s
tate
))).
toEqual
(
null
);
expect
(
selectedDashboard
(
localState
,
localGetters
(
localS
tate
))).
toEqual
(
null
);
});
});
});
});
describe
(
'
linksWithMetadata
'
,
()
=>
{
describe
(
'
linksWithMetadata
'
,
()
=>
{
let
state
;
const
setupState
=
(
initState
=
{})
=>
{
const
setupState
=
(
initState
=
{})
=>
{
state
=
{
state
=
{
...
state
,
...
state
,
...
...
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