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