diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 13:16:36 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 13:16:36 +0000 |
commit | 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch) | |
tree | 07e7870bca8aed6d61fdcc810731c50d2c40af47 /spec/frontend/crm/organizations_root_spec.js | |
parent | 27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff) | |
download | gitlab-ce-311b0269b4eb9839fa63f80c8d7a58f32b8138a0.tar.gz |
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'spec/frontend/crm/organizations_root_spec.js')
-rw-r--r-- | spec/frontend/crm/organizations_root_spec.js | 60 |
1 files changed, 60 insertions, 0 deletions
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); + }); +}); |