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
Show 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 = {
export
const
metricsDashboardViewModel
=
mapToDashboardViewModel
(
metricsDashboardPayload
);
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
...
...
spec/frontend/monitoring/store/getters_spec.js
View file @
f13ae2fe
...
...
@@ -11,21 +11,16 @@ import {
storeVariables
,
mockLinks
,
}
from
'
../mock_data
'
;
import
{
metricsDashboardPayload
,
metricResultStatus
,
metricResultPods
,
metricResultEmpty
,
}
from
'
../fixture_data
'
;
import
{
metricsDashboardPayload
}
from
'
../fixture_data
'
;
describe
(
'
Monitoring store Getters
'
,
()
=>
{
describe
(
'
getMetricStates
'
,
()
=>
{
let
setupState
;
let
state
;
let
getMetricStates
;
const
setMetricSuccess
=
({
result
=
metricsResult
,
group
=
0
,
panel
=
0
,
metric
=
0
})
=>
{
const
{
metricId
}
=
state
.
dashboard
.
panelGroups
[
group
].
panels
[
panel
].
metrics
[
metric
];
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
:
{
...
...
@@ -35,13 +30,17 @@ describe('Monitoring store Getters', () => {
});
};
const
setMetricFailure
=
({
group
=
0
,
panel
=
0
,
metric
=
0
})
=>
{
const
{
metricId
}
=
state
.
dashboard
.
panelGroups
[
group
].
panels
[
panel
].
metrics
[
metric
]
;
const
setMetricFailure
=
({
group
,
panel
,
metric
}
=
{
})
=>
{
const
{
metricId
}
=
getMetric
({
group
,
panel
,
metric
})
;
mutations
[
types
.
RECEIVE_METRIC_RESULT_FAILURE
](
state
,
{
metricId
,
});
};
describe
(
'
getMetricStates
'
,
()
=>
{
let
setupState
;
let
getMetricStates
;
beforeEach
(()
=>
{
setupState
=
(
initState
=
{})
=>
{
state
=
initState
;
...
...
@@ -81,7 +80,7 @@ describe('Monitoring store Getters', () => {
it
(
'
on an empty metric with no result, returns NO_DATA
'
,
()
=>
{
mutations
[
types
.
RECEIVE_METRICS_DASHBOARD_SUCCESS
](
state
,
metricsDashboardPayload
);
setMetricSuccess
({
result
:
[],
group
:
2
});
setMetricSuccess
({
group
:
2
,
result
:
[]
});
expect
(
getMetricStates
()).
toEqual
([
metricStates
.
NO_DATA
]);
});
...
...
@@ -147,7 +146,6 @@ describe('Monitoring store Getters', () => {
describe
(
'
metricsWithData
'
,
()
=>
{
let
metricsWithData
;
let
setupState
;
let
state
;
beforeEach
(()
=>
{
setupState
=
(
initState
=
{})
=>
{
...
...
@@ -191,35 +189,39 @@ describe('Monitoring store Getters', () => {
it
(
'
an empty metric, returns empty
'
,
()
=>
{
mutations
[
types
.
RECEIVE_METRICS_DASHBOARD_SUCCESS
](
state
,
metricsDashboardPayload
);
mutations
[
types
.
RECEIVE_METRIC_RESULT_SUCCESS
](
state
,
metricResultEmpty
);
setMetricSuccess
({
result
:
[]
}
);
expect
(
metricsWithData
()).
toEqual
([]);
});
it
(
'
a metric with results, it returns a metric
'
,
()
=>
{
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
'
,
()
=>
{
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
({
panel
:
0
}
);
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
'
,
()
=>
{
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
expect
(
metricsWithData
(
state
.
dashboard
.
panelGroups
[
1
].
key
)).
toEqual
([
metricResultStatus
.
metricId
,
metricResultPods
.
metricId
,
getMetric
({
group
:
1
})
.
metricId
,
getMetric
({
group
:
1
,
panel
:
1
})
.
metricId
,
]);
// Second group has no metrics
...
...
@@ -229,7 +231,6 @@ describe('Monitoring store Getters', () => {
});
describe
(
'
filteredEnvironments
'
,
()
=>
{
let
state
;
const
setupState
=
(
initState
=
{})
=>
{
state
=
{
...
state
,
...
...
@@ -284,7 +285,6 @@ describe('Monitoring store Getters', () => {
describe
(
'
metricsSavedToDb
'
,
()
=>
{
let
metricsSavedToDb
;
let
state
;
let
mockData
;
beforeEach
(()
=>
{
...
...
@@ -335,8 +335,6 @@ describe('Monitoring store Getters', () => {
});
describe
(
'
getCustomVariablesParams
'
,
()
=>
{
let
state
;
beforeEach
(()
=>
{
state
=
{
variables
:
{},
...
...
@@ -367,58 +365,65 @@ describe('Monitoring store Getters', () => {
describe
(
'
selectedDashboard
'
,
()
=>
{
const
{
selectedDashboard
}
=
getters
;
const
localGetters
=
s
tate
=>
({
fullDashboardPath
:
getters
.
fullDashboardPath
(
s
tate
),
const
localGetters
=
localS
tate
=>
({
fullDashboardPath
:
getters
.
fullDashboardPath
(
localS
tate
),
});
it
(
'
returns a dashboard
'
,
()
=>
{
const
s
tate
=
{
const
localS
tate
=
{
allDashboards
:
dashboardGitResponse
,
currentDashboard
:
dashboardGitResponse
[
0
].
path
,
customDashboardBasePath
,
};
expect
(
selectedDashboard
(
state
,
localGetters
(
state
))).
toEqual
(
dashboardGitResponse
[
0
]);
expect
(
selectedDashboard
(
localState
,
localGetters
(
localState
))).
toEqual
(
dashboardGitResponse
[
0
],
);
});
it
(
'
returns a non-default dashboard
'
,
()
=>
{
const
s
tate
=
{
const
localS
tate
=
{
allDashboards
:
dashboardGitResponse
,
currentDashboard
:
dashboardGitResponse
[
1
].
path
,
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
'
,
()
=>
{
const
s
tate
=
{
const
localS
tate
=
{
allDashboards
:
dashboardGitResponse
,
currentDashboard
:
null
,
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
'
,
()
=>
{
const
s
tate
=
{
const
localS
tate
=
{
allDashboards
:
dashboardGitResponse
,
currentDashboard
:
'
wrong_path
'
,
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
'
,
()
=>
{
const
s
tate
=
{
const
localS
tate
=
{
allDashboards
:
[],
currentDashboard
:
dashboardGitResponse
[
0
].
path
,
customDashboardBasePath
,
};
expect
(
selectedDashboard
(
state
,
localGetters
(
s
tate
))).
toEqual
(
null
);
expect
(
selectedDashboard
(
localState
,
localGetters
(
localS
tate
))).
toEqual
(
null
);
});
});
describe
(
'
linksWithMetadata
'
,
()
=>
{
let
state
;
const
setupState
=
(
initState
=
{})
=>
{
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