mirror of
https://github.com/ansible/awx.git
synced 2026-08-05 12:30:02 -02:30
api.js refactor using classes (#250)
Refactor api.js into an api module where endpoint specific models can be imported and used in components.
This commit is contained in:
@@ -3,6 +3,9 @@ import { shallow } from 'enzyme';
|
||||
import { mountWithContexts } from '../../../../enzymeHelpers';
|
||||
import { sleep } from '../../../../testUtils';
|
||||
import OrganizationTeams, { _OrganizationTeams } from '../../../../../src/pages/Organizations/screens/Organization/OrganizationTeams';
|
||||
import { OrganizationsAPI } from '../../../../../src/api';
|
||||
|
||||
jest.mock('../../../../../src/api');
|
||||
|
||||
const listData = {
|
||||
data: {
|
||||
@@ -17,6 +20,14 @@ const listData = {
|
||||
}
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
OrganizationsAPI.readTeams.mockResolvedValue(listData);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('<OrganizationTeams />', () => {
|
||||
test('renders succesfully', () => {
|
||||
shallow(
|
||||
@@ -24,25 +35,21 @@ describe('<OrganizationTeams />', () => {
|
||||
id={1}
|
||||
searchString=""
|
||||
location={{ search: '', pathname: '/organizations/1/teams' }}
|
||||
api={{
|
||||
readOrganizationTeamsList: jest.fn(),
|
||||
}}
|
||||
handleHttpError={() => {}}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
test('should load teams on mount', () => {
|
||||
const readOrganizationTeamsList = jest.fn(() => Promise.resolve(listData));
|
||||
mountWithContexts(
|
||||
<OrganizationTeams
|
||||
id={1}
|
||||
searchString=""
|
||||
/>, { context: {
|
||||
network: { api: { readOrganizationTeamsList }, handleHttpError: () => {} } }
|
||||
network: {} }
|
||||
}
|
||||
).find('OrganizationTeams');
|
||||
expect(readOrganizationTeamsList).toHaveBeenCalledWith(1, {
|
||||
expect(OrganizationsAPI.readTeams).toHaveBeenCalledWith(1, {
|
||||
page: 1,
|
||||
page_size: 5,
|
||||
order_by: 'name',
|
||||
@@ -50,13 +57,12 @@ describe('<OrganizationTeams />', () => {
|
||||
});
|
||||
|
||||
test('should pass fetched teams to PaginatedDatalist', async () => {
|
||||
const readOrganizationTeamsList = jest.fn(() => Promise.resolve(listData));
|
||||
const wrapper = mountWithContexts(
|
||||
<OrganizationTeams
|
||||
id={1}
|
||||
searchString=""
|
||||
/>, { context: {
|
||||
network: { api: { readOrganizationTeamsList }, handleHttpError: () => {} } }
|
||||
network: { handleHttpError: () => {} } }
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user