Commit b481209b authored by Alexander Turinske's avatar Alexander Turinske

Clean up tests

- add translation
parent 38873a13
...@@ -32,8 +32,6 @@ export default { ...@@ -32,8 +32,6 @@ export default {
: DEFAULT_SCAN_EXECUTION_POLICY; : DEFAULT_SCAN_EXECUTION_POLICY;
return { return {
isRemovingPolicy: false,
isUpdatingPolicy: false,
policy, policy,
yamlEditorValue, yamlEditorValue,
}; };
...@@ -44,12 +42,6 @@ export default { ...@@ -44,12 +42,6 @@ export default {
}, },
}, },
methods: { methods: {
removePolicy() {
// TODO call graphql mutation and redirect to merge request after #329422 is closed
},
savePolicy() {
// TODO call graphql mutation and redirect to merge request after #329422 is closed
},
updateYaml(manifest) { updateYaml(manifest) {
this.yamlEditorValue = manifest; this.yamlEditorValue = manifest;
}, },
...@@ -62,12 +54,8 @@ export default { ...@@ -62,12 +54,8 @@ export default {
:default-editor-mode="$options.DEFAULT_EDITOR_MODE" :default-editor-mode="$options.DEFAULT_EDITOR_MODE"
:editor-modes="$options.EDITOR_MODES" :editor-modes="$options.EDITOR_MODES"
:is-editing="isEditing" :is-editing="isEditing"
:is-removing-policy="isRemovingPolicy"
:is-updating-policy="isUpdatingPolicy"
:policy-name="policy.name" :policy-name="policy.name"
:yaml-editor-value="yamlEditorValue" :yaml-editor-value="yamlEditorValue"
@remove-policy="removePolicy"
@save-policy="savePolicy"
@update-yaml="updateYaml" @update-yaml="updateYaml"
> >
<template #save-button-text> <template #save-button-text>
......
...@@ -63,11 +63,9 @@ describe('NetworkPolicyEditor component', () => { ...@@ -63,11 +63,9 @@ describe('NetworkPolicyEditor component', () => {
const modifyPolicyAlert = async ({ isAlertEnabled }) => { const modifyPolicyAlert = async ({ isAlertEnabled }) => {
const policyAlertPicker = findPolicyAlertPicker(); const policyAlertPicker = findPolicyAlertPicker();
policyAlertPicker.vm.$emit('update-alert', isAlertEnabled); await policyAlertPicker.vm.$emit('update-alert', isAlertEnabled);
await wrapper.vm.$nextTick();
expect(policyAlertPicker.props('policyAlert')).toBe(isAlertEnabled); expect(policyAlertPicker.props('policyAlert')).toBe(isAlertEnabled);
findPolicyEditorLayout().vm.$emit('save-policy'); await findPolicyEditorLayout().vm.$emit('save-policy');
await wrapper.vm.$nextTick();
}; };
beforeEach(() => { beforeEach(() => {
...@@ -140,8 +138,7 @@ describe('NetworkPolicyEditor component', () => { ...@@ -140,8 +138,7 @@ describe('NetworkPolicyEditor component', () => {
}), }),
}); });
findPolicyEditorLayout().vm.$emit('save-policy', EDITOR_MODE_YAML); await findPolicyEditorLayout().vm.$emit('save-policy', EDITOR_MODE_YAML);
await wrapper.vm.$nextTick();
expect(store.dispatch).toHaveBeenCalledWith('networkPolicies/createPolicy', { expect(store.dispatch).toHaveBeenCalledWith('networkPolicies/createPolicy', {
environmentId: -1, environmentId: -1,
policy: { manifest: mockL7Manifest }, policy: { manifest: mockL7Manifest },
...@@ -152,24 +149,21 @@ describe('NetworkPolicyEditor component', () => { ...@@ -152,24 +149,21 @@ describe('NetworkPolicyEditor component', () => {
it('given there is a name change, updates policy yaml preview', async () => { it('given there is a name change, updates policy yaml preview', async () => {
const initialValue = findPreview().props('policyYaml'); const initialValue = findPreview().props('policyYaml');
findPolicyName().vm.$emit('input', 'new'); await findPolicyName().vm.$emit('input', 'new');
await wrapper.vm.$nextTick();
expect(findPreview().props('policyYaml')).not.toEqual(initialValue); expect(findPreview().props('policyYaml')).not.toEqual(initialValue);
}); });
it('given there is a rule change, updates policy description preview', async () => { it('given there is a rule change, updates policy description preview', async () => {
const initialValue = findPreview().props('policyDescription'); const initialValue = findPreview().props('policyDescription');
findAddRuleButton().vm.$emit('click'); await findAddRuleButton().vm.$emit('click');
await wrapper.vm.$nextTick();
expect(findPreview().props('policyDescription')).not.toEqual(initialValue); expect(findPreview().props('policyDescription')).not.toEqual(initialValue);
}); });
it('adds a new rule', async () => { it('adds a new rule', async () => {
expect(wrapper.findAllComponents(PolicyRuleBuilder)).toHaveLength(1); expect(wrapper.findAllComponents(PolicyRuleBuilder)).toHaveLength(1);
const button = findAddRuleButton(); const button = findAddRuleButton();
button.vm.$emit('click'); await button.vm.$emit('click');
button.vm.$emit('click'); await button.vm.$emit('click');
await wrapper.vm.$nextTick();
const elements = wrapper.findAllComponents(PolicyRuleBuilder); const elements = wrapper.findAllComponents(PolicyRuleBuilder);
expect(elements).toHaveLength(3); expect(elements).toHaveLength(3);
...@@ -186,20 +180,17 @@ describe('NetworkPolicyEditor component', () => { ...@@ -186,20 +180,17 @@ describe('NetworkPolicyEditor component', () => {
}); });
it('removes a new rule', async () => { it('removes a new rule', async () => {
findAddRuleButton().vm.$emit('click'); await findAddRuleButton().vm.$emit('click');
await wrapper.vm.$nextTick();
expect(wrapper.findAllComponents(PolicyRuleBuilder)).toHaveLength(2); expect(wrapper.findAllComponents(PolicyRuleBuilder)).toHaveLength(2);
findPolicyRuleBuilder().vm.$emit('remove'); await findPolicyRuleBuilder().vm.$emit('remove');
await wrapper.vm.$nextTick();
expect(wrapper.findAllComponents(PolicyRuleBuilder)).toHaveLength(1); expect(wrapper.findAllComponents(PolicyRuleBuilder)).toHaveLength(1);
}); });
it('updates yaml editor value on switch to yaml editor', async () => { it('updates yaml editor value on switch to yaml editor', async () => {
const policyEditorLayout = findPolicyEditorLayout(); const policyEditorLayout = findPolicyEditorLayout();
findPolicyName().vm.$emit('input', 'test-policy'); findPolicyName().vm.$emit('input', 'test-policy');
policyEditorLayout.vm.$emit('update-editor-mode', EDITOR_MODE_YAML); await policyEditorLayout.vm.$emit('update-editor-mode', EDITOR_MODE_YAML);
await wrapper.vm.$nextTick();
expect(fromYaml(policyEditorLayout.attributes('yamleditorvalue'))).toMatchObject({ expect(fromYaml(policyEditorLayout.attributes('yamleditorvalue'))).toMatchObject({
name: 'test-policy', name: 'test-policy',
}); });
...@@ -245,16 +236,13 @@ describe('NetworkPolicyEditor component', () => { ...@@ -245,16 +236,13 @@ describe('NetworkPolicyEditor component', () => {
it('does not update yaml editor value on switch to yaml editor', async () => { it('does not update yaml editor value on switch to yaml editor', async () => {
findPolicyName().vm.$emit('input', 'test-policy'); findPolicyName().vm.$emit('input', 'test-policy');
const policyEditorLayout = findPolicyEditorLayout(); const policyEditorLayout = findPolicyEditorLayout();
policyEditorLayout.vm.$emit('update-editor-mode', EDITOR_MODE_YAML); await policyEditorLayout.vm.$emit('update-editor-mode', EDITOR_MODE_YAML);
await wrapper.vm.$nextTick();
expect(policyEditorLayout.attributes('yamleditorvalue')).toEqual(''); expect(policyEditorLayout.attributes('yamleditorvalue')).toEqual('');
}); });
}); });
it('creates policy and redirects to a threat monitoring path', async () => { it('creates policy and redirects to a threat monitoring path', async () => {
findPolicyEditorLayout().vm.$emit('save-policy'); await findPolicyEditorLayout().vm.$emit('save-policy');
await wrapper.vm.$nextTick();
expect(store.dispatch).toHaveBeenCalledWith('networkPolicies/createPolicy', { expect(store.dispatch).toHaveBeenCalledWith('networkPolicies/createPolicy', {
environmentId: -1, environmentId: -1,
policy: { manifest: toYaml(wrapper.vm.policy) }, policy: { manifest: toYaml(wrapper.vm.policy) },
...@@ -272,8 +260,7 @@ describe('NetworkPolicyEditor component', () => { ...@@ -272,8 +260,7 @@ describe('NetworkPolicyEditor component', () => {
}); });
it('it does not redirect', async () => { it('it does not redirect', async () => {
findPolicyEditorLayout().vm.$emit('save-policy'); await findPolicyEditorLayout().vm.$emit('save-policy');
await wrapper.vm.$nextTick();
expect(redirectTo).not.toHaveBeenCalledWith('/threat-monitoring'); expect(redirectTo).not.toHaveBeenCalledWith('/threat-monitoring');
}); });
}); });
...@@ -299,8 +286,7 @@ describe('NetworkPolicyEditor component', () => { ...@@ -299,8 +286,7 @@ describe('NetworkPolicyEditor component', () => {
}); });
it('updates existing policy and redirects to a threat monitoring path', async () => { it('updates existing policy and redirects to a threat monitoring path', async () => {
findPolicyEditorLayout().vm.$emit('save-policy'); await findPolicyEditorLayout().vm.$emit('save-policy');
await wrapper.vm.$nextTick();
expect(store.dispatch).toHaveBeenCalledWith('networkPolicies/updatePolicy', { expect(store.dispatch).toHaveBeenCalledWith('networkPolicies/updatePolicy', {
environmentId: -1, environmentId: -1,
policy: { name: 'policy', manifest: toYaml(wrapper.vm.policy) }, policy: { name: 'policy', manifest: toYaml(wrapper.vm.policy) },
...@@ -328,8 +314,7 @@ describe('NetworkPolicyEditor component', () => { ...@@ -328,8 +314,7 @@ describe('NetworkPolicyEditor component', () => {
}); });
it('removes policy and redirects to a threat monitoring path on secondary modal button click', async () => { it('removes policy and redirects to a threat monitoring path on secondary modal button click', async () => {
findPolicyEditorLayout().vm.$emit('remove-policy'); await findPolicyEditorLayout().vm.$emit('remove-policy');
await wrapper.vm.$nextTick();
expect(store.dispatch).toHaveBeenCalledWith('networkPolicies/deletePolicy', { expect(store.dispatch).toHaveBeenCalledWith('networkPolicies/deletePolicy', {
environmentId: -1, environmentId: -1,
......
...@@ -58,15 +58,13 @@ describe('PolicyEditorLayout component', () => { ...@@ -58,15 +58,13 @@ describe('PolicyEditorLayout component', () => {
it('mode changes appropriately when new mode is selected', async () => { it('mode changes appropriately when new mode is selected', async () => {
expect(findRuleModeSection().exists()).toBe(true); expect(findRuleModeSection().exists()).toBe(true);
expect(findYamlModeSection().exists()).toBe(false); expect(findYamlModeSection().exists()).toBe(false);
findEditorModeToggle().vm.$emit('input', EDITOR_MODE_YAML); await findEditorModeToggle().vm.$emit('input', EDITOR_MODE_YAML);
await wrapper.vm.$nextTick();
expect(findRuleModeSection().exists()).toBe(false); expect(findRuleModeSection().exists()).toBe(false);
expect(findYamlModeSection().exists()).toBe(true); expect(findYamlModeSection().exists()).toBe(true);
expect(wrapper.emitted('update-editor-mode')).toStrictEqual([[EDITOR_MODE_YAML]]); expect(wrapper.emitted('update-editor-mode')).toStrictEqual([[EDITOR_MODE_YAML]]);
}); });
it('does display custom save button text', () => { it('does display custom save button text', () => {
// custom save button text works
const saveButton = findSavePolicyButton(); const saveButton = findSavePolicyButton();
expect(saveButton.exists()).toBe(true); expect(saveButton.exists()).toBe(true);
expect(saveButton.text()).toBe('Create policy'); expect(saveButton.text()).toBe('Create policy');
...@@ -118,7 +116,7 @@ describe('PolicyEditorLayout component', () => { ...@@ -118,7 +116,7 @@ describe('PolicyEditorLayout component', () => {
expect(findComponent().exists()).toBe(state); expect(findComponent().exists()).toBe(state);
}); });
it('emits propertly when yaml is updated', () => { it('emits properly when yaml is updated', () => {
const newManifest = 'new yaml!'; const newManifest = 'new yaml!';
findYamlModeSection().vm.$emit('input', newManifest); findYamlModeSection().vm.$emit('input', newManifest);
expect(wrapper.emitted('update-yaml')).toStrictEqual([[newManifest]]); expect(wrapper.emitted('update-yaml')).toStrictEqual([[newManifest]]);
......
...@@ -2,7 +2,6 @@ import { shallowMount } from '@vue/test-utils'; ...@@ -2,7 +2,6 @@ import { shallowMount } from '@vue/test-utils';
import PolicyEditorLayout from 'ee/threat_monitoring/components/policy_editor/policy_editor_layout.vue'; import PolicyEditorLayout from 'ee/threat_monitoring/components/policy_editor/policy_editor_layout.vue';
import { DEFAULT_SCAN_EXECUTION_POLICY } from 'ee/threat_monitoring/components/policy_editor/scan_execution_policy/lib'; import { DEFAULT_SCAN_EXECUTION_POLICY } from 'ee/threat_monitoring/components/policy_editor/scan_execution_policy/lib';
import ScanExecutionPolicyEditor from 'ee/threat_monitoring/components/policy_editor/scan_execution_policy/scan_execution_policy_editor.vue'; import ScanExecutionPolicyEditor from 'ee/threat_monitoring/components/policy_editor/scan_execution_policy/scan_execution_policy_editor.vue';
import waitForPromises from 'helpers/wait_for_promises';
describe('ScanExecutionPolicyEditor', () => { describe('ScanExecutionPolicyEditor', () => {
let wrapper; let wrapper;
...@@ -27,36 +26,12 @@ describe('ScanExecutionPolicyEditor', () => { ...@@ -27,36 +26,12 @@ describe('ScanExecutionPolicyEditor', () => {
wrapper.destroy(); wrapper.destroy();
}); });
it('calls the save policy funtion when "save-policy" is emitted', async () => {
const savePolicySpy = jest.spyOn(wrapper.vm, 'savePolicy');
expect(wrapper.vm.savePolicy).toHaveBeenCalledTimes(0);
findPolicyEditorLayout().vm.$emit('save-policy');
await waitForPromises();
expect(wrapper.vm.savePolicy).toHaveBeenCalledTimes(1);
savePolicySpy.mockRestore();
});
it('calls the remove policy funtion when "remove-policy" is emitted', async () => {
const removePolicySpy = jest.spyOn(wrapper.vm, 'removePolicy');
expect(wrapper.vm.removePolicy).toHaveBeenCalledTimes(0);
findPolicyEditorLayout().vm.$emit('remove-policy');
await waitForPromises();
expect(wrapper.vm.removePolicy).toHaveBeenCalledTimes(1);
removePolicySpy.mockRestore();
});
it('updates the policy yaml when "update-yaml" is emitted', async () => { it('updates the policy yaml when "update-yaml" is emitted', async () => {
const updateYamlSpy = jest.spyOn(wrapper.vm, 'updateYaml');
const newManifest = 'new yaml!'; const newManifest = 'new yaml!';
expect(wrapper.vm.updateYaml).toHaveBeenCalledTimes(0);
expect(findPolicyEditorLayout().attributes('yamleditorvalue')).toBe( expect(findPolicyEditorLayout().attributes('yamleditorvalue')).toBe(
DEFAULT_SCAN_EXECUTION_POLICY, DEFAULT_SCAN_EXECUTION_POLICY,
); );
findPolicyEditorLayout().vm.$emit('update-yaml', newManifest); await findPolicyEditorLayout().vm.$emit('update-yaml', newManifest);
await waitForPromises(); expect(findPolicyEditorLayout().attributes('yamleditorvalue')).toBe(newManifest);
expect(wrapper.vm.updateYaml).toHaveBeenCalledTimes(1);
expect(wrapper.vm.updateYaml).toHaveBeenCalledWith(newManifest);
expect(findPolicyEditorLayout().attributes('yaml-editor-value')).toBe(newManifest);
updateYamlSpy.mockRestore();
}); });
}); });
...@@ -21755,6 +21755,9 @@ msgstr "" ...@@ -21755,6 +21755,9 @@ msgstr ""
msgid "NetworkPolicies|Save changes" msgid "NetworkPolicies|Save changes"
msgstr "" msgstr ""
msgid "NetworkPolicies|Scan Execution"
msgstr ""
msgid "NetworkPolicies|Something went wrong, failed to update policy" msgid "NetworkPolicies|Something went wrong, failed to update policy"
msgstr "" 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