diff --git a/awx/ui_next/src/screens/User/User.jsx b/awx/ui_next/src/screens/User/User.jsx index e7bc917729..d2398846f9 100644 --- a/awx/ui_next/src/screens/User/User.jsx +++ b/awx/ui_next/src/screens/User/User.jsx @@ -9,7 +9,7 @@ import RoutedTabs from '@components/RoutedTabs'; import ContentError from '@components/ContentError'; import UserDetail from './UserDetail'; import UserEdit from './UserEdit'; -import UserOrganizationList from './UserOrganizationList'; +import UserOrganizations from './UserOrganizations'; import UserTeams from './UserTeams'; import UserTokens from './UserTokens'; import { UsersAPI } from '@api'; @@ -131,7 +131,7 @@ class User extends Component { /> )} - + - - - - - {organization.name} - - , - - {organization.description} - , - ]} - /> - - - - ); -} - -export default withI18n()(UserOrganizationListItem); diff --git a/awx/ui_next/src/screens/User/UserOrganizationListItem/index.js b/awx/ui_next/src/screens/User/UserOrganizationListItem/index.js deleted file mode 100644 index 0c9f42e2a7..0000000000 --- a/awx/ui_next/src/screens/User/UserOrganizationListItem/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from './UserOrganizationListItem'; diff --git a/awx/ui_next/src/screens/User/UserOrganizations/UserOrganizationListItem.test.jsx b/awx/ui_next/src/screens/User/UserOrganizations/UserOrganizationListItem.test.jsx new file mode 100644 index 0000000000..23622d6124 --- /dev/null +++ b/awx/ui_next/src/screens/User/UserOrganizations/UserOrganizationListItem.test.jsx @@ -0,0 +1,42 @@ +import React from 'react'; +import { act } from 'react-dom/test-utils'; +import { mountWithContexts } from '@testUtils/enzymeHelpers'; + +import UserOrganizationListItem from './UserOrganizationListItem'; + +describe('', () => { + test('mounts correctly', () => { + let wrapper; + act(() => { + wrapper = mountWithContexts( + + ); + }); + expect(wrapper.find('UserOrganizationListItem').length).toBe(1); + }); + test('render correct information', () => { + let wrapper; + act(() => { + wrapper = mountWithContexts( + + ); + }); + expect( + wrapper + .find('DataListCell') + .at(0) + .text() + ).toBe('foo'); + expect( + wrapper + .find('DataListCell') + .at(1) + .text() + ).toBe('Bar'); + expect(wrapper.find('Link').prop('to')).toBe('/organizations/1/details'); + }); +}); diff --git a/awx/ui_next/src/screens/User/UserOrganizations/UserOrganizations.jsx b/awx/ui_next/src/screens/User/UserOrganizations/UserOrganizations.jsx new file mode 100644 index 0000000000..1bd83ad2fa --- /dev/null +++ b/awx/ui_next/src/screens/User/UserOrganizations/UserOrganizations.jsx @@ -0,0 +1,7 @@ +import React from 'react'; +import UserOrganizationsList from './UserOrganizationsList'; + +function UserOrganizations() { + return ; +} +export default UserOrganizations; diff --git a/awx/ui_next/src/screens/User/UserOrganizations/UserOrganizations.test.jsx b/awx/ui_next/src/screens/User/UserOrganizations/UserOrganizations.test.jsx new file mode 100644 index 0000000000..e5093b07d0 --- /dev/null +++ b/awx/ui_next/src/screens/User/UserOrganizations/UserOrganizations.test.jsx @@ -0,0 +1,36 @@ +import React from 'react'; +import { Route } from 'react-router-dom'; +import { act } from 'react-dom/test-utils'; +import { createMemoryHistory } from 'history'; +import { mountWithContexts, waitForElement } from '@testUtils/enzymeHelpers'; + +import UserOrganizations from './UserOrganizations'; + +describe('', () => { + test('userOrganizations mounts successfully', () => { + const history = createMemoryHistory({ + initialEntries: ['/users/1/organizations'], + }); + let wrapper; + act(() => { + wrapper = mountWithContexts( + } + />, + { + context: { + router: { + history, + route: { + location: history.location, + match: { params: { id: 1 } }, + }, + }, + }, + } + ); + }); + waitForElement(wrapper, 'UserOrganizationList'); + }); +}); diff --git a/awx/ui_next/src/screens/User/UserOrganizationList/UserOrganizationList.jsx b/awx/ui_next/src/screens/User/UserOrganizations/UserOrganizationsList.jsx similarity index 91% rename from awx/ui_next/src/screens/User/UserOrganizationList/UserOrganizationList.jsx rename to awx/ui_next/src/screens/User/UserOrganizations/UserOrganizationsList.jsx index 042d90a32a..ce9a2042ad 100644 --- a/awx/ui_next/src/screens/User/UserOrganizationList/UserOrganizationList.jsx +++ b/awx/ui_next/src/screens/User/UserOrganizations/UserOrganizationsList.jsx @@ -7,7 +7,7 @@ import PaginatedDataList from '@components/PaginatedDataList'; import useRequest from '@util/useRequest'; import { UsersAPI } from '@api'; import { getQSConfig, parseQueryString } from '@util/qs'; -import UserOrganizationListItem from '../UserOrganizationListItem'; +import UserOrganizationListItem from './UserOrganizationListItem'; const QS_CONFIG = getQSConfig('organizations', { page: 1, @@ -16,7 +16,7 @@ const QS_CONFIG = getQSConfig('organizations', { type: 'organization', }); -function UserOrganizationList({ i18n }) { +function UserOrganizationsList({ i18n }) { const location = useLocation(); const { id: userId } = useParams(); @@ -68,4 +68,4 @@ function UserOrganizationList({ i18n }) { ); } -export default withI18n()(UserOrganizationList); +export default withI18n()(UserOrganizationsList); diff --git a/awx/ui_next/src/screens/User/UserOrganizations/UserOrganizationsList.test.jsx b/awx/ui_next/src/screens/User/UserOrganizations/UserOrganizationsList.test.jsx new file mode 100644 index 0000000000..11bdf96eac --- /dev/null +++ b/awx/ui_next/src/screens/User/UserOrganizations/UserOrganizationsList.test.jsx @@ -0,0 +1,66 @@ +import React from 'react'; +import { Route } from 'react-router-dom'; +import { act } from 'react-dom/test-utils'; +import { mountWithContexts, waitForElement } from '@testUtils/enzymeHelpers'; +import { createMemoryHistory } from 'history'; + +import UserOrganizationsList from './UserOrganizationsList'; +import { UsersAPI } from '@api'; + +jest.mock('@api/models/Users'); + +describe('', () => { + let history; + let wrapper; + beforeEach(async () => { + history = createMemoryHistory({ + initialEntries: ['/users/1/organizations'], + }); + UsersAPI.readOrganizations.mockResolvedValue({ + data: { + results: [ + { + name: 'Foo', + id: 1, + description: 'Bar', + url: '/api/v2/organizations/1/', + }, + ], + count: 1, + }, + }); + await act(async () => { + wrapper = mountWithContexts( + } + />, + { + context: { + router: { + history, + route: { + location: history.location, + match: { params: { id: 1 } }, + }, + }, + }, + } + ); + }); + }); + afterEach(() => { + jest.clearAllMocks(); + }); + test('successfully mounts', async () => { + await waitForElement(wrapper, 'UserOrganizationListItem'); + }); + test('calls api to get organizations', () => { + expect(UsersAPI.readOrganizations).toBeCalledWith('1', { + order_by: 'name', + page: 1, + page_size: 20, + type: 'organization', + }); + }); +}); diff --git a/awx/ui_next/src/screens/User/UserOrganizations/index.js b/awx/ui_next/src/screens/User/UserOrganizations/index.js new file mode 100644 index 0000000000..7fa3e0744b --- /dev/null +++ b/awx/ui_next/src/screens/User/UserOrganizations/index.js @@ -0,0 +1 @@ +export { default } from './UserOrganizations';