Commit 56653aa5 authored by Alexander Turinske's avatar Alexander Turinske Committed by Natalia Tepluhina

Update network policy request

parent 1ba7aa96
...@@ -81,7 +81,9 @@ export default { ...@@ -81,7 +81,9 @@ export default {
}, },
error: createPolicyFetchError, error: createPolicyFetchError,
skip() { skip() {
return this.isLoadingEnvironments || !this.shouldShowNetworkPolicies; return (
!this.hasEnvironment || this.isLoadingEnvironments || !this.shouldShowNetworkPolicies
);
}, },
}, },
scanExecutionPolicies: { scanExecutionPolicies: {
......
...@@ -32,9 +32,10 @@ const environments = [ ...@@ -32,9 +32,10 @@ const environments = [
global_id: 'gid://gitlab/Environment/3', global_id: 'gid://gitlab/Environment/3',
}, },
]; ];
const networkPoliciesSpy = networkPolicies(mockNetworkPoliciesResponse);
const scanExecutionPoliciesSpy = scanExecutionPolicies(mockScanExecutionPoliciesResponse); const scanExecutionPoliciesSpy = scanExecutionPolicies(mockScanExecutionPoliciesResponse);
const defaultRequestHandlers = { const defaultRequestHandlers = {
networkPolicies: networkPolicies(mockNetworkPoliciesResponse), networkPolicies: networkPoliciesSpy,
scanExecutionPolicies: scanExecutionPoliciesSpy, scanExecutionPolicies: scanExecutionPoliciesSpy,
}; };
const pendingHandler = jest.fn(() => new Promise(() => {})); const pendingHandler = jest.fn(() => new Promise(() => {}));
...@@ -45,13 +46,19 @@ describe('PoliciesList component', () => { ...@@ -45,13 +46,19 @@ describe('PoliciesList component', () => {
let requestHandlers; let requestHandlers;
const factory = (mountFn = mountExtended) => (options = {}) => { const factory = (mountFn = mountExtended) => (options = {}) => {
const { state = {}, handlers, ...wrapperOptions } = options;
store = createStore(); store = createStore();
const { state, handlers, ...wrapperOptions } = options; store.replaceState({
Object.assign(store.state.networkPolicies, { ...store.state,
...state, threatMonitoring: {
...store.state.threatMonitoring,
environments,
currentEnvironmentId: environments[0].id,
...state.threatMonitoring,
},
}); });
store.state.threatMonitoring.environments = environments;
store.state.threatMonitoring.currentEnvironmentId = environments[0].id;
requestHandlers = { requestHandlers = {
...defaultRequestHandlers, ...defaultRequestHandlers,
...handlers, ...handlers,
...@@ -260,8 +267,7 @@ describe('PoliciesList component', () => { ...@@ -260,8 +267,7 @@ describe('PoliciesList component', () => {
describe('with allEnvironments enabled', () => { describe('with allEnvironments enabled', () => {
beforeEach(() => { beforeEach(() => {
mountWrapper(); mountWrapper({ state: { threatMonitoring: { allEnvironments: true } } });
wrapper.vm.$store.state.threatMonitoring.allEnvironments = true;
}); });
it('renders environments column', () => { it('renders environments column', () => {
...@@ -312,7 +318,26 @@ describe('PoliciesList component', () => { ...@@ -312,7 +318,26 @@ describe('PoliciesList component', () => {
}); });
}); });
describe('given no environement', () => { describe('given loading environment', () => {
beforeEach(() => {
mountWrapper({
propsData: {
hasEnvironment: true,
},
state: {
threatMonitoring: {
isLoadingEnvironments: true,
},
},
});
});
it('does not make a request for network policies', () => {
expect(networkPoliciesSpy).not.toHaveBeenCalled();
});
});
describe('given no environments', () => {
beforeEach(() => { beforeEach(() => {
mountWrapper({ mountWrapper({
propsData: { propsData: {
...@@ -321,8 +346,12 @@ describe('PoliciesList component', () => { ...@@ -321,8 +346,12 @@ describe('PoliciesList component', () => {
}); });
}); });
it('does not make a request for network policies', () => {
expect(networkPoliciesSpy).not.toHaveBeenCalled();
});
it('does not render default network policies', () => { it('does not render default network policies', () => {
expect(findPolicyStatusCells()).toHaveLength(3); expect(findPolicyStatusCells()).toHaveLength(1);
}); });
}); });
}); });
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