mirror of
https://github.com/ansible/awx.git
synced 2026-02-18 03:30:02 -03:30
Add remove role functionality.
This commit is contained in:
@@ -155,14 +155,14 @@ describe('APIClient (api.js)', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
test('disassociateInstanceGroup calls expected http method with expected data', async (done) => {
|
||||
test('disassociate calls expected http method with expected data', async (done) => {
|
||||
const createPromise = () => Promise.resolve();
|
||||
const mockHttp = ({ post: jest.fn(createPromise) });
|
||||
|
||||
const api = new APIClient(mockHttp);
|
||||
const url = 'foo/bar/';
|
||||
const id = 1;
|
||||
await api.disassociateInstanceGroup(url, id);
|
||||
await api.disassociate(url, id);
|
||||
|
||||
expect(mockHttp.post).toHaveBeenCalledTimes(1);
|
||||
expect(mockHttp.post.mock.calls[0][0]).toEqual(url);
|
||||
|
||||
@@ -34,6 +34,7 @@ describe('<AccessList />', () => {
|
||||
match={{ path: '/organizations/:id', url: '/organizations/1', params: { id: '1' } }}
|
||||
location={{ search: '', pathname: '/organizations/1/access' }}
|
||||
getAccessList={() => {}}
|
||||
removeRole={() => {}}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
@@ -48,6 +49,7 @@ describe('<AccessList />', () => {
|
||||
match={{ path: '/organizations/:id', url: '/organizations/1', params: { id: '0' } }}
|
||||
location={{ search: '', pathname: '/organizations/1/access' }}
|
||||
getAccessList={() => ({ data: { count: 1, results: mockResults } })}
|
||||
removeRole={() => {}}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
@@ -69,6 +71,7 @@ describe('<AccessList />', () => {
|
||||
match={{ path: '/organizations/:id', url: '/organizations/1', params: { id: '0' } }}
|
||||
location={{ search: '', pathname: '/organizations/1/access' }}
|
||||
getAccessList={() => ({ data: { count: 1, results: mockResults } })}
|
||||
removeRole={() => {}}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
@@ -95,6 +98,7 @@ describe('<AccessList />', () => {
|
||||
match={{ path: '/organizations/:id', url: '/organizations/1', params: { id: '0' } }}
|
||||
location={{ search: '', pathname: '/organizations/1/access' }}
|
||||
getAccessList={() => ({ data: { count: 1, results: mockResults } })}
|
||||
removeRole={() => {}}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
@@ -144,6 +148,7 @@ describe('<AccessList />', () => {
|
||||
match={{ path: '/organizations/:id', url: '/organizations/1', params: { id: '0' } }}
|
||||
location={{ search: '', pathname: '/organizations/1/access' }}
|
||||
getAccessList={() => ({ data: { count: 1, results: mockData } })}
|
||||
removeRole={() => {}}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
@@ -157,4 +162,36 @@ describe('<AccessList />', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('test handleWarning, confirmDelete, and removeRole methods for Alert component', async (done) => {
|
||||
const handleWarning = jest.spyOn(AccessList.prototype, 'handleWarning');
|
||||
const confirmDelete = jest.spyOn(AccessList.prototype, 'confirmDelete');
|
||||
const removeRole = jest.spyOn(AccessList.prototype, 'removeRole');
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
<MemoryRouter>
|
||||
<AccessList
|
||||
match={{ path: '/organizations/:id', url: '/organizations/1', params: { id: '0' } }}
|
||||
location={{ search: '', pathname: '/organizations/1/access' }}
|
||||
getAccessList={() => ({ data: { count: 1, results: mockResults } })}
|
||||
removeRole={() => {}}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</I18nProvider>
|
||||
).find('AccessList');
|
||||
expect(handleWarning).not.toHaveBeenCalled();
|
||||
expect(confirmDelete).not.toHaveBeenCalled();
|
||||
expect(removeRole).not.toHaveBeenCalled();
|
||||
|
||||
setImmediate(() => {
|
||||
const rendered = wrapper.update().find('ChipButton');
|
||||
rendered.find('button[aria-label="close"]').simulate('click');
|
||||
expect(handleWarning).toHaveBeenCalled();
|
||||
const alert = wrapper.update().find('Alert');
|
||||
alert.find('button[aria-label="confirm-delete"]').simulate('click');
|
||||
expect(confirmDelete).toHaveBeenCalled();
|
||||
expect(removeRole).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,6 +12,14 @@ const mockGetOrganzationAccessList = jest.fn(() => (
|
||||
Promise.resolve(mockAPIAccessList)
|
||||
));
|
||||
|
||||
const mockResponse = {
|
||||
status: 'success',
|
||||
};
|
||||
|
||||
const mockRemoveRole = jest.fn(() => (
|
||||
Promise.resolve(mockResponse)
|
||||
));
|
||||
|
||||
describe('<OrganizationAccess />', () => {
|
||||
test('initially renders succesfully', () => {
|
||||
mount(
|
||||
@@ -37,11 +45,14 @@ describe('<OrganizationAccess />', () => {
|
||||
params={{}}
|
||||
api={{
|
||||
getOrganzationAccessList: mockGetOrganzationAccessList,
|
||||
disassociate: mockRemoveRole
|
||||
}}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
).find('OrganizationAccess');
|
||||
const accessList = await wrapper.instance().getOrgAccessList();
|
||||
expect(accessList).toEqual(mockAPIAccessList);
|
||||
const resp = await wrapper.instance().removeRole(2, 3, 'users');
|
||||
expect(resp).toEqual(mockResponse);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -183,7 +183,7 @@ describe('<OrganizationEdit />', () => {
|
||||
getOrganizationInstanceGroups: getOrganizationInstanceGroupsFn,
|
||||
updateOrganizationDetails: updateOrganizationDetailsFn,
|
||||
associateInstanceGroup: associateInstanceGroupFn,
|
||||
disassociateInstanceGroup: disassociateInstanceGroupFn
|
||||
disassociate: disassociateInstanceGroupFn
|
||||
};
|
||||
const wrapper = mount(
|
||||
<I18nProvider>
|
||||
|
||||
Reference in New Issue
Block a user