2021-12-07 00:14:07 +00:00
|
|
|
import { GlAlert, GlLoadingIcon } from '@gitlab/ui';
|
2021-11-16 00:11:15 +00:00
|
|
|
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 OrganizationsRoot from '~/crm/components/organizations_root.vue';
|
|
|
|
import getGroupOrganizationsQuery from '~/crm/components/queries/get_group_organizations.query.graphql';
|
|
|
|
import { getGroupOrganizationsQueryResponse } from './mock_data';
|
|
|
|
|
|
|
|
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 });
|
2021-12-07 00:14:07 +00:00
|
|
|
const findIssuesLinks = () => wrapper.findAllByTestId('issues-link');
|
|
|
|
const findError = () => wrapper.findComponent(GlAlert);
|
2021-11-16 00:11:15 +00:00
|
|
|
const successQueryHandler = jest.fn().mockResolvedValue(getGroupOrganizationsQueryResponse);
|
|
|
|
|
|
|
|
const mountComponent = ({
|
|
|
|
queryHandler = successQueryHandler,
|
|
|
|
mountFunction = shallowMountExtended,
|
|
|
|
} = {}) => {
|
|
|
|
fakeApollo = createMockApollo([[getGroupOrganizationsQuery, queryHandler]]);
|
|
|
|
wrapper = mountFunction(OrganizationsRoot, {
|
2021-12-07 00:14:07 +00:00
|
|
|
provide: { groupFullPath: 'flightjs', groupIssuesPath: '/issues' },
|
2021-11-16 00:11:15 +00:00
|
|
|
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();
|
|
|
|
|
2021-12-07 00:14:07 +00:00
|
|
|
expect(findError().exists()).toBe(true);
|
2021-11-16 00:11:15 +00: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);
|
2021-12-07 00:14:07 +00:00
|
|
|
|
|
|
|
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-11-16 00:11:15 +00:00
|
|
|
});
|
|
|
|
});
|