Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Mar 21, 2022
1 parent 816cd3d commit 775e922
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<span v-if="sharedParentRoute" class="oc-resource-indicators oc-text-truncate">
<span class="oc-mx-s">·</span>
<router-link
v-oc-tooltip="$gettext('Navigate to inheriting folder')"
v-oc-tooltip="$gettext('Navigate to parent folder')"
class="parent-folder oc-text-truncate"
:to="sharedParentRoute"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const selectors = {
collaboratorName: '.files-collaborators-collaborator-name',
shareType: '.files-collaborators-collaborator-share-type',
collaboratorRole: '.files-collaborators-collaborator-role',
collaboratorEdit: '.files-collaborators-collaborator-edit'
collaboratorEdit: '.files-collaborators-collaborator-edit',
shareInheritanceIndicators: '.oc-resource-indicators'
}

describe('Collaborator ListItem component', () => {
Expand Down Expand Up @@ -90,6 +91,17 @@ describe('Collaborator ListItem component', () => {
expect(wrapper.find(selectors.collaboratorEdit).exists()).toBeFalsy()
})
})
describe('share inheritance indicators', () => {
it('show when sharedParentRoute is given', () => {
const wrapper = createWrapper({ sharedParentRoute: { params: { item: '/folder' } } })
expect(wrapper.find(selectors.shareInheritanceIndicators).exists()).toBeTruthy()
expect(wrapper).toMatchSnapshot()
})
it('do not show when sharedParentRoute is not given', () => {
const wrapper = createWrapper()
expect(wrapper.find(selectors.shareInheritanceIndicators).exists()).toBeFalsy()
})
})
})

function createWrapper({
Expand All @@ -100,7 +112,8 @@ function createWrapper({
additionalInfo: 'brian@owncloud.com'
},
role = peopleRoleViewerFolder,
modifiable = true
modifiable = true,
sharedParentRoute = null
} = {}) {
return mount(ListItem, {
store: new Vuex.Store({
Expand All @@ -124,7 +137,8 @@ function createWrapper({
shareType,
role
},
modifiable
modifiable,
sharedParentRoute
},
localVue,
stubs: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Collaborator ListItem component share inheritance indicators show when sharedParentRoute is given 1`] = `
<div data-testid="collaborator-user-item-brian" class="files-collaborators-collaborator oc-flex oc-flex-middle oc-py-xs oc-flex-between">
<div class="oc-width-2-3 oc-flex oc-flex-middle" style="gap: 10px;">
<avatar-image-stub userid="brian" user-name="Brian Murphy" width="48" class="files-collaborators-collaborator-indicator"></avatar-image-stub>
<div class="oc-text-truncate">
<p class="oc-text-bold oc-text-truncate oc-m-rm"><span aria-hidden="true" class="files-collaborators-collaborator-name">Brian Murphy</span> <span aria-hidden="true" class="files-collaborators-collaborator-additional-info"> (brian@owncloud.com)</span> <span class="oc-invisible-sr">Share receiver name: Brian Murphy (brian@owncloud.com)</span></p>
<p class="oc-m-rm oc-flex"><span aria-hidden="true" class="files-collaborators-collaborator-share-type">User</span> <span class="oc-resource-indicators oc-text-truncate"><span class="oc-mx-s">·</span>
<router-link-stub to="[object Object]" class="parent-folder oc-text-truncate"><span class="text">via</span>
<oc-icon-stub name="folder-2" size="small" fill-type="line" class="oc-px-xs"></oc-icon-stub> <span class="text oc-text-truncate">folder</span>
</router-link-stub>
</span> <span class="oc-invisible-sr">Share type: User</span>
</p>
<!---->
</div>
</div>
<div class="oc-width-1-3 oc-flex oc-flex-nowrap oc-flex-right oc-flex-middle">
<role-dropdown-stub resource="[object Object]" existingrole="[object Object]" existingpermissions="" allowsharepermission="true" class="files-collaborators-collaborator-role"></role-dropdown-stub>
<edit-dropdown-stub sharecategory="user" data-testid="collaborator-edit" class="files-collaborators-collaborator-edit"></edit-dropdown-stub>
</div>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ describe('FileShares', () => {
await wrapper.vm.$nextTick()
expect(spyOnReloadShares).toHaveBeenCalledTimes(1)
})
it('correctly passes the shared parent route to the collaborator list item', () => {
const wrapper = getShallowMountedWrapper({
user,
outgoingCollaborators: collaborators
})
expect(wrapper).toMatchSnapshot()
})
})

describe('current space', () => {
Expand Down Expand Up @@ -196,6 +203,8 @@ const storeOptions = (data) => {
owner = user
}

const highlightedFile = 'testfile.jpg'

return {
state: {
user
Expand All @@ -204,12 +213,17 @@ const storeOptions = (data) => {
Files: {
state: {
incomingShares: incomingCollaborators,
sharesTree: []
sharesTree: { [`/${highlightedFile}`]: [Collaborators[0]] }
},
namespaced: true,
getters: {
highlightedFile: () => {
return getResource({ filename: 'testfile', extension: 'jpg', type: 'file', canShare })
return getResource({
filename: highlightedFile.split('.')[0],
extension: highlightedFile.split('.')[1],
type: 'file',
canShare
})
},
currentFileOutgoingCollaborators: () => outgoingCollaborators,
currentFileOutgoingSharesLoading: () => false,
Expand Down Expand Up @@ -264,7 +278,15 @@ function getMountedWrapper(data, loading = false) {
mocks: {
sharesLoading: loading,
$route: {
params: {}
params: { storageId: 1 }
},
$router: {
currentRoute: { name: 'some-route' },
resolve: (r) => {
return {
href: r.name
}
}
}
},
stubs: {
Expand All @@ -291,6 +313,14 @@ function getShallowMountedWrapper(data, loading = false) {
params: {
storageId: 1
}
},
$router: {
currentRoute: { name: 'some-route' },
resolve: (r) => {
return {
href: r.name
}
}
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ exports[`FileShares if currentUser can share initially renders add people dialog
</div>
`;

exports[`FileShares if there are collaborators present renders sharedWithLabel and sharee list 1`] = `
exports[`FileShares if there are collaborators present correctly passes the shared parent route to the collaborator list item 1`] = `
<div id="oc-files-sharing-sidebar" class="oc-position-relative">
<invite-collaborator-form-stub class="oc-my-s"></invite-collaborator-form-stub>
<div class="avatars-wrapper oc-flex oc-flex-middle oc-flex-between">
Expand All @@ -28,9 +28,30 @@ exports[`FileShares if there are collaborators present renders sharedWithLabel a
</oc-button-stub>
</div>
<ul id="files-collaborators-list" aria-label="Share receivers" class="oc-list oc-list-divider oc-overflow-hidden oc-m-rm">
<li>
<collaborator-list-item-stub share="[object Object]" modifiable="true" sharedparentroute="[object Object]"></collaborator-list-item-stub>
</li>
<li>
<collaborator-list-item-stub share="[object Object]" modifiable="true"></collaborator-list-item-stub>
</li>
</ul>
<!---->
</div>
`;

exports[`FileShares if there are collaborators present renders sharedWithLabel and sharee list 1`] = `
<div id="oc-files-sharing-sidebar" class="oc-position-relative">
<invite-collaborator-form-stub class="oc-my-s"></invite-collaborator-form-stub>
<div class="avatars-wrapper oc-flex oc-flex-middle oc-flex-between">
<h4 class="oc-text-initial oc-text-bold oc-my-rm">Shared with</h4>
<oc-button-stub type="button" size="medium" arialabel="Collapse list of invited people" submit="button" variation="passive" appearance="raw" justifycontent="center" gapsize="medium" data-testid="collaborators-show-people">
<oc-icon-stub name="arrow-up-s" filltype="fill" accessiblelabel="" type="span" size="medium" variation="passive" color=""></oc-icon-stub>
</oc-button-stub>
</div>
<ul id="files-collaborators-list" aria-label="Share receivers" class="oc-list oc-list-divider oc-overflow-hidden oc-m-rm">
<li>
<collaborator-list-item-stub share="[object Object]" modifiable="true" sharedparentroute="[object Object]"></collaborator-list-item-stub>
</li>
<li>
<collaborator-list-item-stub share="[object Object]" modifiable="true"></collaborator-list-item-stub>
</li>
Expand Down

0 comments on commit 775e922

Please sign in to comment.