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
94db3338
Commit
94db3338
authored
Jun 11, 2021
by
Alexander Turinske
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor threat monitoring section tests
- make them more readable and organized - remove useless snapshot tests
parent
97d26284
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
122 deletions
+89
-122
ee/app/assets/javascripts/threat_monitoring/components/threat_monitoring_section.vue
...hreat_monitoring/components/threat_monitoring_section.vue
+3
-3
ee/spec/frontend/threat_monitoring/components/__snapshots__/threat_monitoring_section_spec.js.snap
...ents/__snapshots__/threat_monitoring_section_spec.js.snap
+0
-18
ee/spec/frontend/threat_monitoring/components/threat_monitoring_section_spec.js
...t_monitoring/components/threat_monitoring_section_spec.js
+86
-101
No files found.
ee/app/assets/javascripts/threat_monitoring/components/threat_monitoring_section.vue
View file @
94db3338
...
...
@@ -120,19 +120,19 @@ export default {
<
template
>
<div
class=
"my-3"
>
<h4
ref
=
"chartTitle"
class=
"h4"
>
{{
title
}}
</h4>
<h4
data-testid
=
"chartTitle"
class=
"h4"
>
{{
title
}}
</h4>
<loading-skeleton
v-if=
"isLoading"
class=
"mt-3"
/>
<template
v-else-if=
"hasHistory"
>
<h5
ref
=
"chartSubtitle"
class=
"h5"
>
{{
subtitle
}}
</h5>
<h5
data-testid
=
"chartSubtitle"
class=
"h5"
>
{{
subtitle
}}
</h5>
<statistics-summary
class=
"mt-3"
:data=
"summary"
/>
<statistics-history
class=
"mt-3"
:data=
"chart"
:y-legend=
"yLegend"
/>
</
template
>
<gl-empty-state
v-else
ref
=
"chartEmptyState"
data-testid
=
"chartEmptyState"
:title=
"chartEmptyStateTitle"
:description=
"chartEmptyStateText"
:svg-path=
"chartEmptyStateSvgPath"
...
...
ee/spec/frontend/threat_monitoring/components/__snapshots__/threat_monitoring_section_spec.js.snap
deleted
100644 → 0
View file @
97d26284
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`ThreatMonitoringSection component given the statistics are loading shows the loading skeleton 1`] = `
<loading-skeleton-stub
class="mt-3"
/>
`;
exports[`ThreatMonitoringSection component given there is a default environment with no data to display shows the chart empty state 1`] = `
<gl-empty-state-stub
compact="true"
description="Empty Text"
primarybuttonlink="documentation_path#anchor"
primarybuttontext="Learn more"
svgpath="svg_path"
title="Empty Title"
/>
`;
ee/spec/frontend/threat_monitoring/components/threat_monitoring_section_spec.js
View file @
94db3338
import
{
shallowMount
}
from
'
@vue/test-utils
'
;
import
LoadingSkeleton
from
'
ee/threat_monitoring/components/loading_skeleton.vue
'
;
import
StatisticsHistory
from
'
ee/threat_monitoring/components/statistics_history.vue
'
;
import
StatisticsSummary
from
'
ee/threat_monitoring/components/statistics_summary.vue
'
;
import
ThreatMonitoringSection
from
'
ee/threat_monitoring/components/threat_monitoring_section.vue
'
;
import
createStore
from
'
ee/threat_monitoring/store
'
;
import
{
shallowMountExtended
}
from
'
helpers/vue_test_utils_helper
'
;
import
{
mockNominalHistory
,
mockAnomalousHistory
}
from
'
../mocks/mock_data
'
;
...
...
@@ -11,6 +11,8 @@ describe('ThreatMonitoringSection component', () => {
let
store
;
let
wrapper
;
const
title
=
'
Test Title
'
;
const
timeRange
=
{
from
:
new
Date
(
Date
.
UTC
(
2020
,
2
,
6
)).
toISOString
(),
to
:
new
Date
(
Date
.
UTC
(
2020
,
2
,
13
)).
toISOString
(),
...
...
@@ -34,10 +36,10 @@ describe('ThreatMonitoringSection component', () => {
jest
.
spyOn
(
store
,
'
dispatch
'
).
mockImplementation
(()
=>
Promise
.
resolve
());
wrapper
=
shallowMount
(
ThreatMonitoringSection
,
{
wrapper
=
shallowMount
Extended
(
ThreatMonitoringSection
,
{
propsData
:
{
storeNamespace
:
'
threatMonitoringNetworkPolicy
'
,
title
:
'
Container Network Policy
'
,
title
,
subtitle
:
'
Requests
'
,
nominalTitle
:
'
Total Requests
'
,
anomalousTitle
:
'
Anomalous Requests
'
,
...
...
@@ -53,81 +55,84 @@ describe('ThreatMonitoringSection component', () => {
});
};
const
findLoadingSkeleton
=
()
=>
wrapper
.
find
(
LoadingSkeleton
);
const
findStatisticsHistory
=
()
=>
wrapper
.
find
(
StatisticsHistory
);
const
findStatisticsSummary
=
()
=>
wrapper
.
find
(
StatisticsSummary
);
const
findChartEmptyState
=
()
=>
wrapper
.
find
({
ref
:
'
chartEmptyState
'
});
const
findChartTitle
=
()
=>
wrapper
.
find
({
ref
:
'
chartTitle
'
});
const
findChartSubtitle
=
()
=>
wrapper
.
find
({
ref
:
'
chartSubtitle
'
});
beforeEach
(()
=>
{
factory
({});
});
const
findLoadingSkeleton
=
()
=>
wrapper
.
findComponent
(
LoadingSkeleton
);
const
findStatisticsHistory
=
()
=>
wrapper
.
findComponent
(
StatisticsHistory
);
const
findStatisticsSummary
=
()
=>
wrapper
.
findComponent
(
StatisticsSummary
);
const
findChartEmptyState
=
()
=>
wrapper
.
findByTestId
(
'
chartEmptyState
'
);
const
findChartTitle
=
()
=>
wrapper
.
findByTestId
(
'
chartTitle
'
);
const
findChartSubtitle
=
()
=>
wrapper
.
findByTestId
(
'
chartSubtitle
'
);
afterEach
(()
=>
{
wrapper
.
destroy
();
});
it
(
'
does not show the loading skeleton
'
,
()
=>
{
expect
(
findLoadingSkeleton
().
exists
()).
toBe
(
false
);
});
it
(
'
sets data to the summary
'
,
()
=>
{
const
summary
=
findStatisticsSummary
();
expect
(
summary
.
exists
()).
toBe
(
true
);
expect
(
summary
.
props
(
'
data
'
)).
toStrictEqual
({
anomalous
:
{
title
:
'
Anomalous Requests
'
,
value
:
0.2
,
},
nominal
:
{
title
:
'
Total Requests
'
,
value
:
100
,
},
describe
(
'
given there is data to display
'
,
()
=>
{
beforeEach
(()
=>
{
factory
({});
});
});
it
(
'
sets data to the chart
'
,
()
=>
{
const
chart
=
findStatisticsHistory
();
expect
(
chart
.
exists
()).
toBe
(
true
);
expect
(
chart
.
props
(
'
data
'
)).
toStrictEqual
({
anomalous
:
{
title
:
'
Anomalous Requests
'
,
values
:
mockAnomalousHistory
},
nominal
:
{
title
:
'
Total Requests
'
,
values
:
mockNominalHistory
},
...
timeRange
,
it
(
'
shows the chart title
'
,
()
=>
{
const
chartTitle
=
findChartTitle
();
expect
(
chartTitle
.
exists
()).
toBe
(
true
);
expect
(
chartTitle
.
text
()).
toBe
(
title
);
});
it
.
each
`
component | status | findComponent | state
${
'
loading skeleton
'
}
|
${
'
does not display
'
}
|
${
findLoadingSkeleton
}
|
${
false
}
${
'
chart subtitle
'
}
|
${
'
does display
'
}
|
${
findChartSubtitle
}
|
${
true
}
${
'
statistics summary
'
}
|
${
'
does display
'
}
|
${
findStatisticsSummary
}
|
${
true
}
${
'
statistics history
'
}
|
${
'
does display
'
}
|
${
findStatisticsHistory
}
|
${
true
}
${
'
chart empty state
'
}
|
${
'
does not display
'
}
|
${
findChartEmptyState
}
|
${
false
}
`
(
'
$status the $component
'
,
async
({
findComponent
,
state
})
=>
{
expect
(
findComponent
().
exists
()).
toBe
(
state
);
});
it
(
'
sets data to the summary
'
,
()
=>
{
const
summary
=
findStatisticsSummary
();
expect
(
summary
.
exists
()).
toBe
(
true
);
expect
(
summary
.
props
(
'
data
'
)).
toStrictEqual
({
anomalous
:
{
title
:
'
Anomalous Requests
'
,
value
:
0.2
,
},
nominal
:
{
title
:
'
Total Requests
'
,
value
:
100
,
},
});
});
expect
(
chart
.
props
(
'
yLegend
'
)).
toEqual
(
'
Requests
'
);
});
it
(
'
shows the chart title
'
,
()
=>
{
expect
(
findChartTitle
().
exists
()).
toBe
(
true
);
}
);
it
(
'
sets data to the chart
'
,
()
=>
{
const
chart
=
findStatisticsHistory
(
);
expect
(
chart
.
exists
()).
toBe
(
true
);
it
(
'
shows the chart subtitle
'
,
()
=>
{
expect
(
findChartSubtitle
().
exists
()).
toBe
(
true
);
});
it
(
'
does not show the chart empty state
'
,
()
=>
{
expect
(
findChartEmptyState
().
exists
()).
toBe
(
false
);
});
expect
(
chart
.
props
(
'
data
'
)).
toStrictEqual
(
{
anomalous
:
{
title
:
'
Anomalous Requests
'
,
values
:
mockAnomalousHistory
},
nominal
:
{
title
:
'
Total Requests
'
,
values
:
mockNominalHistory
},
...
timeRange
,
});
expect
(
chart
.
props
(
'
yLegend
'
)).
toEqual
(
'
Requests
'
);
});
it
(
'
fetches statistics
'
,
()
=>
{
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
threatMonitoringNetworkPolicy/fetchStatistics
'
);
});
it
(
'
fetches statistics
'
,
()
=>
{
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
threatMonitoringNetworkPolicy/fetchStatistics
'
);
});
it
(
'
fetches statistics on environment change
'
,
async
()
=>
{
store
.
dispatch
.
mockReset
();
await
store
.
commit
(
'
threatMonitoring/SET_CURRENT_ENVIRONMENT_ID
'
,
2
);
it
(
'
fetches statistics on environment change
'
,
async
()
=>
{
store
.
dispatch
.
mockReset
();
await
store
.
commit
(
'
threatMonitoring/SET_CURRENT_ENVIRONMENT_ID
'
,
2
);
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
threatMonitoringNetworkPolicy/fetchStatistics
'
);
});
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
threatMonitoringNetworkPolicy/fetchStatistics
'
);
});
it
(
'
fetches statistics on time window change
'
,
async
()
=>
{
store
.
dispatch
.
mockReset
();
await
store
.
commit
(
'
threatMonitoring/SET_CURRENT_TIME_WINDOW
'
,
'
hour
'
);
it
(
'
fetches statistics on time window change
'
,
async
()
=>
{
store
.
dispatch
.
mockReset
();
await
store
.
commit
(
'
threatMonitoring/SET_CURRENT_TIME_WINDOW
'
,
'
hour
'
);
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
threatMonitoringNetworkPolicy/fetchStatistics
'
);
expect
(
store
.
dispatch
).
toHaveBeenCalledWith
(
'
threatMonitoringNetworkPolicy/fetchStatistics
'
);
});
});
describe
(
'
given the statistics are loading
'
,
()
=>
{
...
...
@@ -137,25 +142,15 @@ describe('ThreatMonitoringSection component', () => {
});
});
it
(
'
shows the loading skeleton
'
,
()
=>
{
expect
(
findLoadingSkeleton
().
element
).
toMatchSnapshot
();
});
it
(
'
does not show the summary or history statistics
'
,
()
=>
{
expect
(
findStatisticsSummary
().
exists
()).
toBe
(
false
);
expect
(
findStatisticsHistory
().
exists
()).
toBe
(
false
);
});
it
(
'
shows the chart title
'
,
()
=>
{
expect
(
findChartTitle
().
exists
()).
toBe
(
true
);
});
it
(
'
does not show the chart subtitle
'
,
()
=>
{
expect
(
findChartSubtitle
().
exists
()).
toBe
(
false
);
});
it
(
'
does not show the chart empty state
'
,
()
=>
{
expect
(
findChartEmptyState
().
exists
()).
toBe
(
false
);
it
.
each
`
component | status | findComponent | state
${
'
loading skeleton
'
}
|
${
'
does display
'
}
|
${
findLoadingSkeleton
}
|
${
true
}
${
'
chart subtitle
'
}
|
${
'
does not display
'
}
|
${
findChartSubtitle
}
|
${
false
}
${
'
statistics summary
'
}
|
${
'
does not display
'
}
|
${
findStatisticsSummary
}
|
${
false
}
${
'
statistics history
'
}
|
${
'
does not display
'
}
|
${
findStatisticsHistory
}
|
${
false
}
${
'
chart empty state
'
}
|
${
'
does not display
'
}
|
${
findChartEmptyState
}
|
${
false
}
`
(
'
$status the $component
'
,
async
({
findComponent
,
state
})
=>
{
expect
(
findComponent
().
exists
()).
toBe
(
state
);
});
});
...
...
@@ -172,25 +167,15 @@ describe('ThreatMonitoringSection component', () => {
});
});
it
(
'
does not show the loading skeleton
'
,
()
=>
{
expect
(
findLoadingSkeleton
().
exists
()).
toBe
(
false
);
});
it
(
'
does not show the summary or history statistics
'
,
()
=>
{
expect
(
findStatisticsSummary
().
exists
()).
toBe
(
false
);
expect
(
findStatisticsHistory
().
exists
()).
toBe
(
false
);
});
it
(
'
shows the chart title
'
,
()
=>
{
expect
(
findChartTitle
().
exists
()).
toBe
(
true
);
});
it
(
'
does not show the chart subtitle
'
,
()
=>
{
expect
(
findChartSubtitle
().
exists
()).
toBe
(
false
);
});
it
(
'
shows the chart empty state
'
,
()
=>
{
expect
(
findChartEmptyState
().
element
).
toMatchSnapshot
();
it
.
each
`
component | status | findComponent | state
${
'
loading skeleton
'
}
|
${
'
does not display
'
}
|
${
findLoadingSkeleton
}
|
${
false
}
${
'
chart subtitle
'
}
|
${
'
does not display
'
}
|
${
findChartSubtitle
}
|
${
false
}
${
'
statistics summary
'
}
|
${
'
does not display
'
}
|
${
findStatisticsSummary
}
|
${
false
}
${
'
statistics history
'
}
|
${
'
does not display
'
}
|
${
findStatisticsHistory
}
|
${
false
}
${
'
chart empty state
'
}
|
${
'
does not display
'
}
|
${
findChartEmptyState
}
|
${
true
}
`
(
'
$status the $component
'
,
async
({
findComponent
,
state
})
=>
{
expect
(
findComponent
().
exists
()).
toBe
(
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