diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 13:00:54 +0300 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /spec/frontend/crm/contact_form_spec.js | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'spec/frontend/crm/contact_form_spec.js')
-rw-r--r-- | spec/frontend/crm/contact_form_spec.js | 157 |
1 files changed, 0 insertions, 157 deletions
diff --git a/spec/frontend/crm/contact_form_spec.js b/spec/frontend/crm/contact_form_spec.js deleted file mode 100644 index 0edab4f5ec5..00000000000 --- a/spec/frontend/crm/contact_form_spec.js +++ /dev/null @@ -1,157 +0,0 @@ -import { GlAlert } from '@gitlab/ui'; -import Vue from 'vue'; -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 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 contact form component', () => { - Vue.use(VueApollo); - let wrapper; - let fakeApollo; - let mutation; - let queryHandler; - - 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, editForm = false } = {}) => { - fakeApollo = createMockApollo([[mutation, queryHandler]]); - fakeApollo.clients.defaultClient.cache.writeQuery({ - query: getGroupContactsQuery, - variables: { groupFullPath: 'flightjs' }, - data: getGroupContactsQueryResponse.data, - }); - 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, - }); - }; - - beforeEach(() => { - mutation = createContactMutation; - queryHandler = jest.fn().mockResolvedValue(createContactMutationResponse); - }); - - afterEach(() => { - wrapper.destroy(); - fakeApollo = null; - }); - - describe('Save contact button', () => { - it('should be disabled when required fields are empty', () => { - mountComponent(); - - expect(findSaveContactButton().props('disabled')).toBe(true); - }); - - it('should not be disabled when required fields have values', async () => { - mountComponent(); - - wrapper.find('#contact-first-name').vm.$emit('input', 'A'); - wrapper.find('#contact-last-name').vm.$emit('input', 'B'); - wrapper.find('#contact-email').vm.$emit('input', 'C'); - await waitForPromises(); - - expect(findSaveContactButton().props('disabled')).toBe(false); - }); - }); - - it("should emit 'close' when cancel button is clicked", () => { - mountComponent(); - - findCancelButton().vm.$emit('click'); - - expect(wrapper.emitted().close).toBeTruthy(); - }); - - describe('when create mutation is successful', () => { - it("should emit 'close'", async () => { - mountComponent(); - - findForm().trigger('submit'); - await waitForPromises(); - - expect(wrapper.emitted().close).toBeTruthy(); - }); - }); - - describe('when create mutation fails', () => { - it('should show error on reject', async () => { - queryHandler = jest.fn().mockRejectedValue('ERROR'); - mountComponent(); - - findForm().trigger('submit'); - await waitForPromises(); - - expect(findError().exists()).toBe(true); - }); - - it('should show error on error response', async () => { - queryHandler = jest.fn().mockResolvedValue(createContactMutationErrorResponse); - mountComponent(); - - findForm().trigger('submit'); - await waitForPromises(); - - expect(findError().exists()).toBe(true); - expect(findError().text()).toBe('create contact 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('update contact is invalid.'); - }); - }); -}); |