Commit 89a7f4a4 authored by Alexander Turinske's avatar Alexander Turinske

Clean up code/tests for threat monitoring

- replace div with template
- use extendedWrapper
- add additional tests
parent d10d8da7
...@@ -170,7 +170,7 @@ export default { ...@@ -170,7 +170,7 @@ export default {
data-testid="threat-monitoring-statistics-tab" data-testid="threat-monitoring-statistics-tab"
> >
<no-environment-empty-state v-if="!isSetUpMaybe" /> <no-environment-empty-state v-if="!isSetUpMaybe" />
<div v-else> <template v-else>
<threat-monitoring-filters /> <threat-monitoring-filters />
<threat-monitoring-section <threat-monitoring-section
...@@ -206,7 +206,7 @@ export default { ...@@ -206,7 +206,7 @@ export default {
:documentation-path="documentationPath" :documentation-path="documentationPath"
documentation-anchor="container-network-policy" documentation-anchor="container-network-policy"
/> />
</div> </template>
</gl-tab> </gl-tab>
</gl-tabs> </gl-tabs>
</section> </section>
......
import { GlAlert } from '@gitlab/ui'; import { GlAlert } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import ThreatMonitoringAlerts from 'ee/threat_monitoring/components/alerts/alerts.vue'; import ThreatMonitoringAlerts from 'ee/threat_monitoring/components/alerts/alerts.vue';
import ThreatMonitoringApp from 'ee/threat_monitoring/components/app.vue'; import ThreatMonitoringApp from 'ee/threat_monitoring/components/app.vue';
import ThreatMonitoringFilters from 'ee/threat_monitoring/components/threat_monitoring_filters.vue'; import ThreatMonitoringFilters from 'ee/threat_monitoring/components/threat_monitoring_filters.vue';
...@@ -38,7 +39,8 @@ describe('ThreatMonitoringApp component', () => { ...@@ -38,7 +39,8 @@ describe('ThreatMonitoringApp component', () => {
jest.spyOn(store, 'dispatch').mockImplementation(); jest.spyOn(store, 'dispatch').mockImplementation();
wrapper = shallowMount(ThreatMonitoringApp, { wrapper = extendedWrapper(
shallowMount(ThreatMonitoringApp, {
propsData: { propsData: {
defaultEnvironmentId, defaultEnvironmentId,
chartEmptyStateSvgPath, chartEmptyStateSvgPath,
...@@ -58,7 +60,8 @@ describe('ThreatMonitoringApp component', () => { ...@@ -58,7 +60,8 @@ describe('ThreatMonitoringApp component', () => {
}, },
store, store,
stubs, stubs,
}); }),
);
}; };
const findAlert = () => wrapper.find(GlAlert); const findAlert = () => wrapper.find(GlAlert);
...@@ -69,8 +72,8 @@ describe('ThreatMonitoringApp component', () => { ...@@ -69,8 +72,8 @@ describe('ThreatMonitoringApp component', () => {
const findNetworkPolicySection = () => wrapper.find({ ref: 'networkPolicySection' }); const findNetworkPolicySection = () => wrapper.find({ ref: 'networkPolicySection' });
const findNoEnvironmentEmptyStates = () => wrapper.findAll(NoEnvironmentEmptyState); const findNoEnvironmentEmptyStates = () => wrapper.findAll(NoEnvironmentEmptyState);
const findNetworkPolicyTab = () => wrapper.find({ ref: 'networkPolicyTab' }); const findNetworkPolicyTab = () => wrapper.find({ ref: 'networkPolicyTab' });
const findAlertTab = () => wrapper.find('[data-testid="threat-monitoring-alerts-tab"]'); const findAlertTab = () => wrapper.findByTestId('threat-monitoring-alerts-tab');
const findStatisticsTab = () => wrapper.find('[data-testid="threat-monitoring-statistics-tab"]'); const findStatisticsTab = () => wrapper.findByTestId('threat-monitoring-statistics-tab');
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
...@@ -93,7 +96,7 @@ describe('ThreatMonitoringApp component', () => { ...@@ -93,7 +96,7 @@ describe('ThreatMonitoringApp component', () => {
expect(store.dispatch).not.toHaveBeenCalled(); expect(store.dispatch).not.toHaveBeenCalled();
}); });
it('shows the no environment empty state', () => { it('shows the "no environment" empty state', () => {
expect(findNoEnvironmentEmptyStates().length).toBe(2); expect(findNoEnvironmentEmptyStates().length).toBe(2);
}); });
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { GlEmptyState, GlSprintf } from '@gitlab/ui';
import {
EMPTY_STATE_DESCRIPTION,
NO_ENVIRONMENT_TITLE,
} from 'ee/threat_monitoring/components/constants';
import NoEnvironmentEmptyState from 'ee/threat_monitoring/components/no_environment_empty_state.vue'; import NoEnvironmentEmptyState from 'ee/threat_monitoring/components/no_environment_empty_state.vue';
const documentationPath = '/docs'; const documentationPath = '/docs';
...@@ -7,6 +12,9 @@ const emptyStateSvgPath = '/svgs'; ...@@ -7,6 +12,9 @@ const emptyStateSvgPath = '/svgs';
describe('NoEnvironmentEmptyState component', () => { describe('NoEnvironmentEmptyState component', () => {
let wrapper; let wrapper;
const findGlEmptyState = () => wrapper.find(GlEmptyState);
const findGlSprintf = () => wrapper.find(GlSprintf);
const factory = () => { const factory = () => {
wrapper = shallowMount(NoEnvironmentEmptyState, { wrapper = shallowMount(NoEnvironmentEmptyState, {
provide: { provide: {
...@@ -29,5 +37,18 @@ describe('NoEnvironmentEmptyState component', () => { ...@@ -29,5 +37,18 @@ describe('NoEnvironmentEmptyState component', () => {
it('matches the snapshot', () => { it('matches the snapshot', () => {
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
}); });
it('shows the GlEmptyState component', () => {
expect(findGlEmptyState().exists()).toBe(true);
expect(findGlEmptyState().attributes()).toMatchObject({
title: NO_ENVIRONMENT_TITLE,
svgpath: emptyStateSvgPath,
});
});
it('shows the message', () => {
expect(findGlSprintf().exists()).toBe(true);
expect(findGlSprintf().attributes('message')).toBe(EMPTY_STATE_DESCRIPTION);
});
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment