From d9a31e3bce936e55b5476e37f5e8d0ea418e082e Mon Sep 17 00:00:00 2001 From: Jannik Stehle Date: Fri, 18 Mar 2022 13:51:25 +0100 Subject: [PATCH] Add unit tests --- .../SideBar/Shares/Collaborators/ListItem.vue | 2 +- .../Shares/Collaborators/ListItem.spec.js | 20 +++++++++-- .../__snapshots__/ListItem.spec.js.snap | 23 ++++++++++++ .../SideBar/Shares/FileShares.spec.js | 36 +++++++++++++++++-- .../__snapshots__/FileShares.spec.js.snap | 23 +++++++++++- 5 files changed, 96 insertions(+), 8 deletions(-) create mode 100644 packages/web-app-files/tests/unit/components/SideBar/Shares/Collaborators/__snapshots__/ListItem.spec.js.snap diff --git a/packages/web-app-files/src/components/SideBar/Shares/Collaborators/ListItem.vue b/packages/web-app-files/src/components/SideBar/Shares/Collaborators/ListItem.vue index 30de396bb45..b5d2ff342f7 100644 --- a/packages/web-app-files/src/components/SideBar/Shares/Collaborators/ListItem.vue +++ b/packages/web-app-files/src/components/SideBar/Shares/Collaborators/ListItem.vue @@ -45,7 +45,7 @@ · diff --git a/packages/web-app-files/tests/unit/components/SideBar/Shares/Collaborators/ListItem.spec.js b/packages/web-app-files/tests/unit/components/SideBar/Shares/Collaborators/ListItem.spec.js index c57fc166737..51736f67e4f 100644 --- a/packages/web-app-files/tests/unit/components/SideBar/Shares/Collaborators/ListItem.spec.js +++ b/packages/web-app-files/tests/unit/components/SideBar/Shares/Collaborators/ListItem.spec.js @@ -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', () => { @@ -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({ @@ -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({ @@ -127,7 +140,8 @@ function createWrapper({ shareType, role }, - modifiable + modifiable, + sharedParentRoute }, localVue, stubs: { diff --git a/packages/web-app-files/tests/unit/components/SideBar/Shares/Collaborators/__snapshots__/ListItem.spec.js.snap b/packages/web-app-files/tests/unit/components/SideBar/Shares/Collaborators/__snapshots__/ListItem.spec.js.snap new file mode 100644 index 00000000000..99240fea193 --- /dev/null +++ b/packages/web-app-files/tests/unit/components/SideBar/Shares/Collaborators/__snapshots__/ListItem.spec.js.snap @@ -0,0 +1,23 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Collaborator ListItem component share inheritance indicators show when sharedParentRoute is given 1`] = ` +
+
+ +
+

Share receiver name: Brian Murphy (brian@owncloud.com)

+

· + via + folder + + Share type: User +

+ +
+
+
+ + +
+
+`; diff --git a/packages/web-app-files/tests/unit/components/SideBar/Shares/FileShares.spec.js b/packages/web-app-files/tests/unit/components/SideBar/Shares/FileShares.spec.js index 8fbde376718..c6b69326485 100644 --- a/packages/web-app-files/tests/unit/components/SideBar/Shares/FileShares.spec.js +++ b/packages/web-app-files/tests/unit/components/SideBar/Shares/FileShares.spec.js @@ -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', () => { @@ -196,6 +203,8 @@ const storeOptions = (data) => { owner = user } + const highlightedFile = 'testfile.jpg' + return { state: { user @@ -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, @@ -265,7 +279,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: { @@ -292,6 +314,14 @@ function getShallowMountedWrapper(data, loading = false) { params: { storageId: 1 } + }, + $router: { + currentRoute: { name: 'some-route' }, + resolve: (r) => { + return { + href: r.name + } + } } } }) diff --git a/packages/web-app-files/tests/unit/components/SideBar/Shares/__snapshots__/FileShares.spec.js.snap b/packages/web-app-files/tests/unit/components/SideBar/Shares/__snapshots__/FileShares.spec.js.snap index d3438731d0a..a00660d67b2 100644 --- a/packages/web-app-files/tests/unit/components/SideBar/Shares/__snapshots__/FileShares.spec.js.snap +++ b/packages/web-app-files/tests/unit/components/SideBar/Shares/__snapshots__/FileShares.spec.js.snap @@ -18,7 +18,7 @@ exports[`FileShares if currentUser can share initially renders add people dialog `; -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`] = `
@@ -28,9 +28,30 @@ exports[`FileShares if there are collaborators present renders sharedWithLabel a
    +
  • + +
  • +
+ +
+`; + +exports[`FileShares if there are collaborators present renders sharedWithLabel and sharee list 1`] = ` +
+ +
+

Shared with

+ + + +
+
    +
  • + +