Skip to content

Commit

Permalink
fix eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-D-Akbar committed Jan 27, 2021
1 parent dd48d9f commit 4d72748
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 15 deletions.
77 changes: 77 additions & 0 deletions src/users/entitlements/EntitlementForm.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { mount } from 'enzyme';
import React from 'react';
import renderer from 'react-test-renderer';
import { checkProps } from '../../setupTest';
import EntitlementForm from './EntitlementForm';
import { DefaultProps } from './PropTypes';

describe('Entitlement Form', () => {
let props;
let wrapper;

beforeEach(() => {
props = {
entitlement: EntitlementDefaultProps,
changeHandler: jest.fn(),
closeHandler: jest.fn(),
forwardedRef: null,
};
wrapper = mount(<EntitlementForm {...props} />);
});

describe('Checking PropTypes', () => {
it('does not throw a warning', () => {
const propsError = checkProps(EntitlementForm, props);

expect(propsError).toBeUndefined();
});
it('does not throw error with undefined userIdentifier', () => {
delete props.userIdentifier;
const propsError = checkProps(UserSearch, props);

expect(propsError).toBeUndefined();
});
it('throw error with undefined search handler', () => {
const propsError = checkProps(UserSearch, {});

expect(propsError).not.toBeUndefined();
expect(propsError).toContain('Failed props type');
expect(propsError).toContain('searchHandler');
});
});

describe('renders correctly', () => {
it('with correct user identifier', () => {
expect(wrapper.find('input').prop('defaultValue')).toEqual(
props.userIdentifier,
);
});
it('with correct default user identifier', () => {
delete props.userIdentifier;
const userSearchwrapper = mount(<UserSearch {...props} />);

expect(userSearchwrapper.find('input').prop('defaultValue')).toEqual('');
});
it('with submit button', () => {
expect(wrapper.find('button')).toHaveLength(1);
expect(wrapper.find('button').text()).toEqual('Search');
});

it('when submit button is clicked', () => {
const searchProps = { userIdentifier: 'staff', searchHandler: jest.fn() };
const userSearchwrapper = mount(<UserSearch {...searchProps} />);

userSearchwrapper.find('button').simulate('click');

expect(searchProps.searchHandler).toHaveBeenCalledWith(
searchProps.userIdentifier,
);
});

it('matches snapshot', () => {
const tree = renderer.create(wrapper).toJSON();

expect(tree).toMatchSnapshot();
});
});
});
30 changes: 15 additions & 15 deletions src/users/entitlements/Entitlements.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export default function Entitlements({
label: 'Order', key: 'orderNumber', columnSortable: true, onSort: () => setSort('orderNumber'), width: 'col-3',
},
{
label: 'Actions', key: 'actions', columnSortable: true, onSort: () => {}, width: 'col-3',
label: 'Actions', key: 'actions', columnSortable: true, onSort: () => { }, width: 'col-3',
},
];

Expand All @@ -198,17 +198,17 @@ export default function Entitlements({
<section className="mb-3">
<div className="d-flex flex-row justify-content-between mb-2">
{!formType && (
<Button
type="button"
className="btn-outline-primary"
onClick={() => {
clearCourseSummary();
setUserEntitlement(undefined);
setFormType(CREATE);
}}
>
Create New Entitlement
</Button>
<Button
type="button"
className="btn-outline-primary"
onClick={() => {
clearCourseSummary();
setUserEntitlement(undefined);
setFormType(CREATE);
}}
>
Create New Entitlement
</Button>
)}
</div>
<TransitionReplace>
Expand All @@ -219,11 +219,11 @@ export default function Entitlements({
entitlement={userEntitlement}
formType={formType}
changeHandler={changeHandler}
submitHandler={() => {}}
submitHandler={() => { }}
closeHandler={() => setFormType(null)}
forwardedRef={formRef}
/>
) : (<React.Fragment key="nothing" />) }
) : (<React.Fragment key="nothing" />)}
</TransitionReplace>
<TransitionReplace>
{courseSummaryUUID !== null ? (
Expand All @@ -237,7 +237,7 @@ export default function Entitlements({
errors={courseSummaryErrors}
forwardedRef={summaryRef}
/>
) : (<React.Fragment key="nothing" />) }
) : (<React.Fragment key="nothing" />)}
</TransitionReplace>
<Collapsible title={`Entitlements (${tableData.length})`} defaultOpen={expanded}>
<Table
Expand Down

0 comments on commit 4d72748

Please sign in to comment.