Commit 953b4c31 authored by Alexander Turinske's avatar Alexander Turinske

Add ability to change security policy project

- to owners only
- hide to all other users
- add tests
parent 36adf4b2
......@@ -10,14 +10,19 @@ export default {
GlAlert,
ScanNewPolicyModal,
},
inject: ['documentationPath', 'assignedPolicyProject', 'newPolicyPath'],
inject: [
'assignedPolicyProject',
'disableSecurityPolicyProject',
'documentationPath',
'newPolicyPath',
],
i18n: {
title: s__('NetworkPolicies|Policies'),
title: s__('SecurityOrchestration|Policies'),
subtitle: s__(
'NetworkPolicies|Enforce security for this project. %{linkStart}More information.%{linkEnd}',
'SecurityOrchestration|Enforce security for this project. %{linkStart}More information.%{linkEnd}',
),
newPolicyButtonText: s__('NetworkPolicies|New policy'),
editPolicyButtonText: s__('NetworkPolicies|Edit policy project'),
newPolicyButtonText: s__('SecurityOrchestration|New policy'),
editPolicyProjectButtonText: s__('SecurityOrchestration|Edit policy project'),
},
data() {
return {
......@@ -86,12 +91,13 @@ export default {
</p>
</div>
<gl-button
v-if="!disableSecurityPolicyProject"
data-testid="edit-project-policy-button"
class="gl-mr-4"
:loading="projectIsBeingLinked"
@click="showNewPolicyModal"
>
{{ $options.i18n.editPolicyButtonText }}
{{ $options.i18n.editPolicyProjectButtonText }}
</gl-button>
<gl-button data-testid="new-policy-button" variant="confirm" :href="newPolicyPath">
{{ $options.i18n.newPolicyButtonText }}
......
......@@ -23,6 +23,7 @@ describe('Policies Header Component', () => {
documentationPath,
newPolicyPath,
assignedPolicyProject: null,
disableSecurityPolicyProject: false,
...provide,
},
stubs: {
......@@ -36,58 +37,70 @@ describe('Policies Header Component', () => {
wrapper.destroy();
});
beforeEach(() => {
createWrapper();
});
describe('project owner', () => {
beforeEach(() => {
createWrapper();
});
it('displays New policy button with correct text and link', () => {
expect(findNewPolicyButton().text()).toBe('New policy');
expect(findNewPolicyButton().attributes('href')).toBe(newPolicyPath);
});
it('displays New policy button with correct text and link', () => {
expect(findNewPolicyButton().text()).toBe('New policy');
expect(findNewPolicyButton().attributes('href')).toBe(newPolicyPath);
});
it('displays the Edit policy project button', () => {
expect(findEditPolicyProjectButton().text()).toBe('Edit policy project');
});
it('displays the Edit policy project button', () => {
expect(findEditPolicyProjectButton().text()).toBe('Edit policy project');
});
it('does not display the alert component by default', () => {
expect(findAlert().exists()).toBe(false);
});
it('does not display the alert component by default', () => {
expect(findAlert().exists()).toBe(false);
});
it('displays the alert component when scan new modal policy emits events', async () => {
const text = 'Project was linked successfully.';
findScanNewPolicyModal().vm.$emit('project-updated', {
text,
variant: 'success',
});
it('displays the alert component when scan new modal policy emits events', async () => {
const text = 'Project was linked successfully.';
// When the project is updated it displays the output message.
await wrapper.vm.$nextTick();
expect(findAlert().text()).toBe(text);
findScanNewPolicyModal().vm.$emit('project-updated', {
text,
variant: 'success',
// When the project is being updated once again, it removes the alert so that
// the new one will be displayed.
findScanNewPolicyModal().vm.$emit('updating-project');
await wrapper.vm.$nextTick();
expect(findAlert().exists()).toBe(false);
});
// When the project is updated it displays the output message.
await wrapper.vm.$nextTick();
expect(findAlert().text()).toBe(text);
it('mounts the scan new policy modal', () => {
expect(findScanNewPolicyModal().exists()).toBe(true);
});
// When the project is being updated once again, it removes the alert so that
// the new one will be displayed.
findScanNewPolicyModal().vm.$emit('updating-project');
await wrapper.vm.$nextTick();
expect(findAlert().exists()).toBe(false);
});
it('displays scan new policy modal when the action button is clicked', async () => {
await findEditPolicyProjectButton().trigger('click');
it('mounts the scan new policy modal', () => {
expect(findScanNewPolicyModal().exists()).toBe(true);
});
expect(findScanNewPolicyModal().props().visible).toBe(true);
});
it('displays scan new policy modal when the action button is clicked', async () => {
await findEditPolicyProjectButton().trigger('click');
it('displays the header', () => {
expect(findHeader().text()).toBe('Policies');
});
expect(findScanNewPolicyModal().props().visible).toBe(true);
it('displays the subheader', () => {
expect(findSubheader().text()).toContain('Enforce security for this project.');
expect(findMoreInformationLink().attributes('href')).toBe(documentationPath);
});
});
it('displays the header', () => {
expect(findHeader().text()).toBe('Policies');
});
describe('project user', () => {
beforeEach(() => {
createWrapper({ provide: { disableSecurityPolicyProject: true } });
});
it('displays the subheader', () => {
expect(findSubheader().text()).toContain('Enforce security for this project.');
expect(findMoreInformationLink().attributes('href')).toBe(documentationPath);
it('does not display the Edit policy project button', () => {
expect(findEditPolicyProjectButton().exists()).toBe(false);
});
});
});
......@@ -22040,12 +22040,6 @@ msgstr ""
msgid "NetworkPolicies|Edit policy"
msgstr ""
msgid "NetworkPolicies|Edit policy project"
msgstr ""
msgid "NetworkPolicies|Enforce security for this project. %{linkStart}More information.%{linkEnd}"
msgstr ""
msgid "NetworkPolicies|Enforcement status"
msgstr ""
......@@ -22088,9 +22082,6 @@ msgstr ""
msgid "NetworkPolicies|Please %{installLinkStart}install%{installLinkEnd} and %{configureLinkStart}configure a Kubernetes Agent for this project%{configureLinkEnd} to enable alerts."
msgstr ""
msgid "NetworkPolicies|Policies"
msgstr ""
msgid "NetworkPolicies|Policies are a specification of how groups of pods are allowed to communicate with each other's network endpoints."
msgstr ""
......@@ -29504,9 +29495,21 @@ msgstr ""
msgid "SecurityOrchestration|An error occurred assigning your security policy project"
msgstr ""
msgid "SecurityOrchestration|Edit policy project"
msgstr ""
msgid "SecurityOrchestration|Enforce security for this project. %{linkStart}More information.%{linkEnd}"
msgstr ""
msgid "SecurityOrchestration|New policy"
msgstr ""
msgid "SecurityOrchestration|Only owners can update Security Policy Project"
msgstr ""
msgid "SecurityOrchestration|Policies"
msgstr ""
msgid "SecurityOrchestration|Security policy project was linked successfully"
msgstr ""
......
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