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

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