mirror of
https://github.com/ansible/awx.git
synced 2026-05-14 04:47:44 -02:30
Fix for unit test failure in jt detail test where getting instance groups wasn't mocked (#296)
Fix for unit test failure in jt detail test where getting instance groups wasn't mocked.
This commit is contained in:
@@ -5,12 +5,12 @@ import { CardBody, Button, TextList, TextListItem, TextListItemVariants, TextLis
|
|||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
|
|
||||||
import ContentError from '../../../components/ContentError';
|
import ContentError from '@components/ContentError';
|
||||||
import ContentLoading from '../../../components/ContentLoading';
|
import ContentLoading from '@components/ContentLoading';
|
||||||
import { ChipGroup, Chip } from '../../../components/Chip';
|
import { ChipGroup, Chip } from '@components/Chip';
|
||||||
import { DetailList, Detail } from '../../../components/DetailList';
|
import { DetailList, Detail } from '@components/DetailList';
|
||||||
import { JobTemplatesAPI } from '../../../api';
|
import { JobTemplatesAPI } from '@api';
|
||||||
import { toTitleCase } from '../../../util/strings';
|
import { toTitleCase } from '@util/strings';
|
||||||
|
|
||||||
const ButtonGroup = styled.div`
|
const ButtonGroup = styled.div`
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { mountWithContexts, waitForElement } from '../../../../testUtils/enzymeHelpers';
|
import { mountWithContexts, waitForElement } from '@testUtils/enzymeHelpers';
|
||||||
import JobTemplateDetail, { _JobTemplateDetail } from './JobTemplateDetail';
|
import JobTemplateDetail, { _JobTemplateDetail } from './JobTemplateDetail';
|
||||||
|
import { JobTemplatesAPI } from '@api';
|
||||||
|
|
||||||
|
jest.mock('@api');
|
||||||
|
|
||||||
describe('<JobTemplateDetail />', () => {
|
describe('<JobTemplateDetail />', () => {
|
||||||
const template = {
|
const template = {
|
||||||
@@ -38,6 +41,14 @@ describe('<JobTemplateDetail />', () => {
|
|||||||
|
|
||||||
const readInstanceGroups = jest.spyOn(_JobTemplateDetail.prototype, 'readInstanceGroups');
|
const readInstanceGroups = jest.spyOn(_JobTemplateDetail.prototype, 'readInstanceGroups');
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
JobTemplatesAPI.readInstanceGroups.mockResolvedValue(mockInstanceGroups);
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
test('initially renders succesfully', () => {
|
test('initially renders succesfully', () => {
|
||||||
const wrapper = mountWithContexts(
|
const wrapper = mountWithContexts(
|
||||||
<JobTemplateDetail
|
<JobTemplateDetail
|
||||||
@@ -55,6 +66,7 @@ describe('<JobTemplateDetail />', () => {
|
|||||||
await waitForElement(wrapper, 'JobTemplateDetail', (el) => el.state('hasContentLoading') === true);
|
await waitForElement(wrapper, 'JobTemplateDetail', (el) => el.state('hasContentLoading') === true);
|
||||||
expect(readInstanceGroups).toHaveBeenCalled();
|
expect(readInstanceGroups).toHaveBeenCalled();
|
||||||
await waitForElement(wrapper, 'JobTemplateDetail', (el) => el.state('hasContentLoading') === false);
|
await waitForElement(wrapper, 'JobTemplateDetail', (el) => el.state('hasContentLoading') === false);
|
||||||
|
expect(JobTemplatesAPI.readInstanceGroups).toHaveBeenCalledTimes(1);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
test('Edit button is absent when user does not have edit privilege', async (done) => {
|
test('Edit button is absent when user does not have edit privilege', async (done) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user