mirror of
https://github.com/ansible/awx.git
synced 2026-02-28 00:08:44 -03:30
Merge pull request #183 from jakemcdermott/test-fixup
fix unit and functional tests
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
exports[`<NotificationListItem /> initially renders succesfully 1`] = `
|
exports[`<NotificationListItem canToggleNotifications /> initially renders succesfully 1`] = `
|
||||||
<NotificationListItem
|
<NotificationListItem
|
||||||
canToggleNotifications={true}
|
canToggleNotifications={true}
|
||||||
detailUrl="/foo"
|
detailUrl="/foo"
|
||||||
@@ -184,186 +184,3 @@ exports[`<NotificationListItem /> initially renders succesfully 1`] = `
|
|||||||
</I18n>
|
</I18n>
|
||||||
</NotificationListItem>
|
</NotificationListItem>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`<NotificationListItem canToggleNotifications /> initially renders succesfully 1`] = `
|
|
||||||
<NotificationListItem
|
|
||||||
canToggleNotifications={true}
|
|
||||||
detailUrl="/foo"
|
|
||||||
errorTurnedOn={false}
|
|
||||||
notification={
|
|
||||||
Object {
|
|
||||||
"id": 9000,
|
|
||||||
"name": "Foo",
|
|
||||||
"notification_type": "slack",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
successTurnedOn={false}
|
|
||||||
toggleNotification={[MockFunction]}
|
|
||||||
>
|
|
||||||
<I18n
|
|
||||||
update={true}
|
|
||||||
withHash={true}
|
|
||||||
>
|
|
||||||
<DataListItem
|
|
||||||
aria-labelledby="items-list-item-9000"
|
|
||||||
className=""
|
|
||||||
isExpanded={false}
|
|
||||||
key="9000"
|
|
||||||
>
|
|
||||||
<li
|
|
||||||
aria-labelledby="items-list-item-9000"
|
|
||||||
className="pf-c-data-list__item"
|
|
||||||
>
|
|
||||||
<DataListCell
|
|
||||||
className=""
|
|
||||||
key=".0"
|
|
||||||
rowid="items-list-item-9000"
|
|
||||||
width={1}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className="pf-c-data-list__cell"
|
|
||||||
>
|
|
||||||
<Link
|
|
||||||
replace={false}
|
|
||||||
style={
|
|
||||||
Object {
|
|
||||||
"marginRight": "1.5em",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
to={
|
|
||||||
Object {
|
|
||||||
"pathname": "/foo",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
onClick={[Function]}
|
|
||||||
style={
|
|
||||||
Object {
|
|
||||||
"marginRight": "1.5em",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<b>
|
|
||||||
Foo
|
|
||||||
</b>
|
|
||||||
</a>
|
|
||||||
</Link>
|
|
||||||
<Badge
|
|
||||||
className=""
|
|
||||||
isRead={true}
|
|
||||||
style={
|
|
||||||
Object {
|
|
||||||
"textTransform": "capitalize",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
className="pf-c-badge pf-m-read"
|
|
||||||
style={
|
|
||||||
Object {
|
|
||||||
"textTransform": "capitalize",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
>
|
|
||||||
slack
|
|
||||||
</span>
|
|
||||||
</Badge>
|
|
||||||
</div>
|
|
||||||
</DataListCell>
|
|
||||||
<DataListCell
|
|
||||||
alignRight={true}
|
|
||||||
className=""
|
|
||||||
key=".1"
|
|
||||||
rowid="items-list-item-9000"
|
|
||||||
width={1}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
alignRight={true}
|
|
||||||
className="pf-c-data-list__cell"
|
|
||||||
>
|
|
||||||
<Switch
|
|
||||||
aria-label="Toggle notification success"
|
|
||||||
className=""
|
|
||||||
id="notification-9000-success-toggle"
|
|
||||||
isChecked={false}
|
|
||||||
isDisabled={false}
|
|
||||||
label="Successful"
|
|
||||||
onChange={[Function]}
|
|
||||||
>
|
|
||||||
<label
|
|
||||||
className="pf-c-switch"
|
|
||||||
htmlFor="notification-9000-success-toggle"
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
aria-label="Toggle notification success"
|
|
||||||
checked={false}
|
|
||||||
className="pf-c-switch__input"
|
|
||||||
disabled={false}
|
|
||||||
id="notification-9000-success-toggle"
|
|
||||||
onChange={[Function]}
|
|
||||||
type="checkbox"
|
|
||||||
/>
|
|
||||||
<span
|
|
||||||
className="pf-c-switch__toggle"
|
|
||||||
/>
|
|
||||||
<span
|
|
||||||
aria-hidden="true"
|
|
||||||
className="pf-c-switch__label pf-m-on"
|
|
||||||
>
|
|
||||||
Successful
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
aria-hidden="true"
|
|
||||||
className="pf-c-switch__label pf-m-off"
|
|
||||||
>
|
|
||||||
Successful
|
|
||||||
</span>
|
|
||||||
</label>
|
|
||||||
</Switch>
|
|
||||||
<Switch
|
|
||||||
aria-label="Toggle notification failure"
|
|
||||||
className=""
|
|
||||||
id="notification-9000-error-toggle"
|
|
||||||
isChecked={false}
|
|
||||||
isDisabled={false}
|
|
||||||
label="Failure"
|
|
||||||
onChange={[Function]}
|
|
||||||
>
|
|
||||||
<label
|
|
||||||
className="pf-c-switch"
|
|
||||||
htmlFor="notification-9000-error-toggle"
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
aria-label="Toggle notification failure"
|
|
||||||
checked={false}
|
|
||||||
className="pf-c-switch__input"
|
|
||||||
disabled={false}
|
|
||||||
id="notification-9000-error-toggle"
|
|
||||||
onChange={[Function]}
|
|
||||||
type="checkbox"
|
|
||||||
/>
|
|
||||||
<span
|
|
||||||
className="pf-c-switch__toggle"
|
|
||||||
/>
|
|
||||||
<span
|
|
||||||
aria-hidden="true"
|
|
||||||
className="pf-c-switch__label pf-m-on"
|
|
||||||
>
|
|
||||||
Failure
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
aria-hidden="true"
|
|
||||||
className="pf-c-switch__label pf-m-off"
|
|
||||||
>
|
|
||||||
Failure
|
|
||||||
</span>
|
|
||||||
</label>
|
|
||||||
</Switch>
|
|
||||||
</div>
|
|
||||||
</DataListCell>
|
|
||||||
</li>
|
|
||||||
</DataListItem>
|
|
||||||
</I18n>
|
|
||||||
</NotificationListItem>
|
|
||||||
`;
|
|
||||||
|
|||||||
@@ -1,205 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
|
|
||||||
import { mountWithContexts } from '../../../enzymeHelpers';
|
|
||||||
import OrganizationAccessList, { _OrganizationAccessList } from '../../../../src/pages/Organizations/components/OrganizationAccessList';
|
|
||||||
|
|
||||||
const mockData = [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
username: 'boo',
|
|
||||||
url: '/foo/bar/',
|
|
||||||
first_name: 'john',
|
|
||||||
last_name: 'smith',
|
|
||||||
summary_fields: {
|
|
||||||
foo: [
|
|
||||||
{
|
|
||||||
role: {
|
|
||||||
name: 'foo',
|
|
||||||
id: 2,
|
|
||||||
user_capabilities: {
|
|
||||||
unattach: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
const organization = {
|
|
||||||
id: 1,
|
|
||||||
name: 'Default',
|
|
||||||
summary_fields: {
|
|
||||||
object_roles: {},
|
|
||||||
user_capabilities: {
|
|
||||||
edit: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const api = {
|
|
||||||
foo: () => {}
|
|
||||||
};
|
|
||||||
|
|
||||||
describe('<OrganizationAccessList />', () => {
|
|
||||||
afterEach(() => {
|
|
||||||
jest.restoreAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('initially renders succesfully', () => {
|
|
||||||
mountWithContexts(
|
|
||||||
<OrganizationAccessList
|
|
||||||
getAccessList={() => {}}
|
|
||||||
removeRole={() => {}}
|
|
||||||
organization={organization}
|
|
||||||
/>, { context: { network: { api } } }
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('api response data passed to component gets set to state properly', (done) => {
|
|
||||||
const wrapper = mountWithContexts(
|
|
||||||
<OrganizationAccessList
|
|
||||||
getAccessList={() => ({ data: { count: 1, results: mockData } })}
|
|
||||||
removeRole={() => {}}
|
|
||||||
organization={organization}
|
|
||||||
/>, { context: { network: { api } } }
|
|
||||||
).find('OrganizationAccessList');
|
|
||||||
|
|
||||||
setImmediate(() => {
|
|
||||||
expect(wrapper.state().results).toEqual(mockData);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('onSort being passed properly to DataListToolbar component', async (done) => {
|
|
||||||
const onSort = jest.spyOn(_OrganizationAccessList.prototype, 'onSort');
|
|
||||||
const wrapper = mountWithContexts(
|
|
||||||
<OrganizationAccessList
|
|
||||||
getAccessList={() => ({ data: { count: 1, results: mockData } })}
|
|
||||||
removeRole={() => {}}
|
|
||||||
organization={organization}
|
|
||||||
/>, { context: { network: { api } } }
|
|
||||||
).find('OrganizationAccessList');
|
|
||||||
expect(onSort).not.toHaveBeenCalled();
|
|
||||||
|
|
||||||
setImmediate(() => {
|
|
||||||
const rendered = wrapper.update();
|
|
||||||
rendered.find('button[aria-label="Sort"]').simulate('click');
|
|
||||||
expect(onSort).toHaveBeenCalled();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('getTeamRoles returns empty array if dataset is missing team_id attribute', (done) => {
|
|
||||||
const wrapper = mountWithContexts(
|
|
||||||
<OrganizationAccessList
|
|
||||||
getAccessList={() => ({ data: { count: 1, results: mockData } })}
|
|
||||||
removeRole={() => {}}
|
|
||||||
organization={organization}
|
|
||||||
/>, { context: { network: { api } } }
|
|
||||||
).find('OrganizationAccessList');
|
|
||||||
|
|
||||||
setImmediate(() => {
|
|
||||||
const { results } = wrapper.state();
|
|
||||||
results.forEach(result => {
|
|
||||||
expect(result.teamRoles).toEqual([]);
|
|
||||||
});
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('test handleWarning, confirmDelete, and removeRole methods for Alert component', (done) => {
|
|
||||||
const handleWarning = jest.spyOn(_OrganizationAccessList.prototype, 'handleWarning');
|
|
||||||
const confirmDelete = jest.spyOn(_OrganizationAccessList.prototype, 'confirmDelete');
|
|
||||||
const removeRole = jest.spyOn(_OrganizationAccessList.prototype, 'removeAccessRole');
|
|
||||||
const wrapper = mountWithContexts(
|
|
||||||
<OrganizationAccessList
|
|
||||||
getAccessList={() => ({ data: { count: 1, results: mockData } })}
|
|
||||||
removeRole={() => {}}
|
|
||||||
organization={organization}
|
|
||||||
/>, { context: { network: { api } } }
|
|
||||||
).find('OrganizationAccessList');
|
|
||||||
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 alertModal = wrapper.update().find('Modal');
|
|
||||||
alertModal.find('button[aria-label="Confirm delete"]').simulate('click');
|
|
||||||
expect(confirmDelete).toHaveBeenCalled();
|
|
||||||
expect(removeRole).toHaveBeenCalled();
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('state is set appropriately when a user tries deleting a role', (done) => {
|
|
||||||
const wrapper = mountWithContexts(
|
|
||||||
<OrganizationAccessList
|
|
||||||
getAccessList={() => ({ data: { count: 1, results: mockData } })}
|
|
||||||
removeRole={() => {}}
|
|
||||||
organization={organization}
|
|
||||||
/>, { context: { network: { api } } }
|
|
||||||
).find('OrganizationAccessList');
|
|
||||||
|
|
||||||
setImmediate(() => {
|
|
||||||
const expected = [
|
|
||||||
{
|
|
||||||
deleteType: 'users'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
deleteRoleId: mockData[0].summary_fields.foo[0].role.id
|
|
||||||
},
|
|
||||||
{
|
|
||||||
deleteResourceId: mockData[0].id
|
|
||||||
}
|
|
||||||
];
|
|
||||||
const rendered = wrapper.update().find('ChipButton');
|
|
||||||
rendered.find('button[aria-label="close"]').simulate('click');
|
|
||||||
const alertModal = wrapper.update().find('Modal');
|
|
||||||
alertModal.find('button[aria-label="Confirm delete"]').simulate('click');
|
|
||||||
expect(wrapper.state().warningTitle).not.toBe(null);
|
|
||||||
expect(wrapper.state().warningMsg).not.toBe(null);
|
|
||||||
expected.forEach(criteria => {
|
|
||||||
Object.keys(criteria).forEach(key => {
|
|
||||||
expect(wrapper.state()[key]).toEqual(criteria[key]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('add role button visible for user that can edit org', () => {
|
|
||||||
const wrapper = mountWithContexts(
|
|
||||||
<OrganizationAccessList
|
|
||||||
getAccessList={() => ({ data: { count: 1, results: mockData } })}
|
|
||||||
removeRole={() => {}}
|
|
||||||
organization={organization}
|
|
||||||
/>, { context: { network: { api } } }
|
|
||||||
).find('OrganizationAccessList');
|
|
||||||
|
|
||||||
setImmediate(() => {
|
|
||||||
const addRole = wrapper.update().find('DataListToolbar').find('PlusIcon');
|
|
||||||
expect(addRole.length).toBe(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('add role button hidden for user that cannot edit org', () => {
|
|
||||||
const readOnlyOrg = { ...organization };
|
|
||||||
readOnlyOrg.summary_fields.user_capabilities.edit = false;
|
|
||||||
const wrapper = mountWithContexts(
|
|
||||||
<OrganizationAccessList
|
|
||||||
getAccessList={() => ({ data: { count: 1, results: mockData } })}
|
|
||||||
removeRole={() => {}}
|
|
||||||
organization={readOnlyOrg}
|
|
||||||
/>, { context: { network: { api } } }
|
|
||||||
).find('OrganizationAccessList');
|
|
||||||
|
|
||||||
setImmediate(() => {
|
|
||||||
const addRole = wrapper.update().find('DataListToolbar').find('PlusIcon');
|
|
||||||
expect(addRole.length).toBe(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -7,7 +7,13 @@ describe('<OrganizationAccess />', () => {
|
|||||||
let network;
|
let network;
|
||||||
const organization = {
|
const organization = {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 'Default'
|
name: 'Default',
|
||||||
|
summary_fields: {
|
||||||
|
object_roles: {},
|
||||||
|
user_capabilities: {
|
||||||
|
edit: true
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
|
|||||||
@@ -26,6 +26,12 @@ exports[`<OrganizationAccess /> initially renders succesfully 1`] = `
|
|||||||
Object {
|
Object {
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"name": "Default",
|
"name": "Default",
|
||||||
|
"summary_fields": Object {
|
||||||
|
"object_roles": Object {},
|
||||||
|
"user_capabilities": Object {
|
||||||
|
"edit": true,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -76,10 +76,10 @@ function NotificationListItem (props) {
|
|||||||
NotificationListItem.propTypes = {
|
NotificationListItem.propTypes = {
|
||||||
notification: shape({
|
notification: shape({
|
||||||
id: number.isRequired,
|
id: number.isRequired,
|
||||||
canToggleNotifications: bool.isRequired,
|
|
||||||
name: string.isRequired,
|
name: string.isRequired,
|
||||||
notification_type: string.isRequired,
|
notification_type: string.isRequired,
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
|
canToggleNotifications: bool.isRequired,
|
||||||
detailUrl: string.isRequired,
|
detailUrl: string.isRequired,
|
||||||
errorTurnedOn: bool,
|
errorTurnedOn: bool,
|
||||||
successTurnedOn: bool,
|
successTurnedOn: bool,
|
||||||
|
|||||||
Reference in New Issue
Block a user