Commit 13314608 authored by Dave Pisek's avatar Dave Pisek

Feedback: Improve specs

* Fix test descriptions
* Move setting input value to helper
parent ef02c5c7
......@@ -62,6 +62,11 @@ describe('DastSiteProfileForm', () => {
const findSiteValidationToggle = () => findByTestId('dast-site-validation-toggle');
const findDastSiteValidation = () => wrapper.find(DastSiteValidation);
const setFieldValue = async (field, value) => {
await field.setValue(value);
field.trigger('blur');
};
const mockClientFactory = handlers => {
const mockClient = createMockClient();
......@@ -132,16 +137,13 @@ describe('DastSiteProfileForm', () => {
});
it.each(['asd', 'example.com'])('is marked as invalid provided an invalid URL', async value => {
findTargetUrlInput().setValue(value);
findTargetUrlInput().trigger('blur');
await wrapper.vm.$nextTick();
await setFieldValue(findTargetUrlInput(), value);
expect(wrapper.text()).toContain(errorMessage);
});
it('is marked as valid provided a valid URL', async () => {
findTargetUrlInput().setValue(targetUrl);
await wrapper.vm.$nextTick();
await setFieldValue(findTargetUrlInput(), targetUrl);
expect(wrapper.text()).not.toContain(errorMessage);
});
......@@ -149,8 +151,7 @@ describe('DastSiteProfileForm', () => {
describe('validation', () => {
const enableValidationToggle = async () => {
await findTargetUrlInput().setValue(targetUrl);
await findTargetUrlInput().trigger('blur');
await setFieldValue(findTargetUrlInput(), targetUrl);
await findSiteValidationToggle().vm.$emit('change', true);
};
......@@ -197,9 +198,7 @@ describe('DastSiteProfileForm', () => {
it('toggle is disabled until target URL is valid', async () => {
expect(findSiteValidationToggle().props('disabled')).toBe(true);
await findTargetUrlInput().setValue(targetUrl);
await findTargetUrlInput().trigger('input');
await findTargetUrlInput().trigger('blur');
await setFieldValue(findTargetUrlInput(), targetUrl);
expect(findSiteValidationToggle().props('disabled')).toBe(false);
});
......@@ -308,11 +307,8 @@ describe('DastSiteProfileForm', () => {
describe('submission', () => {
const fillAndSubmitForm = async () => {
await findProfileNameInput().setValue(profileName);
findProfileNameInput().trigger('blur');
await findTargetUrlInput().setValue(targetUrl);
findTargetUrlInput().trigger('blur');
await setFieldValue(findProfileNameInput(), profileName);
await setFieldValue(findTargetUrlInput(), targetUrl);
submitForm();
};
......
......@@ -93,14 +93,14 @@ describe('validation directive', () => {
setValueAndTriggerValidation(validValue);
});
it('leaves the field to be valid', () => {
it('sets the field to be valid', () => {
expect(getFormData().fields.exampleField).toEqual({
state: true,
feedback: '',
});
});
it('leaves the form to be valid', () => {
it('sets the form to be valid', () => {
expect(getFormData().state).toBe(true);
});
});
......
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