Commit 7269368f authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '338839-do-not-get-network-requests' into 'master'

Update network policy request

See merge request gitlab-org/gitlab!68990
parents b50ffcb5 56653aa5
...@@ -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