Commit 667d36ca authored by Alexander Turinske's avatar Alexander Turinske

Optimize hasInvalidPolicy code

- remove unnecessary elements
parent d20c33e2
......@@ -132,9 +132,9 @@ const hasUnsupportedAttribute = (manifest) => {
return !Object.keys(object).every((item) => allowedValues.includes(item));
};
const hasInvalidPolicy = (type) => {
const hasInvalidPolicy = (ingress = [], egress = []) => {
let isInvalidPolicy = false;
manifest.spec[type].forEach((item) => {
[...ingress, ...egress].forEach((item) => {
isInvalidPolicy = hasInvalidKey(item, ruleKeys);
if (item.toPorts?.length && !isInvalidPolicy) {
item.toPorts.forEach((entry) => {
......@@ -158,11 +158,8 @@ const hasUnsupportedAttribute = (manifest) => {
if (manifest?.spec && !isUnsupported) {
isUnsupported = hasInvalidKey(manifest.spec, specKeys);
}
if (manifest?.spec?.ingress?.length && !isUnsupported) {
isUnsupported = hasInvalidPolicy('ingress');
}
if (manifest?.spec?.egress?.length && !isUnsupported) {
isUnsupported = hasInvalidPolicy('egress');
if (!isUnsupported && (manifest?.spec?.ingress?.length || manifest?.spec?.egress?.length)) {
isUnsupported = hasInvalidPolicy(manifest.spec.ingress, manifest.spec.egress);
}
return isUnsupported;
......
......@@ -237,7 +237,6 @@ export default {
<div class="row">
<div class="col-sm-6 col-md-4 col-lg-3 col-xl-2">
<gl-form-group :disabled="hasParsingError">
<gl-form-group :label="s__('NetworkPolicies|Policy type')" label-for="policyType">
<gl-form-select
id="policyType"
......@@ -246,26 +245,21 @@ export default {
disabled
/>
</gl-form-group>
</gl-form-group>
</div>
<div class="col-sm-6 col-md-6 col-lg-5 col-xl-4">
<gl-form-group :disabled="hasParsingError" data-testid="policy-name">
<gl-form-group
:disabled="hasParsingError"
:label="s__('NetworkPolicies|Name')"
label-for="policyName"
>
<gl-form-input id="policyName" v-model="policy.name" />
</gl-form-group>
<gl-form-group :label="s__('NetworkPolicies|Name')" label-for="policyName">
<gl-form-input id="policyName" v-model="policy.name" :disabled="hasParsingError" />
</gl-form-group>
</div>
</div>
<div class="row">
<div class="col-sm-12 col-md-10 col-lg-8 col-xl-6">
<gl-form-group :disabled="hasParsingError" data-testid="policy-description">
<gl-form-group :label="s__('NetworkPolicies|Description')" label-for="policyDescription">
<gl-form-textarea id="policyDescription" v-model="policy.description" />
</gl-form-group>
<gl-form-textarea
id="policyDescription"
v-model="policy.description"
:disabled="hasParsingError"
/>
</gl-form-group>
</div>
</div>
......
......@@ -52,7 +52,6 @@ exports[`PolicyEditorApp component renders the policy editor layout 1`] = `
<div
class="col-sm-6 col-md-4 col-lg-3 col-xl-2"
>
<gl-form-group-stub>
<gl-form-group-stub
label="Policy type"
label-for="policyType"
......@@ -64,14 +63,10 @@ exports[`PolicyEditorApp component renders the policy editor layout 1`] = `
value="networkPolicy"
/>
</gl-form-group-stub>
</gl-form-group-stub>
</div>
<div
class="col-sm-6 col-md-6 col-lg-5 col-xl-4"
>
<gl-form-group-stub
data-testid="policy-name"
>
<gl-form-group-stub
label="Name"
......@@ -82,7 +77,6 @@ exports[`PolicyEditorApp component renders the policy editor layout 1`] = `
value=""
/>
</gl-form-group-stub>
</gl-form-group-stub>
</div>
</div>
......@@ -91,9 +85,6 @@ exports[`PolicyEditorApp component renders the policy editor layout 1`] = `
>
<div
class="col-sm-12 col-md-10 col-lg-8 col-xl-6"
>
<gl-form-group-stub
data-testid="policy-description"
>
<gl-form-group-stub
label="Description"
......@@ -105,7 +96,6 @@ exports[`PolicyEditorApp component renders the policy editor layout 1`] = `
value=""
/>
</gl-form-group-stub>
</gl-form-group-stub>
</div>
</div>
......
......@@ -79,10 +79,9 @@ spec:
const findYAMLParsingAlert = () => wrapper.findByTestId('parsing-alert');
const findNetworkPolicyEditor = () => wrapper.findByTestId('network-policy-editor');
const findPolicyAlertPicker = () => wrapper.find(PolicyAlertPicker);
const findPolicyDescriptionContainer = () => wrapper.findByTestId('policy-description');
const findPolicyDescription = () => wrapper.find("[id='policyDescription']");
const findPolicyEnableContainer = () => wrapper.findByTestId('policy-enable');
const findPolicyNameContainer = () => wrapper.findByTestId('policy-name');
const findPolicyName = () => findPolicyNameContainer().find("[id='policyName']");
const findPolicyName = () => wrapper.find("[id='policyName']");
const findSavePolicy = () => wrapper.findByTestId('save-policy');
const findDeletePolicy = () => wrapper.findByTestId('delete-policy');
const findEditorModeToggle = () => wrapper.findByTestId('editor-mode');
......@@ -280,11 +279,11 @@ spec:
});
it('disables policy name field', () => {
expect(findPolicyNameContainer().attributes().disabled).toBe('true');
expect(findPolicyName().attributes().disabled).toBe('true');
});
it('disables policy description field', () => {
expect(findPolicyDescriptionContainer().attributes().disabled).toBe('true');
expect(findPolicyDescription().attributes().disabled).toBe('true');
});
it('disables policy enable/disable toggle', () => {
......
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