2022-10-11 01:57:18 +05:30
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
2021-12-11 22:18:48 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
2022-01-26 12:08:38 +05:30
|
|
|
import VueRouter from 'vue-router';
|
2022-10-11 01:57:18 +05:30
|
|
|
import { mountExtended } from 'helpers/vue_test_utils_helper';
|
2021-12-11 22:18:48 +05:30
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2022-06-21 17:19:12 +05:30
|
|
|
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';
|
2022-10-11 01:57:18 +05:30
|
|
|
import getGroupOrganizationsCountByStateQuery from '~/crm/organizations/components/graphql/get_group_organizations_count_by_state.query.graphql';
|
|
|
|
import PaginatedTableWithSearchAndTabs from '~/vue_shared/components/paginated_table_with_search_and_tabs/paginated_table_with_search_and_tabs.vue';
|
|
|
|
import {
|
|
|
|
getGroupOrganizationsQueryResponse,
|
|
|
|
getGroupOrganizationsCountQueryResponse,
|
|
|
|
} from './mock_data';
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
describe('Customer relations organizations root app', () => {
|
|
|
|
Vue.use(VueApollo);
|
2022-01-26 12:08:38 +05:30
|
|
|
Vue.use(VueRouter);
|
2021-12-11 22:18:48 +05:30
|
|
|
let wrapper;
|
|
|
|
let fakeApollo;
|
2022-01-26 12:08:38 +05:30
|
|
|
let router;
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);
|
|
|
|
const findRowByName = (rowName) => wrapper.findAllByRole('row', { name: rowName });
|
2022-01-26 12:08:38 +05:30
|
|
|
const findIssuesLinks = () => wrapper.findAllByTestId('issues-link');
|
|
|
|
const findNewOrganizationButton = () => wrapper.findByTestId('new-organization-button');
|
2022-10-11 01:57:18 +05:30
|
|
|
const findTable = () => wrapper.findComponent(PaginatedTableWithSearchAndTabs);
|
2021-12-11 22:18:48 +05:30
|
|
|
const successQueryHandler = jest.fn().mockResolvedValue(getGroupOrganizationsQueryResponse);
|
2022-10-11 01:57:18 +05:30
|
|
|
const successCountQueryHandler = jest
|
|
|
|
.fn()
|
|
|
|
.mockResolvedValue(getGroupOrganizationsCountQueryResponse);
|
2021-12-11 22:18:48 +05:30
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
const basePath = '/groups/flightjs/-/crm/organizations';
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
const mountComponent = ({
|
|
|
|
queryHandler = successQueryHandler,
|
2022-10-11 01:57:18 +05:30
|
|
|
countQueryHandler = successCountQueryHandler,
|
2022-01-26 12:08:38 +05:30
|
|
|
canAdminCrmOrganization = true,
|
2022-10-11 01:57:18 +05:30
|
|
|
textQuery = null,
|
2021-12-11 22:18:48 +05:30
|
|
|
} = {}) => {
|
2022-10-11 01:57:18 +05:30
|
|
|
fakeApollo = createMockApollo([
|
|
|
|
[getGroupOrganizationsQuery, queryHandler],
|
|
|
|
[getGroupOrganizationsCountByStateQuery, countQueryHandler],
|
|
|
|
]);
|
|
|
|
wrapper = mountExtended(OrganizationsRoot, {
|
2022-01-26 12:08:38 +05:30
|
|
|
router,
|
2022-06-21 17:19:12 +05:30
|
|
|
provide: {
|
|
|
|
canAdminCrmOrganization,
|
|
|
|
groupFullPath: 'flightjs',
|
|
|
|
groupIssuesPath: '/issues',
|
2022-10-11 01:57:18 +05:30
|
|
|
textQuery,
|
2022-06-21 17:19:12 +05:30
|
|
|
},
|
2021-12-11 22:18:48 +05:30
|
|
|
apolloProvider: fakeApollo,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
router = new VueRouter({
|
|
|
|
base: basePath,
|
|
|
|
mode: 'history',
|
|
|
|
routes,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
afterEach(() => {
|
|
|
|
fakeApollo = null;
|
2022-01-26 12:08:38 +05:30
|
|
|
router = null;
|
2021-12-11 22:18:48 +05:30
|
|
|
});
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
it('should render table with default props and loading spinner', () => {
|
2021-12-11 22:18:48 +05:30
|
|
|
mountComponent();
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(findTable().props()).toMatchObject({
|
|
|
|
items: [],
|
|
|
|
itemsCount: {},
|
|
|
|
pageInfo: {},
|
|
|
|
statusTabs: [
|
|
|
|
{ title: 'Active', status: 'ACTIVE', filters: 'active' },
|
|
|
|
{ title: 'Inactive', status: 'INACTIVE', filters: 'inactive' },
|
|
|
|
{ title: 'All', status: 'ALL', filters: 'all' },
|
|
|
|
],
|
|
|
|
showItems: true,
|
|
|
|
showErrorMsg: false,
|
|
|
|
trackViewsOptions: { category: 'Customer Relations', action: 'view_organizations_list' },
|
|
|
|
i18n: {
|
|
|
|
emptyText: 'No organizations found',
|
|
|
|
issuesButtonLabel: 'View issues',
|
|
|
|
editButtonLabel: 'Edit',
|
|
|
|
title: 'Customer relations organizations',
|
|
|
|
newOrganization: 'New organization',
|
2022-11-25 23:54:43 +05:30
|
|
|
errorMsg: 'Something went wrong. Please try again.',
|
2022-10-11 01:57:18 +05:30
|
|
|
},
|
|
|
|
serverErrorMessage: '',
|
|
|
|
filterSearchKey: 'organizations',
|
|
|
|
filterSearchTokens: [],
|
|
|
|
});
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(findLoadingIcon().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
describe('error', () => {
|
|
|
|
it('should render on reject', async () => {
|
|
|
|
mountComponent({ queryHandler: jest.fn().mockRejectedValue('ERROR') });
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain('Something went wrong. Please try again.');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should be removed on error-alert-dismissed event', async () => {
|
|
|
|
mountComponent({ queryHandler: jest.fn().mockRejectedValue('ERROR') });
|
|
|
|
await waitForPromises();
|
2021-12-11 22:18:48 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(wrapper.text()).toContain('Something went wrong. Please try again.');
|
|
|
|
|
|
|
|
findTable().vm.$emit('error-alert-dismissed');
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(wrapper.text()).not.toContain('Something went wrong. Please try again.');
|
|
|
|
});
|
2021-12-11 22:18:48 +05:30
|
|
|
});
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
describe('on successful load', () => {
|
|
|
|
it('should not render error', async () => {
|
|
|
|
mountComponent();
|
|
|
|
await waitForPromises();
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(wrapper.text()).not.toContain('Something went wrong. Please try again.');
|
2022-01-26 12:08:38 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correct results', async () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
mountComponent();
|
2022-01-26 12:08:38 +05:30
|
|
|
await waitForPromises();
|
2021-12-11 22:18:48 +05:30
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
expect(findRowByName(/Test Inc/i)).toHaveLength(1);
|
|
|
|
expect(findRowByName(/VIP/i)).toHaveLength(1);
|
|
|
|
expect(findRowByName(/120/i)).toHaveLength(1);
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(findIssuesLinks()).toHaveLength(3);
|
|
|
|
|
|
|
|
const links = findIssuesLinks().wrappers.map((w) => w.attributes('href'));
|
|
|
|
expect(links).toEqual(
|
|
|
|
expect.arrayContaining([
|
|
|
|
'/issues?crm_organization_id=1',
|
|
|
|
'/issues?crm_organization_id=2',
|
|
|
|
'/issues?crm_organization_id=3',
|
|
|
|
]),
|
|
|
|
);
|
2022-01-26 12:08:38 +05:30
|
|
|
});
|
2021-12-11 22:18:48 +05:30
|
|
|
});
|
|
|
|
});
|