debian-mirror-gitlab/spec/frontend/crm/organizations_root_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

111 lines
3.5 KiB
JavaScript
Raw Normal View History

2022-01-26 12:08:38 +05:30
import { GlAlert, 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';
2021-12-11 22:18:48 +05:30
import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper';
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';
2021-12-11 22:18:48 +05:30
import { getGroupOrganizationsQueryResponse } from './mock_data';
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');
const findError = () => wrapper.findComponent(GlAlert);
2021-12-11 22:18:48 +05:30
const successQueryHandler = jest.fn().mockResolvedValue(getGroupOrganizationsQueryResponse);
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,
mountFunction = shallowMountExtended,
2022-01-26 12:08:38 +05:30
canAdminCrmOrganization = true,
2021-12-11 22:18:48 +05:30
} = {}) => {
fakeApollo = createMockApollo([[getGroupOrganizationsQuery, queryHandler]]);
wrapper = mountFunction(OrganizationsRoot, {
2022-01-26 12:08:38 +05:30
router,
2022-06-21 17:19:12 +05:30
provide: {
canAdminCrmOrganization,
groupFullPath: 'flightjs',
groupIssuesPath: '/issues',
},
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(() => {
wrapper.destroy();
fakeApollo = null;
2022-01-26 12:08:38 +05:30
router = null;
2021-12-11 22:18:48 +05:30
});
it('should render loading spinner', () => {
mountComponent();
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);
});
});
2021-12-11 22:18:48 +05:30
it('should render error message on reject', async () => {
mountComponent({ queryHandler: jest.fn().mockRejectedValue('ERROR') });
await waitForPromises();
2022-01-26 12:08:38 +05:30
expect(findError().exists()).toBe(true);
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();
expect(findError().exists()).toBe(false);
});
it('renders correct results', async () => {
mountComponent({ mountFunction: mountExtended });
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);
const issueLink = findIssuesLinks().at(0);
expect(issueLink.exists()).toBe(true);
expect(issueLink.attributes('href')).toBe(
'/issues?scope=all&state=opened&crm_organization_id=2',
);
});
2021-12-11 22:18:48 +05:30
});
});