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:
Diffstat (limited to 'spec/frontend/crm/contacts_root_spec.js')
-rw-r--r--spec/frontend/crm/contacts_root_spec.js60
1 files changed, 60 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);
+ });
+});