Add remove role functionality.

This commit is contained in:
Kia Lam
2019-03-08 13:56:27 -05:00
parent e935776067
commit 3b65068258
11 changed files with 202 additions and 46 deletions

View File

@@ -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);

View File

@@ -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();
});
});
});

View File

@@ -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);
});
});

View File

@@ -183,7 +183,7 @@ describe('<OrganizationEdit />', () => {
getOrganizationInstanceGroups: getOrganizationInstanceGroupsFn,
updateOrganizationDetails: updateOrganizationDetailsFn,
associateInstanceGroup: associateInstanceGroupFn,
disassociateInstanceGroup: disassociateInstanceGroupFn
disassociate: disassociateInstanceGroupFn
};
const wrapper = mount(
<I18nProvider>