Commit b6ab1abf authored by Enrique Alcántara's avatar Enrique Alcántara

Merge branch '333978-limit-changing-security-policy-project' into 'master'

Add ability to change security policy project

See merge request gitlab-org/gitlab!68017
parents 5774f6f5 6b999c86
......@@ -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 }}
......
......@@ -8,6 +8,7 @@ describe('Policies Header Component', () => {
const documentationPath = '/path/to/docs';
const newPolicyPath = '/path/to/new/policy/page';
const projectLinkSuccessText = 'Project was linked successfully.';
const findAlert = () => wrapper.findComponent(GlAlert);
const findScanNewPolicyModal = () => wrapper.findComponent(ScanNewPolicyModal);
......@@ -17,12 +18,21 @@ describe('Policies Header Component', () => {
const findNewPolicyButton = () => wrapper.findByTestId('new-policy-button');
const findSubheader = () => wrapper.findByTestId('policies-subheader');
const linkSecurityPoliciesProject = async () => {
findScanNewPolicyModal().vm.$emit('project-updated', {
text: projectLinkSuccessText,
variant: 'success',
});
await wrapper.vm.$nextTick();
};
const createWrapper = ({ provide } = {}) => {
wrapper = shallowMountExtended(PoliciesHeader, {
provide: {
documentationPath,
newPolicyPath,
assignedPolicyProject: null,
disableSecurityPolicyProject: false,
...provide,
},
stubs: {
......@@ -36,58 +46,69 @@ 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.';
it('mounts the scan new policy modal', () => {
expect(findScanNewPolicyModal().exists()).toBe(true);
});
findScanNewPolicyModal().vm.$emit('project-updated', {
text,
variant: 'success',
it('displays scan new policy modal when the action button is clicked', async () => {
await findEditPolicyProjectButton().trigger('click');
expect(findScanNewPolicyModal().props().visible).toBe(true);
});
// When the project is updated it displays the output message.
await wrapper.vm.$nextTick();
expect(findAlert().text()).toBe(text);
it('displays the header', () => {
expect(findHeader().text()).toBe('Policies');
});
// 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 the subheader', () => {
expect(findSubheader().text()).toMatchInterpolatedText(
'Enforce security for this project. More information.',
);
expect(findMoreInformationLink().attributes('href')).toBe(documentationPath);
});
it('mounts the scan new policy modal', () => {
expect(findScanNewPolicyModal().exists()).toBe(true);
});
describe('linking security policies project', () => {
beforeEach(async () => {
await linkSecurityPoliciesProject();
});
it('displays scan new policy modal when the action button is clicked', async () => {
await findEditPolicyProjectButton().trigger('click');
it('displays the alert component when scan new modal policy emits event', async () => {
expect(findAlert().text()).toBe(projectLinkSuccessText);
});
expect(findScanNewPolicyModal().props().visible).toBe(true);
it('hides the previous alert when scan new modal policy is processing a new link', async () => {
findScanNewPolicyModal().vm.$emit('updating-project');
await wrapper.vm.$nextTick();
expect(findAlert().exists()).toBe(false);
});
});
});
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);
});
});
});
......@@ -22076,12 +22076,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 ""
......@@ -22124,9 +22118,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 ""
......@@ -29537,9 +29528,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