2020-02-19 07:09:13 -05:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2020-10-02 14:08:56 -04:00
|
|
|
import { GlAlert, GlToggle, GlDropdown } from '@gitlab/ui';
|
2020-02-19 07:09:13 -05:00
|
|
|
import IngressModsecuritySettings from '~/clusters/components/ingress_modsecurity_settings.vue';
|
|
|
|
import { APPLICATION_STATUS, INGRESS } from '~/clusters/constants';
|
|
|
|
import eventHub from '~/clusters/event_hub';
|
|
|
|
|
|
|
|
const { UPDATING } = APPLICATION_STATUS;
|
|
|
|
|
|
|
|
describe('IngressModsecuritySettings', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
modsecurity_enabled: false,
|
|
|
|
status: 'installable',
|
|
|
|
installed: false,
|
2020-03-19 05:09:27 -04:00
|
|
|
modsecurity_mode: 'logging',
|
2020-03-27 17:07:53 -04:00
|
|
|
updateAvailable: false,
|
2020-02-19 07:09:13 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const createComponent = (props = defaultProps) => {
|
|
|
|
wrapper = shallowMount(IngressModsecuritySettings, {
|
|
|
|
propsData: {
|
|
|
|
ingress: {
|
|
|
|
...defaultProps,
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-10-01 02:09:59 -04:00
|
|
|
const findSaveButton = () =>
|
|
|
|
wrapper.find('[data-qa-selector="save_ingress_modsecurity_settings"]');
|
|
|
|
const findCancelButton = () =>
|
|
|
|
wrapper.find('[data-qa-selector="cancel_ingress_modsecurity_settings"]');
|
2020-03-13 05:09:23 -04:00
|
|
|
const findModSecurityToggle = () => wrapper.find(GlToggle);
|
2020-10-02 14:08:56 -04:00
|
|
|
const findModSecurityDropdown = () => wrapper.find(GlDropdown);
|
2020-02-19 07:09:13 -05:00
|
|
|
|
|
|
|
describe('when ingress is installed', () => {
|
|
|
|
beforeEach(() => {
|
2020-03-13 05:09:23 -04:00
|
|
|
createComponent({ installed: true, status: 'installed' });
|
2020-02-19 07:09:13 -05:00
|
|
|
jest.spyOn(eventHub, '$emit');
|
|
|
|
});
|
|
|
|
|
2020-03-13 05:09:23 -04:00
|
|
|
it('does not render save and cancel buttons', () => {
|
|
|
|
expect(findSaveButton().exists()).toBe(false);
|
|
|
|
expect(findCancelButton().exists()).toBe(false);
|
2020-02-19 07:09:13 -05:00
|
|
|
});
|
|
|
|
|
2020-03-13 05:09:23 -04:00
|
|
|
describe('with toggle changed by the user', () => {
|
2020-02-19 07:09:13 -05:00
|
|
|
beforeEach(() => {
|
2020-03-13 05:09:23 -04:00
|
|
|
findModSecurityToggle().vm.$emit('change');
|
2020-03-19 05:09:27 -04:00
|
|
|
wrapper.setProps({
|
|
|
|
ingress: {
|
|
|
|
...defaultProps,
|
|
|
|
installed: true,
|
|
|
|
status: 'installed',
|
|
|
|
modsecurity_enabled: true,
|
|
|
|
},
|
|
|
|
});
|
2020-03-13 05:09:23 -04:00
|
|
|
});
|
|
|
|
|
2020-03-19 05:09:27 -04:00
|
|
|
it('renders save and cancel buttons', () => {
|
2020-03-13 05:09:23 -04:00
|
|
|
expect(findSaveButton().exists()).toBe(true);
|
|
|
|
expect(findCancelButton().exists()).toBe(true);
|
2020-02-19 07:09:13 -05:00
|
|
|
});
|
|
|
|
|
2020-03-27 17:07:53 -04:00
|
|
|
it('enables related toggle and buttons', () => {
|
|
|
|
expect(findSaveButton().attributes().disabled).toBeUndefined();
|
|
|
|
expect(findCancelButton().attributes().disabled).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
2020-03-19 05:09:27 -04:00
|
|
|
describe('with dropdown changed by the user', () => {
|
2020-03-13 05:09:23 -04:00
|
|
|
beforeEach(() => {
|
2020-03-19 05:09:27 -04:00
|
|
|
findModSecurityDropdown().vm.$children[1].$emit('click');
|
|
|
|
wrapper.setProps({
|
|
|
|
ingress: {
|
|
|
|
...defaultProps,
|
|
|
|
installed: true,
|
|
|
|
status: 'installed',
|
|
|
|
modsecurity_enabled: true,
|
|
|
|
modsecurity_mode: 'blocking',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders both save and cancel buttons', () => {
|
|
|
|
expect(findSaveButton().exists()).toBe(true);
|
|
|
|
expect(findCancelButton().exists()).toBe(true);
|
2020-03-13 05:09:23 -04:00
|
|
|
});
|
|
|
|
|
2020-03-19 05:09:27 -04:00
|
|
|
describe('and the save changes button is clicked', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
findSaveButton().vm.$emit('click');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('triggers save event and pass current modsecurity value', () => {
|
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('updateApplication', {
|
|
|
|
id: INGRESS,
|
|
|
|
params: { modsecurity_enabled: true, modsecurity_mode: 'blocking' },
|
|
|
|
});
|
2020-02-19 07:09:13 -05:00
|
|
|
});
|
2020-03-13 05:09:23 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('and the cancel button is clicked', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
findCancelButton().vm.$emit('click');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('triggers reset event and hides both cancel and save changes button', () => {
|
2020-03-19 05:09:27 -04:00
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('resetIngressModSecurityChanges', INGRESS);
|
2020-03-13 05:09:23 -04:00
|
|
|
expect(findSaveButton().exists()).toBe(false);
|
|
|
|
expect(findCancelButton().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2020-03-27 17:07:53 -04:00
|
|
|
|
|
|
|
describe('with a new version available', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper.setProps({
|
|
|
|
ingress: {
|
|
|
|
...defaultProps,
|
|
|
|
installed: true,
|
|
|
|
status: 'installed',
|
|
|
|
modsecurity_enabled: true,
|
|
|
|
updateAvailable: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('disables related toggle and buttons', () => {
|
|
|
|
expect(findSaveButton().attributes().disabled).toBe('true');
|
|
|
|
expect(findCancelButton().attributes().disabled).toBe('true');
|
|
|
|
});
|
|
|
|
});
|
2020-02-19 07:09:13 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('triggers set event to be propagated with the current modsecurity value', () => {
|
|
|
|
wrapper.setData({ modSecurityEnabled: true });
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('setIngressModSecurityEnabled', {
|
|
|
|
id: INGRESS,
|
|
|
|
modSecurityEnabled: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(`when ingress status is ${UPDATING}`, () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ installed: true, status: UPDATING });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders loading spinner in save button', () => {
|
|
|
|
expect(findSaveButton().props('loading')).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders disabled save button', () => {
|
|
|
|
expect(findSaveButton().props('disabled')).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders save button with "Saving" label', () => {
|
2020-03-13 05:09:23 -04:00
|
|
|
expect(findSaveButton().text()).toBe('Saving');
|
2020-02-19 07:09:13 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when ingress fails to update', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ updateFailed: true });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('displays a error message', () => {
|
|
|
|
expect(wrapper.find(GlAlert).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when ingress is not installed', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render the save button', () => {
|
|
|
|
expect(findSaveButton().exists()).toBe(false);
|
2020-03-13 05:09:23 -04:00
|
|
|
expect(findModSecurityToggle().props('value')).toBe(false);
|
2020-02-19 07:09:13 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|