2021-12-06 19:14:07 -05:00
|
|
|
import { GlAlert, GlLoadingIcon } from '@gitlab/ui';
|
2021-11-15 19:11:15 -05:00
|
|
|
import Vue from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
2021-12-16 10:10:28 -05:00
|
|
|
import VueRouter from 'vue-router';
|
2021-11-15 19:11:15 -05:00
|
|
|
import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2022-03-31 17:08:16 -04:00
|
|
|
import OrganizationsRoot from '~/crm/organizations/components/organizations_root.vue';
|
|
|
|
import routes from '~/crm/organizations/routes';
|
|
|
|
import getGroupOrganizationsQuery from '~/crm/organizations/components/graphql/get_group_organizations.query.graphql';
|
2021-11-15 19:11:15 -05:00
|
|
|
import { getGroupOrganizationsQueryResponse } from './mock_data';
|
|
|
|
|
|
|
|
describe('Customer relations organizations root app', () => {
|
|
|
|
Vue.use(VueApollo);
|
2021-12-16 10:10:28 -05:00
|
|
|
Vue.use(VueRouter);
|
2021-11-15 19:11:15 -05:00
|
|
|
let wrapper;
|
|
|
|
let fakeApollo;
|
2021-12-16 10:10:28 -05:00
|
|
|
let router;
|
2021-11-15 19:11:15 -05:00
|
|
|
|
|
|
|
const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);
|
|
|
|
const findRowByName = (rowName) => wrapper.findAllByRole('row', { name: rowName });
|
2021-12-06 19:14:07 -05:00
|
|
|
const findIssuesLinks = () => wrapper.findAllByTestId('issues-link');
|
2021-12-16 10:10:28 -05:00
|
|
|
const findNewOrganizationButton = () => wrapper.findByTestId('new-organization-button');
|
2021-12-06 19:14:07 -05:00
|
|
|
const findError = () => wrapper.findComponent(GlAlert);
|
2021-11-15 19:11:15 -05:00
|
|
|
const successQueryHandler = jest.fn().mockResolvedValue(getGroupOrganizationsQueryResponse);
|
|
|
|
|
2021-12-16 10:10:28 -05:00
|
|
|
const basePath = '/groups/flightjs/-/crm/organizations';
|
|
|
|
|
2021-11-15 19:11:15 -05:00
|
|
|
const mountComponent = ({
|
|
|
|
queryHandler = successQueryHandler,
|
|
|
|
mountFunction = shallowMountExtended,
|
2021-12-16 10:10:28 -05:00
|
|
|
canAdminCrmOrganization = true,
|
2021-11-15 19:11:15 -05:00
|
|
|
} = {}) => {
|
|
|
|
fakeApollo = createMockApollo([[getGroupOrganizationsQuery, queryHandler]]);
|
|
|
|
wrapper = mountFunction(OrganizationsRoot, {
|
2021-12-16 10:10:28 -05:00
|
|
|
router,
|
2022-03-31 17:08:16 -04:00
|
|
|
provide: {
|
|
|
|
canAdminCrmOrganization,
|
|
|
|
groupFullPath: 'flightjs',
|
|
|
|
groupIssuesPath: '/issues',
|
|
|
|
},
|
2021-11-15 19:11:15 -05:00
|
|
|
apolloProvider: fakeApollo,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-12-16 10:10:28 -05:00
|
|
|
beforeEach(() => {
|
|
|
|
router = new VueRouter({
|
|
|
|
base: basePath,
|
|
|
|
mode: 'history',
|
|
|
|
routes,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-11-15 19:11:15 -05:00
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
fakeApollo = null;
|
2021-12-16 10:10:28 -05:00
|
|
|
router = null;
|
2021-11-15 19:11:15 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render loading spinner', () => {
|
|
|
|
mountComponent();
|
|
|
|
|
|
|
|
expect(findLoadingIcon().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2021-12-16 10:10:28 -05:00
|
|
|
describe('new organization button', () => {
|
|
|
|
it('should exist when user has permission', () => {
|
|
|
|
mountComponent();
|
|
|
|
|
|
|
|
expect(findNewOrganizationButton().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not exist when user has no permission', () => {
|
|
|
|
mountComponent({ canAdminCrmOrganization: false });
|
|
|
|
|
|
|
|
expect(findNewOrganizationButton().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-11-15 19:11:15 -05:00
|
|
|
it('should render error message on reject', async () => {
|
|
|
|
mountComponent({ queryHandler: jest.fn().mockRejectedValue('ERROR') });
|
|
|
|
await waitForPromises();
|
|
|
|
|
2021-12-06 19:14:07 -05:00
|
|
|
expect(findError().exists()).toBe(true);
|
2021-11-15 19:11:15 -05:00
|
|
|
});
|
|
|
|
|
2021-12-16 10:10:28 -05:00
|
|
|
describe('on successful load', () => {
|
|
|
|
it('should not render error', async () => {
|
|
|
|
mountComponent();
|
|
|
|
await waitForPromises();
|
2021-11-15 19:11:15 -05:00
|
|
|
|
2021-12-16 10:10:28 -05:00
|
|
|
expect(findError().exists()).toBe(false);
|
|
|
|
});
|
2021-12-06 19:14:07 -05:00
|
|
|
|
2021-12-16 10:10:28 -05:00
|
|
|
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);
|
|
|
|
|
|
|
|
const issueLink = findIssuesLinks().at(0);
|
|
|
|
expect(issueLink.exists()).toBe(true);
|
2022-05-13 05:07:54 -04:00
|
|
|
expect(issueLink.attributes('href')).toBe('/issues?crm_organization_id=2');
|
2021-12-16 10:10:28 -05:00
|
|
|
});
|
2021-11-15 19:11:15 -05:00
|
|
|
});
|
|
|
|
});
|