1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

Adds unit test coverage for add button rbac on several lists

This commit is contained in:
mabashian 2019-10-08 16:10:55 -04:00
parent d239d55d2a
commit f34bd632d8
3 changed files with 130 additions and 3 deletions

View File

@ -128,7 +128,10 @@ describe('<InventoriesList />', () => {
InventoriesAPI.readOptions.mockResolvedValue({
data: {
actions: [],
actions: {
GET: {},
POST: {},
},
},
});
});
@ -280,4 +283,43 @@ describe('<InventoriesList />', () => {
done();
});
test('Add button shown for users without ability to POST', async done => {
const wrapper = mountWithContexts(<InventoriesList />);
await waitForElement(
wrapper,
'InventoriesList',
el => el.state('hasContentLoading') === true
);
await waitForElement(
wrapper,
'InventoriesList',
el => el.state('hasContentLoading') === false
);
expect(wrapper.find('ToolbarAddButton').length).toBe(1);
done();
});
test('Add button hidden for users without ability to POST', async done => {
InventoriesAPI.readOptions.mockResolvedValue({
data: {
actions: {
GET: {},
},
},
});
const wrapper = mountWithContexts(<InventoriesList />);
await waitForElement(
wrapper,
'InventoriesList',
el => el.state('hasContentLoading') === true
);
await waitForElement(
wrapper,
'InventoriesList',
el => el.state('hasContentLoading') === false
);
expect(wrapper.find('ToolbarAddButton').length).toBe(0);
done();
});
});

View File

@ -73,7 +73,10 @@ describe('<OrganizationsList />', () => {
OrganizationsAPI.readOptions = () =>
Promise.resolve({
data: {
actions: [],
actions: {
GET: {},
POST: {},
},
},
});
});
@ -176,4 +179,44 @@ describe('<OrganizationsList />', () => {
);
done();
});
test('Add button shown for users without ability to POST', async done => {
wrapper = mountWithContexts(<OrganizationsList />);
await waitForElement(
wrapper,
'OrganizationsList',
el => el.state('hasContentLoading') === true
);
await waitForElement(
wrapper,
'OrganizationsList',
el => el.state('hasContentLoading') === false
);
expect(wrapper.find('ToolbarAddButton').length).toBe(1);
done();
});
test('Add button hidden for users without ability to POST', async done => {
OrganizationsAPI.readOptions = () =>
Promise.resolve({
data: {
actions: {
GET: {},
},
},
});
wrapper = mountWithContexts(<OrganizationsList />);
await waitForElement(
wrapper,
'OrganizationsList',
el => el.state('hasContentLoading') === true
);
await waitForElement(
wrapper,
'OrganizationsList',
el => el.state('hasContentLoading') === false
);
expect(wrapper.find('ToolbarAddButton').length).toBe(0);
done();
});
});

View File

@ -71,7 +71,10 @@ describe('<ProjectsList />', () => {
ProjectsAPI.readOptions.mockResolvedValue({
data: {
actions: [],
actions: {
GET: {},
POST: {},
},
},
});
});
@ -219,4 +222,43 @@ describe('<ProjectsList />', () => {
done();
});
test('Add button shown for users without ability to POST', async done => {
const wrapper = mountWithContexts(<ProjectsList />);
await waitForElement(
wrapper,
'ProjectsList',
el => el.state('hasContentLoading') === true
);
await waitForElement(
wrapper,
'ProjectsList',
el => el.state('hasContentLoading') === false
);
expect(wrapper.find('ToolbarAddButton').length).toBe(1);
done();
});
test('Add button hidden for users without ability to POST', async done => {
ProjectsAPI.readOptions.mockResolvedValue({
data: {
actions: {
GET: {},
},
},
});
const wrapper = mountWithContexts(<ProjectsList />);
await waitForElement(
wrapper,
'ProjectsList',
el => el.state('hasContentLoading') === true
);
await waitForElement(
wrapper,
'ProjectsList',
el => el.state('hasContentLoading') === false
);
expect(wrapper.find('ToolbarAddButton').length).toBe(0);
done();
});
});