diff options
Diffstat (limited to 'spec/frontend/crm')
-rw-r--r-- | spec/frontend/crm/contacts_root_spec.js | 60 | ||||
-rw-r--r-- | spec/frontend/crm/mock_data.js | 81 | ||||
-rw-r--r-- | spec/frontend/crm/organizations_root_spec.js | 60 |
3 files changed, 201 insertions, 0 deletions
diff --git a/spec/frontend/crm/contacts_root_spec.js b/spec/frontend/crm/contacts_root_spec.js new file mode 100644 index 00000000000..79b85969eb4 --- /dev/null +++ b/spec/frontend/crm/contacts_root_spec.js @@ -0,0 +1,60 @@ +import { GlLoadingIcon } from '@gitlab/ui'; +import Vue from 'vue'; +import VueApollo from 'vue-apollo'; +import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper'; +import createMockApollo from 'helpers/mock_apollo_helper'; +import waitForPromises from 'helpers/wait_for_promises'; +import createFlash from '~/flash'; +import ContactsRoot from '~/crm/components/contacts_root.vue'; +import getGroupContactsQuery from '~/crm/components/queries/get_group_contacts.query.graphql'; +import { getGroupContactsQueryResponse } from './mock_data'; + +jest.mock('~/flash'); + +describe('Customer relations contacts root app', () => { + Vue.use(VueApollo); + let wrapper; + let fakeApollo; + + const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon); + const findRowByName = (rowName) => wrapper.findAllByRole('row', { name: rowName }); + const successQueryHandler = jest.fn().mockResolvedValue(getGroupContactsQueryResponse); + + const mountComponent = ({ + queryHandler = successQueryHandler, + mountFunction = shallowMountExtended, + } = {}) => { + fakeApollo = createMockApollo([[getGroupContactsQuery, queryHandler]]); + wrapper = mountFunction(ContactsRoot, { + provide: { groupFullPath: 'flightjs' }, + apolloProvider: fakeApollo, + }); + }; + + afterEach(() => { + wrapper.destroy(); + fakeApollo = null; + }); + + it('should render loading spinner', () => { + mountComponent(); + + expect(findLoadingIcon().exists()).toBe(true); + }); + + it('should render error message on reject', async () => { + mountComponent({ queryHandler: jest.fn().mockRejectedValue('ERROR') }); + await waitForPromises(); + + expect(createFlash).toHaveBeenCalled(); + }); + + it('renders correct results', async () => { + mountComponent({ mountFunction: mountExtended }); + await waitForPromises(); + + expect(findRowByName(/Marty/i)).toHaveLength(1); + expect(findRowByName(/George/i)).toHaveLength(1); + expect(findRowByName(/jd@gitlab.com/i)).toHaveLength(1); + }); +}); diff --git a/spec/frontend/crm/mock_data.js b/spec/frontend/crm/mock_data.js new file mode 100644 index 00000000000..4197621aaa6 --- /dev/null +++ b/spec/frontend/crm/mock_data.js @@ -0,0 +1,81 @@ +export const getGroupContactsQueryResponse = { + data: { + group: { + __typename: 'Group', + id: 'gid://gitlab/Group/26', + contacts: { + nodes: [ + { + __typename: 'CustomerRelationsContact', + id: 'gid://gitlab/CustomerRelations::Contact/12', + firstName: 'Marty', + lastName: 'McFly', + email: 'example@gitlab.com', + phone: null, + description: null, + organization: { + __typename: 'CustomerRelationsOrganization', + id: 'gid://gitlab/CustomerRelations::Organization/2', + name: 'Tech Giant Inc', + }, + }, + { + __typename: 'CustomerRelationsContact', + id: 'gid://gitlab/CustomerRelations::Contact/16', + firstName: 'Boy', + lastName: 'George', + email: null, + phone: null, + description: null, + organization: null, + }, + { + __typename: 'CustomerRelationsContact', + id: 'gid://gitlab/CustomerRelations::Contact/13', + firstName: 'Jane', + lastName: 'Doe', + email: 'jd@gitlab.com', + phone: '+44 44 4444 4444', + description: 'Vice President', + organization: null, + }, + ], + __typename: 'CustomerRelationsContactConnection', + }, + }, + }, +}; + +export const getGroupOrganizationsQueryResponse = { + data: { + group: { + __typename: 'Group', + id: 'gid://gitlab/Group/26', + organizations: { + nodes: [ + { + __typename: 'CustomerRelationsOrganization', + id: 'gid://gitlab/CustomerRelations::Organization/1', + name: 'Test Inc', + defaultRate: 100, + description: null, + }, + { + __typename: 'CustomerRelationsOrganization', + id: 'gid://gitlab/CustomerRelations::Organization/2', + name: 'ABC Company', + defaultRate: 110, + description: 'VIP', + }, + { + __typename: 'CustomerRelationsOrganization', + id: 'gid://gitlab/CustomerRelations::Organization/3', + name: 'GitLab', + defaultRate: 120, + description: null, + }, + ], + }, + }, + }, +}; diff --git a/spec/frontend/crm/organizations_root_spec.js b/spec/frontend/crm/organizations_root_spec.js new file mode 100644 index 00000000000..a69a099e03d --- /dev/null +++ b/spec/frontend/crm/organizations_root_spec.js @@ -0,0 +1,60 @@ +import { GlLoadingIcon } from '@gitlab/ui'; +import Vue from 'vue'; +import VueApollo from 'vue-apollo'; +import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper'; +import createMockApollo from 'helpers/mock_apollo_helper'; +import waitForPromises from 'helpers/wait_for_promises'; +import createFlash from '~/flash'; +import OrganizationsRoot from '~/crm/components/organizations_root.vue'; +import getGroupOrganizationsQuery from '~/crm/components/queries/get_group_organizations.query.graphql'; +import { getGroupOrganizationsQueryResponse } from './mock_data'; + +jest.mock('~/flash'); + +describe('Customer relations organizations root app', () => { + Vue.use(VueApollo); + let wrapper; + let fakeApollo; + + const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon); + const findRowByName = (rowName) => wrapper.findAllByRole('row', { name: rowName }); + const successQueryHandler = jest.fn().mockResolvedValue(getGroupOrganizationsQueryResponse); + + const mountComponent = ({ + queryHandler = successQueryHandler, + mountFunction = shallowMountExtended, + } = {}) => { + fakeApollo = createMockApollo([[getGroupOrganizationsQuery, queryHandler]]); + wrapper = mountFunction(OrganizationsRoot, { + provide: { groupFullPath: 'flightjs' }, + apolloProvider: fakeApollo, + }); + }; + + afterEach(() => { + wrapper.destroy(); + fakeApollo = null; + }); + + it('should render loading spinner', () => { + mountComponent(); + + expect(findLoadingIcon().exists()).toBe(true); + }); + + it('should render error message on reject', async () => { + mountComponent({ queryHandler: jest.fn().mockRejectedValue('ERROR') }); + await waitForPromises(); + + expect(createFlash).toHaveBeenCalled(); + }); + + it('renders correct results', async () => { + mountComponent({ mountFunction: mountExtended }); + await waitForPromises(); + + expect(findRowByName(/Test Inc/i)).toHaveLength(1); + expect(findRowByName(/VIP/i)).toHaveLength(1); + expect(findRowByName(/120/i)).toHaveLength(1); + }); +}); |