-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add basic tests for SharingDialog widget/components
- Loading branch information
Showing
6 changed files
with
454 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
packages/widgets/src/SharingDialog/__tests__/ShareBlock.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,46 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
|
||
import { Button } from '../../../../core' | ||
import { ShareBlock } from '../ShareBlock' | ||
import { Autocomplete } from '../Autocomplete/Autocomplete' | ||
import { AccessSelect } from '../AccessSelect' | ||
|
||
describe('SharingDialog widget - ShareBlock component', () => { | ||
let shallowShareBlockComponent | ||
let props | ||
|
||
const onAdd = jest.fn() | ||
|
||
const getShareBlockComponent = props => { | ||
if (!shallowShareBlockComponent) { | ||
shallowShareBlockComponent = shallow(<ShareBlock {...props} />) | ||
} | ||
|
||
return shallowShareBlockComponent | ||
} | ||
|
||
beforeEach(() => { | ||
shallowShareBlockComponent = undefined | ||
props = { | ||
onAdd, | ||
} | ||
}) | ||
|
||
it('renders the Autocomplete component ', () => | ||
expect(getShareBlockComponent(props).find(Autocomplete)).toHaveLength( | ||
1 | ||
)) | ||
|
||
it('renders the AccessSelect component', () => | ||
expect(getShareBlockComponent(props).find(AccessSelect)).toHaveLength( | ||
1 | ||
)) | ||
|
||
it('renders the Give access button', () => { | ||
const button = getShareBlockComponent(props).find(Button) | ||
|
||
expect(button).toHaveLength(1) | ||
expect(button.html()).toMatch('Give access') | ||
}) | ||
}) |
72 changes: 72 additions & 0 deletions
72
packages/widgets/src/SharingDialog/__tests__/SharingDialog.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,72 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
|
||
import { Button, Modal, ModalTitle } from '../../../../core' | ||
import { SharingDialog } from '../SharingDialog' | ||
import { ShareBlock } from '../ShareBlock' | ||
import { SharingList } from '../SharingList' | ||
import { defaultSharingSettings } from '../sharingConstants' | ||
|
||
describe('SharingDialog widget', () => { | ||
const onClose = jest.fn() | ||
const onSave = jest.fn() | ||
const onError = jest.fn() | ||
|
||
let shallowSharingDialog | ||
let props | ||
|
||
const getSharingDialogWidget = props => { | ||
if (!shallowSharingDialog) { | ||
shallowSharingDialog = shallow(<SharingDialog {...props} />) | ||
} | ||
|
||
return shallowSharingDialog | ||
} | ||
|
||
beforeEach(() => { | ||
shallowSharingDialog = undefined | ||
props = { | ||
type: 'dashboard', | ||
onClose, | ||
onError, | ||
onSave, | ||
} | ||
}) | ||
|
||
it('renders a Modal', () => | ||
expect(getSharingDialogWidget(props).find(Modal)).toHaveLength(1)) | ||
|
||
it('renders the ModalTitle with the name of the AO if passed in props', () => { | ||
props.initialSharingSettings = { | ||
...defaultSharingSettings, | ||
name: 'test object', | ||
} | ||
|
||
expect( | ||
getSharingDialogWidget(props) | ||
.find(ModalTitle) | ||
.html() | ||
).toMatch(props.initialSharingSettings.name) | ||
}) | ||
|
||
it('renders a ShareBlock component', () => | ||
expect(getSharingDialogWidget(props).find(ShareBlock)).toHaveLength(1)) | ||
|
||
it('renders a SharingList component', () => | ||
expect(getSharingDialogWidget(props).find(SharingList)).toHaveLength(1)) | ||
|
||
it('renders a Close button', () => { | ||
const button = getSharingDialogWidget(props).find(Button) | ||
|
||
expect(button).toHaveLength(1) | ||
expect(button.html()).toMatch('Close') | ||
}) | ||
|
||
it('calls the Close callback when the Close button is clicked', () => { | ||
const button = getSharingDialogWidget(props).find(Button) | ||
|
||
button.simulate('click') | ||
|
||
expect(onClose).toHaveBeenCalled() | ||
}) | ||
}) |
104 changes: 104 additions & 0 deletions
104
packages/widgets/src/SharingDialog/__tests__/SharingList.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,104 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
|
||
import { SharingList } from '../SharingList' | ||
import { | ||
SHARE_TARGET_EXTERNAL, | ||
SHARE_TARGET_PUBLIC, | ||
SHARE_TARGET_GROUP, | ||
SHARE_TARGET_USER, | ||
defaultSharingSettings, | ||
} from '../sharingConstants' | ||
|
||
describe('SharingDialog widget - SharingList component', () => { | ||
let shallowSharingListComponent | ||
let props | ||
|
||
const onChange = jest.fn() | ||
const onRemove = jest.fn() | ||
|
||
const getSharingListComponent = props => { | ||
if (!shallowSharingListComponent) { | ||
shallowSharingListComponent = shallow(<SharingList {...props} />) | ||
} | ||
|
||
return shallowSharingListComponent | ||
} | ||
|
||
beforeEach(() => { | ||
shallowSharingListComponent = undefined | ||
props = { | ||
sharingSettings: defaultSharingSettings, | ||
onChange, | ||
onRemove, | ||
} | ||
}) | ||
|
||
it('renders a SharingListItem for external access', () => { | ||
const external = getSharingListComponent(props).findWhere( | ||
n => n.prop('target') === SHARE_TARGET_EXTERNAL | ||
) | ||
|
||
expect(external).toHaveLength(1) | ||
expect(external.prop('name')).toEqual('External users') | ||
expect(external.prop('access')).toEqual(defaultSharingSettings.external) | ||
}) | ||
|
||
it('renders a SharingListItem for public access', () => { | ||
const external = getSharingListComponent(props).findWhere( | ||
n => n.prop('target') === SHARE_TARGET_PUBLIC | ||
) | ||
|
||
expect(external).toHaveLength(1) | ||
expect(external.prop('name')).toEqual('All users') | ||
expect(external.prop('access')).toEqual(defaultSharingSettings.public) | ||
}) | ||
|
||
it('renders a SharingListItem for a user group access', () => { | ||
const groupId = 'test-group-id' | ||
|
||
props.sharingSettings.groups = { | ||
[groupId]: { | ||
id: groupId, | ||
name: 'Test group', | ||
access: 'r-------', | ||
}, | ||
} | ||
|
||
const group = getSharingListComponent(props).findWhere( | ||
n => n.prop('target') === SHARE_TARGET_GROUP | ||
) | ||
|
||
expect(group).toHaveLength(1) | ||
expect(group.prop('name')).toEqual( | ||
props.sharingSettings.groups[groupId].name | ||
) | ||
expect(group.prop('access')).toEqual( | ||
props.sharingSettings.groups[groupId].access | ||
) | ||
}) | ||
|
||
it('renders a SharingListItem for a user access', () => { | ||
const userId = 'test-user-id' | ||
|
||
props.sharingSettings.users = { | ||
[userId]: { | ||
id: userId, | ||
name: 'User group', | ||
access: 'rw------', | ||
}, | ||
} | ||
|
||
const user = getSharingListComponent(props).findWhere( | ||
n => n.prop('target') === SHARE_TARGET_USER | ||
) | ||
|
||
expect(user).toHaveLength(1) | ||
expect(user.prop('name')).toEqual( | ||
props.sharingSettings.users[userId].name | ||
) | ||
expect(user.prop('access')).toEqual( | ||
props.sharingSettings.users[userId].access | ||
) | ||
}) | ||
}) |
169 changes: 169 additions & 0 deletions
169
packages/widgets/src/SharingDialog/__tests__/SharingListItem.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,169 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
|
||
import { SharingListItem } from '../SharingListItem' | ||
import { World as WorldIcon } from '../icons/World' | ||
import { UserGroup as UserGroupIcon } from '../icons/UserGroup' | ||
import { Avatar } from '../icons/Avatar' | ||
import { | ||
ACCESS_NONE, | ||
SHARE_TARGET_EXTERNAL, | ||
SHARE_TARGET_PUBLIC, | ||
SHARE_TARGET_USER, | ||
SHARE_TARGET_GROUP, | ||
accessStrings, | ||
} from '../sharingConstants' | ||
|
||
describe('SharingDialog widget - SharingListItem component', () => { | ||
let shallowSharingListItemComponent | ||
let props | ||
|
||
const onChange = jest.fn() | ||
const onRemove = jest.fn() | ||
|
||
const getSharingListItemComponent = props => { | ||
if (!shallowSharingListItemComponent) { | ||
shallowSharingListItemComponent = shallow( | ||
<SharingListItem {...props} /> | ||
) | ||
} | ||
|
||
return shallowSharingListItemComponent | ||
} | ||
|
||
describe('external access', () => { | ||
beforeEach(() => { | ||
shallowSharingListItemComponent = undefined | ||
props = { | ||
access: ACCESS_NONE, | ||
accessOptions: [], | ||
disabled: false, | ||
name: 'External test', | ||
target: SHARE_TARGET_EXTERNAL, | ||
onChange, | ||
onRemove, | ||
} | ||
}) | ||
|
||
it('renders the icon for external access', () => | ||
expect( | ||
getSharingListItemComponent(props).find(WorldIcon) | ||
).toHaveLength(1)) | ||
|
||
it('renders the label for external access', () => | ||
expect( | ||
getSharingListItemComponent(props) | ||
.find('.share-entity') | ||
.html() | ||
).toMatch(props.name)) | ||
|
||
it('renders the description for external access', () => | ||
expect( | ||
getSharingListItemComponent(props) | ||
.find('.share-context') | ||
.html() | ||
).toMatch(accessStrings[props.access].description())) | ||
}) | ||
|
||
describe('public access', () => { | ||
beforeEach(() => { | ||
shallowSharingListItemComponent = undefined | ||
props = { | ||
access: ACCESS_NONE, | ||
accessOptions: [], | ||
disabled: false, | ||
name: 'Public test', | ||
target: SHARE_TARGET_PUBLIC, | ||
onChange, | ||
onRemove, | ||
} | ||
}) | ||
|
||
it('renders the icon for public access', () => | ||
expect( | ||
getSharingListItemComponent(props).find(UserGroupIcon) | ||
).toHaveLength(1)) | ||
|
||
it('renders the label for public access', () => | ||
expect( | ||
getSharingListItemComponent(props) | ||
.find('.share-entity') | ||
.html() | ||
).toMatch(props.name)) | ||
|
||
it('renders the description for public access', () => | ||
expect( | ||
getSharingListItemComponent(props) | ||
.find('.share-context') | ||
.html() | ||
).toMatch(accessStrings[props.access].publicDescription())) | ||
}) | ||
|
||
describe('group access', () => { | ||
beforeEach(() => { | ||
shallowSharingListItemComponent = undefined | ||
props = { | ||
access: ACCESS_NONE, | ||
accessOptions: [], | ||
disabled: false, | ||
name: 'Group test', | ||
target: SHARE_TARGET_GROUP, | ||
onChange, | ||
onRemove, | ||
} | ||
}) | ||
|
||
it('renders the icon for group access', () => | ||
expect( | ||
getSharingListItemComponent(props).find(UserGroupIcon) | ||
).toHaveLength(1)) | ||
|
||
it('renders the label for group access', () => | ||
expect( | ||
getSharingListItemComponent(props) | ||
.find('.share-entity') | ||
.html() | ||
).toMatch(props.name)) | ||
|
||
it('renders the description for group access', () => | ||
expect( | ||
getSharingListItemComponent(props) | ||
.find('.share-context') | ||
.html() | ||
).toMatch(accessStrings[props.access].description())) | ||
}) | ||
|
||
describe('user access', () => { | ||
beforeEach(() => { | ||
shallowSharingListItemComponent = undefined | ||
props = { | ||
access: ACCESS_NONE, | ||
accessOptions: [], | ||
disabled: false, | ||
name: 'User test', | ||
target: SHARE_TARGET_USER, | ||
onChange, | ||
onRemove, | ||
} | ||
}) | ||
|
||
it('renders the icon for user access', () => | ||
expect( | ||
getSharingListItemComponent(props).find(Avatar) | ||
).toHaveLength(1)) | ||
|
||
it('renders the label for user access', () => | ||
expect( | ||
getSharingListItemComponent(props) | ||
.find('.share-entity') | ||
.html() | ||
).toMatch(props.name)) | ||
|
||
it('renders the description for user access', () => | ||
expect( | ||
getSharingListItemComponent(props) | ||
.find('.share-context') | ||
.html() | ||
).toMatch(accessStrings[props.access].description())) | ||
}) | ||
}) |
Oops, something went wrong.