Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-12-16 03:15:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-12-16 03:15:50 +0300
commite04431d29efaf17dda9dfbfbd0c5001693b25ee4 (patch)
treef114abad1f4882ef6c9c702e8de3a84334809031 /spec/frontend/crm
parent1c898dc5c10bbedf94386d917259153d73608495 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/crm')
-rw-r--r--spec/frontend/crm/contact_form_spec.js (renamed from spec/frontend/crm/new_contact_form_spec.js)75
-rw-r--r--spec/frontend/crm/contacts_root_spec.js58
-rw-r--r--spec/frontend/crm/mock_data.js28
3 files changed, 134 insertions, 27 deletions
diff --git a/spec/frontend/crm/new_contact_form_spec.js b/spec/frontend/crm/contact_form_spec.js
index 1497c348676..b2753ad8cf5 100644
--- a/spec/frontend/crm/new_contact_form_spec.js
+++ b/spec/frontend/crm/contact_form_spec.js
@@ -4,41 +4,49 @@ import VueApollo from 'vue-apollo';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
-import NewContactForm from '~/crm/components/new_contact_form.vue';
+import ContactForm from '~/crm/components/contact_form.vue';
import createContactMutation from '~/crm/components/queries/create_contact.mutation.graphql';
+import updateContactMutation from '~/crm/components/queries/update_contact.mutation.graphql';
import getGroupContactsQuery from '~/crm/components/queries/get_group_contacts.query.graphql';
import {
createContactMutationErrorResponse,
createContactMutationResponse,
getGroupContactsQueryResponse,
+ updateContactMutationErrorResponse,
+ updateContactMutationResponse,
} from './mock_data';
-describe('Customer relations contacts root app', () => {
+describe('Customer relations contact form component', () => {
Vue.use(VueApollo);
let wrapper;
let fakeApollo;
+ let mutation;
let queryHandler;
- const findCreateNewContactButton = () => wrapper.findByTestId('create-new-contact-button');
+ const findSaveContactButton = () => wrapper.findByTestId('save-contact-button');
const findCancelButton = () => wrapper.findByTestId('cancel-button');
const findForm = () => wrapper.find('form');
const findError = () => wrapper.findComponent(GlAlert);
- const mountComponent = ({ mountFunction = shallowMountExtended } = {}) => {
- fakeApollo = createMockApollo([[createContactMutation, queryHandler]]);
+ const mountComponent = ({ mountFunction = shallowMountExtended, editForm = false } = {}) => {
+ fakeApollo = createMockApollo([[mutation, queryHandler]]);
fakeApollo.clients.defaultClient.cache.writeQuery({
query: getGroupContactsQuery,
variables: { groupFullPath: 'flightjs' },
data: getGroupContactsQueryResponse.data,
});
- wrapper = mountFunction(NewContactForm, {
+ const propsData = { drawerOpen: true };
+ if (editForm)
+ propsData.contact = { firstName: 'First', lastName: 'Last', email: 'email@example.com' };
+ wrapper = mountFunction(ContactForm, {
provide: { groupId: 26, groupFullPath: 'flightjs' },
apolloProvider: fakeApollo,
- propsData: { drawerOpen: true },
+ propsData,
});
};
beforeEach(() => {
+ mutation = createContactMutation;
queryHandler = jest.fn().mockResolvedValue(createContactMutationResponse);
});
@@ -47,14 +55,14 @@ describe('Customer relations contacts root app', () => {
fakeApollo = null;
});
- describe('Create new contact button', () => {
- it('should be disabled by default', () => {
+ describe('Save contact button', () => {
+ it('should be disabled when required fields are empty', () => {
mountComponent();
- expect(findCreateNewContactButton().attributes('disabled')).toBeTruthy();
+ expect(findSaveContactButton().props('disabled')).toBe(true);
});
- it('should not be disabled when first, last and email have values', async () => {
+ it('should not be disabled when required fields have values', async () => {
mountComponent();
wrapper.find('#contact-first-name').vm.$emit('input', 'A');
@@ -62,7 +70,7 @@ describe('Customer relations contacts root app', () => {
wrapper.find('#contact-email').vm.$emit('input', 'C');
await waitForPromises();
- expect(findCreateNewContactButton().attributes('disabled')).toBeFalsy();
+ expect(findSaveContactButton().props('disabled')).toBe(false);
});
});
@@ -74,7 +82,7 @@ describe('Customer relations contacts root app', () => {
expect(wrapper.emitted().close).toBeTruthy();
});
- describe('when query is successful', () => {
+ describe('when create mutation is successful', () => {
it("should emit 'close'", async () => {
mountComponent();
@@ -85,7 +93,7 @@ describe('Customer relations contacts root app', () => {
});
});
- describe('when query fails', () => {
+ describe('when create mutation fails', () => {
it('should show error on reject', async () => {
queryHandler = jest.fn().mockRejectedValue('ERROR');
mountComponent();
@@ -107,4 +115,43 @@ describe('Customer relations contacts root app', () => {
expect(findError().text()).toBe('Phone is invalid.');
});
});
+
+ describe('when update mutation is successful', () => {
+ it("should emit 'close'", async () => {
+ mutation = updateContactMutation;
+ queryHandler = jest.fn().mockResolvedValue(updateContactMutationResponse);
+ mountComponent({ editForm: true });
+
+ findForm().trigger('submit');
+ await waitForPromises();
+
+ expect(wrapper.emitted().close).toBeTruthy();
+ });
+ });
+
+ describe('when update mutation fails', () => {
+ beforeEach(() => {
+ mutation = updateContactMutation;
+ });
+
+ it('should show error on reject', async () => {
+ queryHandler = jest.fn().mockRejectedValue('ERROR');
+ mountComponent({ editForm: true });
+ findForm().trigger('submit');
+ await waitForPromises();
+
+ expect(findError().exists()).toBe(true);
+ });
+
+ it('should show error on error response', async () => {
+ queryHandler = jest.fn().mockResolvedValue(updateContactMutationErrorResponse);
+ mountComponent({ editForm: true });
+
+ findForm().trigger('submit');
+ await waitForPromises();
+
+ expect(findError().exists()).toBe(true);
+ expect(findError().text()).toBe('Email is invalid.');
+ });
+ });
});
diff --git a/spec/frontend/crm/contacts_root_spec.js b/spec/frontend/crm/contacts_root_spec.js
index 18bd2d7c45b..b30349305a3 100644
--- a/spec/frontend/crm/contacts_root_spec.js
+++ b/spec/frontend/crm/contacts_root_spec.js
@@ -6,8 +6,10 @@ import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_help
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
import ContactsRoot from '~/crm/components/contacts_root.vue';
-import NewContactForm from '~/crm/components/new_contact_form.vue';
+import ContactForm from '~/crm/components/contact_form.vue';
import getGroupContactsQuery from '~/crm/components/queries/get_group_contacts.query.graphql';
+import { NEW_ROUTE_NAME, EDIT_ROUTE_NAME } from '~/crm/constants';
+import routes from '~/crm/routes';
import { getGroupContactsQueryResponse } from './mock_data';
describe('Customer relations contacts root app', () => {
@@ -21,7 +23,8 @@ describe('Customer relations contacts root app', () => {
const findRowByName = (rowName) => wrapper.findAllByRole('row', { name: rowName });
const findIssuesLinks = () => wrapper.findAllByTestId('issues-link');
const findNewContactButton = () => wrapper.findByTestId('new-contact-button');
- const findNewContactForm = () => wrapper.findComponent(NewContactForm);
+ const findEditContactButton = () => wrapper.findByTestId('edit-contact-button');
+ const findContactForm = () => wrapper.findComponent(ContactForm);
const findError = () => wrapper.findComponent(GlAlert);
const successQueryHandler = jest.fn().mockResolvedValue(getGroupContactsQueryResponse);
@@ -49,7 +52,7 @@ describe('Customer relations contacts root app', () => {
router = new VueRouter({
base: basePath,
mode: 'history',
- routes: [],
+ routes,
});
});
@@ -79,12 +82,12 @@ describe('Customer relations contacts root app', () => {
});
});
- describe('new contact form', () => {
+ describe('contact form', () => {
it('should not exist by default', async () => {
mountComponent();
await waitForPromises();
- expect(findNewContactForm().exists()).toBe(false);
+ expect(findContactForm().exists()).toBe(false);
});
it('should exist when user clicks new contact button', async () => {
@@ -93,25 +96,54 @@ describe('Customer relations contacts root app', () => {
findNewContactButton().vm.$emit('click');
await waitForPromises();
- expect(findNewContactForm().exists()).toBe(true);
+ expect(findContactForm().exists()).toBe(true);
});
- it('should exist when user navigates directly to /new', async () => {
- router.replace({ path: '/new' });
+ it('should exist when user navigates directly to `new` route', async () => {
+ router.replace({ name: NEW_ROUTE_NAME });
mountComponent();
await waitForPromises();
- expect(findNewContactForm().exists()).toBe(true);
+ expect(findContactForm().exists()).toBe(true);
});
- it('should not exist when form emits close', async () => {
- router.replace({ path: '/new' });
+ it('should exist when user clicks edit contact button', async () => {
+ mountComponent({ mountFunction: mountExtended });
+ await waitForPromises();
+
+ findEditContactButton().vm.$emit('click');
+ await waitForPromises();
+
+ expect(findContactForm().exists()).toBe(true);
+ });
+
+ it('should exist when user navigates directly to `edit` route', async () => {
+ router.replace({ name: EDIT_ROUTE_NAME, params: { id: 16 } });
mountComponent();
+ await waitForPromises();
+
+ expect(findContactForm().exists()).toBe(true);
+ });
+
+ it('should not exist when new form emits close', async () => {
+ router.replace({ name: NEW_ROUTE_NAME });
+ mountComponent();
+
+ findContactForm().vm.$emit('close');
+ await waitForPromises();
+
+ expect(findContactForm().exists()).toBe(false);
+ });
+
+ it('should not exist when edit form emits close', async () => {
+ router.replace({ name: EDIT_ROUTE_NAME, params: { id: 16 } });
+ mountComponent();
+ await waitForPromises();
- findNewContactForm().vm.$emit('close');
+ findContactForm().vm.$emit('close');
await waitForPromises();
- expect(findNewContactForm().exists()).toBe(false);
+ expect(findContactForm().exists()).toBe(false);
});
});
diff --git a/spec/frontend/crm/mock_data.js b/spec/frontend/crm/mock_data.js
index e784ac3764d..3abbc488081 100644
--- a/spec/frontend/crm/mock_data.js
+++ b/spec/frontend/crm/mock_data.js
@@ -106,3 +106,31 @@ export const createContactMutationErrorResponse = {
},
},
};
+
+export const updateContactMutationResponse = {
+ data: {
+ customerRelationsContactUpdate: {
+ __typeName: 'CustomerRelationsContactCreatePayload',
+ contact: {
+ __typename: 'CustomerRelationsContact',
+ id: 'gid://gitlab/CustomerRelations::Contact/1',
+ firstName: 'First',
+ lastName: 'Last',
+ email: 'email@example.com',
+ phone: null,
+ description: null,
+ organization: null,
+ },
+ errors: [],
+ },
+ },
+};
+
+export const updateContactMutationErrorResponse = {
+ data: {
+ customerRelationsContactUpdate: {
+ contact: null,
+ errors: ['Email is invalid.'],
+ },
+ },
+};