Commit 4b17cc4b authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch 'update-policy-list-on-project-update' into 'master'

Update policy list on security project update

See merge request gitlab-org/gitlab!68290
parents 3100504e a2fe5bfb
...@@ -18,6 +18,7 @@ export default { ...@@ -18,6 +18,7 @@ export default {
// environments, therefore infrastructure cannot be set up. A valid default // environments, therefore infrastructure cannot be set up. A valid default
// environment id only means that infrastructure *might* be set up. // environment id only means that infrastructure *might* be set up.
shouldFetchEnvironment: this.isValidEnvironmentId(this.defaultEnvironmentId), shouldFetchEnvironment: this.isValidEnvironmentId(this.defaultEnvironmentId),
shouldUpdatePolicyList: false,
}; };
}, },
created() { created() {
...@@ -32,13 +33,20 @@ export default { ...@@ -32,13 +33,20 @@ export default {
isValidEnvironmentId(id) { isValidEnvironmentId(id) {
return Number.isInteger(id) && id >= 0; return Number.isInteger(id) && id >= 0;
}, },
handleUpdatePolicyList(val) {
this.shouldUpdatePolicyList = val;
},
}, },
}; };
</script> </script>
<template> <template>
<div> <div>
<policies-header /> <policies-header @update-policy-list="handleUpdatePolicyList" />
<no-environment-empty-state v-if="!shouldFetchEnvironment" /> <no-environment-empty-state v-if="!shouldFetchEnvironment" />
<policies-list v-else /> <policies-list
v-else
:should-update-policy-list="shouldUpdatePolicyList"
@update-policy-list="handleUpdatePolicyList"
/>
</div> </div>
</template> </template>
...@@ -47,6 +47,7 @@ export default { ...@@ -47,6 +47,7 @@ export default {
this.alertVariant = variant; this.alertVariant = variant;
this.alertText = text; this.alertText = text;
} }
this.$emit('update-policy-list', true);
}, },
isUpdatingProject() { isUpdatingProject() {
this.projectIsBeingLinked = true; this.projectIsBeingLinked = true;
......
...@@ -56,6 +56,13 @@ export default { ...@@ -56,6 +56,13 @@ export default {
GlTooltip: GlTooltipDirective, GlTooltip: GlTooltipDirective,
}, },
inject: ['projectPath', 'documentationPath', 'newPolicyPath'], inject: ['projectPath', 'documentationPath', 'newPolicyPath'],
props: {
shouldUpdatePolicyList: {
type: Boolean,
required: false,
default: false,
},
},
apollo: { apollo: {
networkPolicies: { networkPolicies: {
query: networkPoliciesQuery, query: networkPoliciesQuery,
...@@ -194,6 +201,14 @@ export default { ...@@ -194,6 +201,14 @@ export default {
return fields; return fields;
}, },
}, },
watch: {
shouldUpdatePolicyList(newShouldUpdatePolicyList) {
if (newShouldUpdatePolicyList) {
this.$apollo.queries.scanExecutionPolicies.refetch();
this.$emit('update-policy-list', false);
}
},
},
methods: { methods: {
getTimeAgoString(updatedAt) { getTimeAgoString(updatedAt) {
if (!updatedAt) return ''; if (!updatedAt) return '';
......
...@@ -60,6 +60,20 @@ describe('Policies App', () => { ...@@ -60,6 +60,20 @@ describe('Policies App', () => {
expect(setCurrentEnvironmentIdSpy).toHaveBeenCalled(); expect(setCurrentEnvironmentIdSpy).toHaveBeenCalled();
expect(fetchEnvironmentsSpy).toHaveBeenCalled(); expect(fetchEnvironmentsSpy).toHaveBeenCalled();
}); });
it.each`
component | findFn
${'PolicyHeader'} | ${findPoliciesHeader}
${'PolicyList'} | ${findPoliciesList}
`(
'sets the `shouldUpdatePolicyList` variable from the $component component',
async ({ findFn }) => {
expect(findPoliciesList().props('shouldUpdatePolicyList')).toBe(false);
findFn().vm.$emit('update-policy-list', true);
await wrapper.vm.$nextTick();
expect(findPoliciesList().props('shouldUpdatePolicyList')).toBe(true);
},
);
}); });
describe('when does not have an environment enabled', () => { describe('when does not have an environment enabled', () => {
......
...@@ -92,6 +92,7 @@ describe('Policies Header Component', () => { ...@@ -92,6 +92,7 @@ describe('Policies Header Component', () => {
it('displays the alert component when scan new modal policy emits event', async () => { it('displays the alert component when scan new modal policy emits event', async () => {
expect(findAlert().text()).toBe(projectLinkSuccessText); expect(findAlert().text()).toBe(projectLinkSuccessText);
expect(wrapper.emitted('update-policy-list')).toStrictEqual([[true]]);
}); });
it('hides the previous alert when scan new modal policy is processing a new link', async () => { it('hides the previous alert when scan new modal policy is processing a new link', async () => {
......
...@@ -28,9 +28,10 @@ const environments = [ ...@@ -28,9 +28,10 @@ const environments = [
global_id: 'gid://gitlab/Environment/2', global_id: 'gid://gitlab/Environment/2',
}, },
]; ];
const scanExecutionPoliciesSpy = scanExecutionPolicies(mockScanExecutionPoliciesResponse);
const defaultRequestHandlers = { const defaultRequestHandlers = {
networkPolicies: networkPolicies(mockNetworkPoliciesResponse), networkPolicies: networkPolicies(mockNetworkPoliciesResponse),
scanExecutionPolicies: scanExecutionPolicies(mockScanExecutionPoliciesResponse), scanExecutionPolicies: scanExecutionPoliciesSpy,
}; };
const pendingHandler = jest.fn(() => new Promise(() => {})); const pendingHandler = jest.fn(() => new Promise(() => {}));
...@@ -201,6 +202,24 @@ describe('PoliciesList component', () => { ...@@ -201,6 +202,24 @@ describe('PoliciesList component', () => {
expect(findPoliciesTable().text()).not.toContain(hiddenType.text); expect(findPoliciesTable().text()).not.toContain(hiddenType.text);
}); });
}); });
it('does emit `update-policy-list` and refetch scan execution policies on `shouldUpdatePolicyList` change to `false`', async () => {
expect(scanExecutionPoliciesSpy).toHaveBeenCalledTimes(1);
expect(wrapper.emitted('update-policy-list')).toBeUndefined();
wrapper.setProps({ shouldUpdatePolicyList: true });
await wrapper.vm.$nextTick();
expect(wrapper.emitted('update-policy-list')).toStrictEqual([[false]]);
expect(scanExecutionPoliciesSpy).toHaveBeenCalledTimes(2);
});
it('does not emit `update-policy-list` or refetch scan execution policies on `shouldUpdatePolicyList` change to `false`', async () => {
wrapper.setProps({ shouldUpdatePolicyList: true });
await wrapper.vm.$nextTick();
wrapper.setProps({ shouldUpdatePolicyList: false });
await wrapper.vm.$nextTick();
expect(wrapper.emitted('update-policy-list')).toStrictEqual([[false]]);
expect(scanExecutionPoliciesSpy).toHaveBeenCalledTimes(2);
});
}); });
describe('status column', () => { describe('status column', () => {
......
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