-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UIU-3021: add edit user roles accordion to user edit view (#2671)
Refs UIU-3021.
- Loading branch information
1 parent
a96ffd2
commit dbc37f0
Showing
9 changed files
with
199 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/components/EditSections/EditUserRoles/ EditUserRoles.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
|
||
import React from 'react'; | ||
import { cleanup } from '@folio/jest-config-stripes/testing-library/react'; | ||
import renderWithRouter from 'helpers/renderWithRouter'; | ||
import { | ||
useStripes, | ||
} from '@folio/stripes/core'; | ||
import EditUserRoles from './EditUserRoles'; | ||
|
||
import { useUserTenantRoles } from '../../../hooks'; | ||
|
||
jest.mock('../../../hooks', () => ({ | ||
...jest.requireActual('../../../hooks'), | ||
useUserTenantRoles: jest.fn(), | ||
})); | ||
|
||
jest.mock('@folio/stripes/core', () => ({ | ||
...jest.requireActual('@folio/stripes/core'), | ||
useStripes: jest.fn(), | ||
})); | ||
|
||
jest.unmock('@folio/stripes/components'); | ||
|
||
const STRIPES = { | ||
config: {}, | ||
hasPerm: jest.fn().mockReturnValue(true), | ||
okapi: { | ||
tenant: 'diku', | ||
}, | ||
user: { | ||
user: { | ||
consortium: {}, | ||
}, | ||
}, | ||
}; | ||
|
||
|
||
const renderEditRolesAccordion = () => renderWithRouter(<EditUserRoles accordionId="user-roles" />); | ||
|
||
describe('EditUserRoles Component', () => { | ||
beforeEach(() => { | ||
useStripes.mockClear().mockReturnValue(STRIPES); | ||
useUserTenantRoles.mockClear().mockReturnValue({ | ||
isFetching: false, | ||
userRoles: [{ id: '1', name: 'test role' }, | ||
{ id: '2', name: 'admin role' } | ||
] | ||
}); | ||
}); | ||
afterEach(cleanup); | ||
|
||
it('shows the list of user roles', () => { | ||
const { getByText } = renderEditRolesAccordion(); | ||
|
||
expect(getByText('test role')).toBeInTheDocument(); | ||
expect(getByText('admin role')).toBeInTheDocument(); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
src/components/EditSections/EditUserRoles/EditUserRoles.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from 'react'; | ||
import { Accordion, Headline, Badge, Row, Col, List, Button, Icon, Loading } from '@folio/stripes/components'; | ||
import { useIntl, FormattedMessage } from 'react-intl'; | ||
import { withRouter } from 'react-router'; | ||
import PropTypes from 'prop-types'; | ||
import { useStripes } from '@folio/stripes/core'; | ||
import { useUserTenantRoles } from '../../../hooks'; | ||
|
||
function EditUserRoles({ match, accordionId }) { | ||
const { okapi } = useStripes(); | ||
const intl = useIntl(); | ||
|
||
const userId = match.params.id; | ||
|
||
const { userRoles, isLoading } = useUserTenantRoles({ userId, tenantId: okapi.tenant }); | ||
|
||
const renderRoles = (role) => { | ||
return ( | ||
<li | ||
data-test-user-role={role.id} | ||
key={role.id} | ||
> | ||
{role.name} | ||
<Button | ||
buttonStyle="fieldControl" | ||
align="end" | ||
type="button" | ||
id={`clickable-remove-user-role-${role.id}`} | ||
aria-label={`${intl.formatMessage({ id:'ui-users.roles.deleteRole' })}: ${role.name}`} | ||
> | ||
<Icon icon="times-circle" /> | ||
</Button> | ||
</li> | ||
); | ||
}; | ||
|
||
return ( | ||
<Accordion | ||
label={<Headline size="large" tag="h3"><FormattedMessage id="ui-users.roles.userRoles" /></Headline>} | ||
id={accordionId} | ||
displayWhenClosed={isLoading ? <Loading /> : <Badge>{userRoles.length}</Badge>} | ||
> | ||
<Row> | ||
<Col xs={12}> | ||
<List | ||
items={userRoles} | ||
itemFormatter={renderRoles} | ||
isEmptyMessage={<FormattedMessage id="ui-users.roles.empty" />} | ||
/> | ||
</Col> | ||
<Button><FormattedMessage id="ui-users.roles.addRoles" /></Button> | ||
<Button><FormattedMessage id="ui-users.roles.unassignAllRoles" /></Button> | ||
</Row> | ||
</Accordion> | ||
); | ||
} | ||
|
||
EditUserRoles.propTypes = { | ||
match: PropTypes.shape({ params: { id: PropTypes.string } }), | ||
accordionId: PropTypes.string | ||
}; | ||
|
||
export default withRouter(EditUserRoles); |
58 changes: 58 additions & 0 deletions
58
src/components/EditSections/EditUserRoles/EditUserRoles.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
|
||
import React from 'react'; | ||
import { cleanup } from '@folio/jest-config-stripes/testing-library/react'; | ||
import renderWithRouter from 'helpers/renderWithRouter'; | ||
import { | ||
useStripes, | ||
} from '@folio/stripes/core'; | ||
import EditUserRoles from './EditUserRoles'; | ||
|
||
import { useUserTenantRoles } from '../../../hooks'; | ||
|
||
jest.mock('../../../hooks', () => ({ | ||
...jest.requireActual('../../../hooks'), | ||
useUserTenantRoles: jest.fn(), | ||
})); | ||
|
||
jest.mock('@folio/stripes/core', () => ({ | ||
...jest.requireActual('@folio/stripes/core'), | ||
useStripes: jest.fn(), | ||
})); | ||
|
||
jest.unmock('@folio/stripes/components'); | ||
|
||
const STRIPES = { | ||
config: {}, | ||
hasPerm: jest.fn().mockReturnValue(true), | ||
okapi: { | ||
tenant: 'diku', | ||
}, | ||
user: { | ||
user: { | ||
consortium: {}, | ||
}, | ||
}, | ||
}; | ||
|
||
|
||
const renderEditRolesAccordion = () => renderWithRouter(<EditUserRoles accordionId="user-roles" />); | ||
|
||
describe('EditUserRoles Component', () => { | ||
beforeEach(() => { | ||
useStripes.mockClear().mockReturnValue(STRIPES); | ||
useUserTenantRoles.mockClear().mockReturnValue({ | ||
isFetching: false, | ||
userRoles: [{ id: '1', name: 'test role' }, | ||
{ id: '2', name: 'admin role' } | ||
] | ||
}); | ||
}); | ||
afterEach(cleanup); | ||
|
||
it('shows the list of user roles', () => { | ||
const { getByText } = renderEditRolesAccordion(); | ||
|
||
expect(getByText('test role')).toBeInTheDocument(); | ||
expect(getByText('admin role')).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './EditUserRoles'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters