Skip to content

Commit

Permalink
Add and adjust unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Mar 24, 2022
1 parent 2e06753 commit 2d7173b
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { shallowMount, createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import DesignSystem from 'owncloud-design-system'
import GetTextPlugin from 'vue-gettext'

import ContextActionMenu from '@files/src/components/ContextActionMenu'

const localVue = createLocalVue()
localVue.use(Vuex)
localVue.use(DesignSystem)
localVue.use(GetTextPlugin, {
translations: 'does-not-matter.json',
silent: true
})

describe('ContextActionMenu component', () => {
it('renders the menu with actions', () => {
const menuSections = [{ name: 'action 1' }, { name: 'action 2' }]
const wrapper = getShallowWrapper(menuSections)
expect(wrapper).toMatchSnapshot()
expect(wrapper.find('.oc-files-context-actions').exists()).toBeTruthy()
expect(wrapper.findAll('.oc-files-context-actions').length).toEqual(menuSections.length)
})
})

function getShallowWrapper(menuSections, items = []) {
return shallowMount(ContextActionMenu, {
localVue,
propsData: {
menuSections,
items
}
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import Vuex from 'vuex'
import DesignSystem from 'owncloud-design-system'
import { createLocalVue, mount } from '@vue/test-utils'
import SpaceContextActions from '../../../../src/components/Spaces/SpaceContextActions.vue'
import GetTextPlugin from 'vue-gettext'
import { createLocationSpaces } from '../../../../src/router'
import { buildSpace } from '../../../../src/helpers/resources'

const localVue = createLocalVue()
localVue.use(DesignSystem)
localVue.use(Vuex)
localVue.use(GetTextPlugin, {
translations: 'does-not-matter.json',
silent: true
})

const spaceMock = {
id: '1',
root: { permissions: [{ roles: ['manager'], grantedTo: [{ user: { id: 1 } }] }] }
}

describe('SpaceContextActions', () => {
describe('action handlers', () => {
it('renders actions that are always available: "Members", "Deleted files", "Details"', () => {
const wrapper = getWrapper(buildSpace(spaceMock))
expect(wrapper).toMatchSnapshot()
})
})
})

function getWrapper(space) {
return mount(SpaceContextActions, {
localVue,
store: createStore(),
mocks: {
$router: {
currentRoute: createLocationSpaces('some-route'),
resolve: (r) => {
return { href: r.name }
}
}
},
propsData: {
items: [space]
}
})
}

function createStore() {
return new Vuex.Store({})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SpaceContextActions action handlers renders actions that are always available: "Members", "Deleted files", "Details" 1`] = `
<div>
<div id="oc-files-context-menu">
<ul id="oc-files-context-actions-members" class="oc-list oc-my-rm oc-mx-rm oc-files-context-actions oc-pb-s oc-files-context-actions-border">
<li class="oc-files-context-action oc-px-s oc-rounded"><button type="button" class="oc-button oc-rounded oc-button-s oc-button-justify-content-center oc-button-gap-m oc-button-passive oc-button-passive-raw oc-files-actions-show-details-trigger action-menu-item" data-testid="action-handler"><span class="oc-icon oc-icon-m oc-icon-passive" data-testid="action-icon"><!----></span> <span data-testid="action-label" class="oc-files-context-action-label">Members</span>
<!---->
</button></li>
</ul>
<ul id="oc-files-context-actions-trashBin" class="oc-list oc-my-rm oc-mx-rm oc-files-context-actions oc-pb-s oc-pt-s oc-files-context-actions-border">
<li class="oc-files-context-action oc-px-s oc-rounded"><button type="button" class="oc-button oc-rounded oc-button-s oc-button-justify-content-center oc-button-gap-m oc-button-passive oc-button-passive-raw oc-files-actions-delete-trigger action-menu-item" data-testid="action-handler"><span class="oc-icon oc-icon-m oc-icon-passive" data-testid="action-icon"><!----></span> <span data-testid="action-label" class="oc-files-context-action-label">Deleted files</span>
<!---->
</button></li>
</ul>
<ul id="oc-files-context-actions-sidebar" class="oc-list oc-my-rm oc-mx-rm oc-files-context-actions oc-pt-s">
<li class="oc-files-context-action oc-px-s oc-rounded"><button type="button" class="oc-button oc-rounded oc-button-s oc-button-justify-content-center oc-button-gap-m oc-button-passive oc-button-passive-raw oc-files-actions-show-details-trigger action-menu-item" data-testid="action-handler"><span class="oc-icon oc-icon-m oc-icon-passive" data-testid="action-icon"><!----></span> <span data-testid="action-label" class="oc-files-context-action-label">Details</span>
<!---->
</button></li>
</ul>
</div>
<!---->
<!----> <input id="space-image-upload-input" type="file" name="file" multiple="multiple" tabindex="-1" accept="image/*">
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ContextActionMenu component renders the menu with actions 1`] = `
<div id="oc-files-context-menu">
<oc-list-stub id="oc-files-context-actions-action 1" class="oc-files-context-actions oc-pb-s oc-files-context-actions-border"></oc-list-stub>
<oc-list-stub id="oc-files-context-actions-action 2" class="oc-files-context-actions oc-pt-s"></oc-list-stub>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Vuex from 'vuex'
import { createStore } from 'vuex-extensions'
import { mount, createLocalVue } from '@vue/test-utils'
import ShowMembers from '@files/src/mixins/spaces/actions/showMembers.js'
import { openSpaceMembersPanel } from '../../../../src/quickActions'
const quickActions = '../../../../src/quickActions'

jest.mock(quickActions, () => ({
...jest.requireActual(quickActions),
openSpaceMembersPanel: jest.fn(() => false)
}))

const localVue = createLocalVue()
localVue.use(Vuex)

const Component = {
render() {},
mixins: [ShowMembers]
}

describe('showMembers', () => {
describe('isEnabled property', () => {
it('should be false when no resource given', () => {
const wrapper = getWrapper()
expect(wrapper.vm.$_showMembers_items[0].isEnabled({ resources: [] })).toBe(false)
})
it('should be true when a resource is given', () => {
const wrapper = getWrapper()
expect(wrapper.vm.$_showMembers_items[0].isEnabled({ resources: [{ id: 1 }] })).toBe(true)
})
})
describe('method "$_showMembers_trigger"', () => {
it('should trigger the members panel for one resource', async () => {
const wrapper = getWrapper()
await wrapper.vm.$_showMembers_trigger({ resources: [{ id: 1 }] })
expect(openSpaceMembersPanel).toBeCalledTimes(1)
})
})
})

function getWrapper() {
return mount(Component, {
localVue,
store: createStore(Vuex.Store, {
modules: {
Files: {
namespaced: true,
mutations: {
SET_FILE_SELECTION: jest.fn()
}
}
}
})
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
exports[`Spaces project view space image should show if given 1`] = `
<div class="space-overview">
<div>
<!---->
<!---->
<div class="oc-px-m oc-mt-m oc-flex">
<div class="oc-width-1-4 oc-mr-l"><img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApgAAAKYB3X3/OAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAANCSURBVEiJtZZPbBtFFMZ/M7ubXdtdb1xSFyeilBapySVU8h8OoFaooFSqiihIVIpQBKci6KEg9Q6H9kovIHoCIVQJJCKE1ENFjnAgcaSGC6rEnxBwA04Tx43t2FnvDAfjkNibxgHxnWb2e/u992bee7tCa00YFsffekFY+nUzFtjW0LrvjRXrCDIAaPLlW0nHL0SsZtVoaF98mLrx3pdhOqLtYPHChahZcYYO7KvPFxvRl5XPp1sN3adWiD1ZAqD6XYK1b/dvE5IWryTt2udLFedwc1+9kLp+vbbpoDh+6TklxBeAi9TL0taeWpdmZzQDry0AcO+jQ12RyohqqoYoo8RDwJrU+qXkjWtfi8Xxt58BdQuwQs9qC/afLwCw8tnQbqYAPsgxE1S6F3EAIXux2oQFKm0ihMsOF71dHYx+f3NND68ghCu1YIoePPQN1pGRABkJ6Bus96CutRZMydTl+TvuiRW1m3n0eDl0vRPcEysqdXn+jsQPsrHMquGeXEaY4Yk4wxWcY5V/9scqOMOVUFthatyTy8QyqwZ+kDURKoMWxNKr2EeqVKcTNOajqKoBgOE28U4tdQl5p5bwCw7BWquaZSzAPlwjlithJtp3pTImSqQRrb2Z8PHGigD4RZuNX6JYj6wj7O4TFLbCO/Mn/m8R+h6rYSUb3ekokRY6f/YukArN979jcW+V/S8g0eT/N3VN3kTqWbQ428m9/8k0P/1aIhF36PccEl6EhOcAUCrXKZXXWS3XKd2vc/TRBG9O5ELC17MmWubD2nKhUKZa26Ba2+D3P+4/MNCFwg59oWVeYhkzgN/JDR8deKBoD7Y+ljEjGZ0sosXVTvbc6RHirr2reNy1OXd6pJsQ+gqjk8VWFYmHrwBzW/n+uMPFiRwHB2I7ih8ciHFxIkd/3Omk5tCDV1t+2nNu5sxxpDFNx+huNhVT3/zMDz8usXC3ddaHBj1GHj/As08fwTS7Kt1HBTmyN29vdwAw+/wbwLVOJ3uAD1wi/dUH7Qei66PfyuRj4Ik9is+hglfbkbfR3cnZm7chlUWLdwmprtCohX4HUtlOcQjLYCu+fzGJH2QRKvP3UNz8bWk1qMxjGTOMThZ3kvgLI5AzFfo379UAAAAASUVORK5CYII=" class="space-overview-image oc-cursor-pointer"></div>
<div class="oc-width-3-4">
Expand All @@ -14,21 +12,8 @@ exports[`Spaces project view space image should show if given 1`] = `
<oc-button-stub type="button" size="medium" arialabel="Show context menu" submit="button" variation="passive" appearance="raw" justifycontent="center" gapsize="medium" id="space-context-btn" class="oc-ml-s">
<oc-icon-stub name="more-2" filltype="fill" accessiblelabel="" type="span" size="medium" variation="passive" color=""></oc-icon-stub>
</oc-button-stub>
<oc-drop-stub dropid="space-context-drop" toggle="#space-context-btn" position="right-start" mode="click" closeonclick="true" paddingsize="small" options="[object Object]"><input id="space-image-upload-input" type="file" name="file" multiple="multiple" tabindex="-1" accept="image/png,image/jpg,image/jpeg,image/gif">
<ul class="oc-list oc-files-context-actions">
<li class="oc-spaces-context-action oc-py-xs oc-px-s">
<oc-button-stub type="button" size="medium" submit="button" variation="passive" appearance="raw" justifycontent="left" gapsize="medium">
<oc-icon-stub name="delete-bin-5" filltype="fill" accessiblelabel="" type="span" size="medium" variation="passive" color=""></oc-icon-stub>
Deleted files
</oc-button-stub>
</li>
<li class="oc-spaces-context-action oc-py-xs oc-px-s">
<oc-button-stub type="button" size="medium" submit="button" variation="passive" appearance="raw" justifycontent="left" gapsize="medium">
<oc-icon-stub name="information" filltype="fill" accessiblelabel="" type="span" size="medium" variation="passive" color=""></oc-icon-stub>
Details
</oc-button-stub>
</li>
</ul>
<oc-drop-stub dropid="space-context-drop" toggle="#space-context-btn" position="right-start" mode="click" closeonclick="true" paddingsize="small" options="[object Object]">
<space-context-actions-stub items="[object Object]"></space-context-actions-stub>
</oc-drop-stub>
</div>
<oc-button-stub type="button" size="medium" arialabel="Open context menu and show members" submit="button" variation="passive" appearance="raw" justifycontent="center" gapsize="medium">
Expand All @@ -52,8 +37,6 @@ exports[`Spaces project view space image should show if given 1`] = `
exports[`Spaces project view space readme should show if given 1`] = `
<div class="space-overview">
<div>
<!---->
<!---->
<div class="oc-px-m oc-mt-m oc-flex">
<div class="oc-width-1-4 oc-mr-l"><img alt="" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApgAAAKYB3X3/OAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAANCSURBVEiJtZZPbBtFFMZ/M7ubXdtdb1xSFyeilBapySVU8h8OoFaooFSqiihIVIpQBKci6KEg9Q6H9kovIHoCIVQJJCKE1ENFjnAgcaSGC6rEnxBwA04Tx43t2FnvDAfjkNibxgHxnWb2e/u992bee7tCa00YFsffekFY+nUzFtjW0LrvjRXrCDIAaPLlW0nHL0SsZtVoaF98mLrx3pdhOqLtYPHChahZcYYO7KvPFxvRl5XPp1sN3adWiD1ZAqD6XYK1b/dvE5IWryTt2udLFedwc1+9kLp+vbbpoDh+6TklxBeAi9TL0taeWpdmZzQDry0AcO+jQ12RyohqqoYoo8RDwJrU+qXkjWtfi8Xxt58BdQuwQs9qC/afLwCw8tnQbqYAPsgxE1S6F3EAIXux2oQFKm0ihMsOF71dHYx+f3NND68ghCu1YIoePPQN1pGRABkJ6Bus96CutRZMydTl+TvuiRW1m3n0eDl0vRPcEysqdXn+jsQPsrHMquGeXEaY4Yk4wxWcY5V/9scqOMOVUFthatyTy8QyqwZ+kDURKoMWxNKr2EeqVKcTNOajqKoBgOE28U4tdQl5p5bwCw7BWquaZSzAPlwjlithJtp3pTImSqQRrb2Z8PHGigD4RZuNX6JYj6wj7O4TFLbCO/Mn/m8R+h6rYSUb3ekokRY6f/YukArN979jcW+V/S8g0eT/N3VN3kTqWbQ428m9/8k0P/1aIhF36PccEl6EhOcAUCrXKZXXWS3XKd2vc/TRBG9O5ELC17MmWubD2nKhUKZa26Ba2+D3P+4/MNCFwg59oWVeYhkzgN/JDR8deKBoD7Y+ljEjGZ0sosXVTvbc6RHirr2reNy1OXd6pJsQ+gqjk8VWFYmHrwBzW/n+uMPFiRwHB2I7ih8ciHFxIkd/3Omk5tCDV1t+2nNu5sxxpDFNx+huNhVT3/zMDz8usXC3ddaHBj1GHj/As08fwTS7Kt1HBTmyN29vdwAw+/wbwLVOJ3uAD1wi/dUH7Qei66PfyuRj4Ik9is+hglfbkbfR3cnZm7chlUWLdwmprtCohX4HUtlOcQjLYCu+fzGJH2QRKvP3UNz8bWk1qMxjGTOMThZ3kvgLI5AzFfo379UAAAAASUVORK5CYII=" class="space-overview-image oc-cursor-pointer"></div>
<div class="oc-width-3-4">
Expand All @@ -63,21 +46,8 @@ exports[`Spaces project view space readme should show if given 1`] = `
<oc-button-stub type="button" size="medium" arialabel="Show context menu" submit="button" variation="passive" appearance="raw" justifycontent="center" gapsize="medium" id="space-context-btn" class="oc-ml-s">
<oc-icon-stub name="more-2" filltype="fill" accessiblelabel="" type="span" size="medium" variation="passive" color=""></oc-icon-stub>
</oc-button-stub>
<oc-drop-stub dropid="space-context-drop" toggle="#space-context-btn" position="right-start" mode="click" closeonclick="true" paddingsize="small" options="[object Object]"><input id="space-image-upload-input" type="file" name="file" multiple="multiple" tabindex="-1" accept="image/png,image/jpg,image/jpeg,image/gif">
<ul class="oc-list oc-files-context-actions">
<li class="oc-spaces-context-action oc-py-xs oc-px-s">
<oc-button-stub type="button" size="medium" submit="button" variation="passive" appearance="raw" justifycontent="left" gapsize="medium">
<oc-icon-stub name="delete-bin-5" filltype="fill" accessiblelabel="" type="span" size="medium" variation="passive" color=""></oc-icon-stub>
Deleted files
</oc-button-stub>
</li>
<li class="oc-spaces-context-action oc-py-xs oc-px-s">
<oc-button-stub type="button" size="medium" submit="button" variation="passive" appearance="raw" justifycontent="left" gapsize="medium">
<oc-icon-stub name="information" filltype="fill" accessiblelabel="" type="span" size="medium" variation="passive" color=""></oc-icon-stub>
Details
</oc-button-stub>
</li>
</ul>
<oc-drop-stub dropid="space-context-drop" toggle="#space-context-btn" position="right-start" mode="click" closeonclick="true" paddingsize="small" options="[object Object]">
<space-context-actions-stub items="[object Object]"></space-context-actions-stub>
</oc-drop-stub>
</div>
<oc-button-stub type="button" size="medium" arialabel="Open context menu and show members" submit="button" variation="passive" appearance="raw" justifycontent="center" gapsize="medium">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ exports[`Spaces component should list spaces 1`] = `
<translate-stub tag="span">Create Space</translate-stub>
</button>
<div class="oc-pb-xl oc-border-b"><span>Store your project related files in Spaces for seamless collaboration.</span></div>
<div class="spaces-list oc-mt-l"><input id="space-image-upload-input" type="file" name="file" multiple="multiple" tabindex="-1" accept="image/*">
<!---->
<div class="spaces-list oc-mt-l">
<ul class="
oc-grid
oc-grid-match
Expand All @@ -30,14 +29,27 @@ exports[`Spaces component should list spaces 1`] = `
<div><button aria-label="Show context menu" type="button" class="oc-button oc-rounded oc-button-m oc-button-justify-content-center oc-button-gap-m oc-button-passive oc-button-passive-raw" id="space-context-btn-1"><span class="oc-icon oc-icon-m oc-icon-passive"><!----></span></button>
<div id="space-context-drop-1" class="oc-drop oc-box-shadow-medium oc-rounded" options="[object Object]">
<div class="oc-card oc-card-body oc-rounded oc-background-secondary oc-p-s">
<ul class="oc-list oc-files-context-actions">
<li class="oc-files-context-action oc-px-s"><button type="button" class="oc-button oc-rounded oc-button-m oc-button-justify-content-left oc-button-gap-m oc-button-passive oc-button-passive-raw"><span class="oc-flex oc-icon oc-icon-m oc-icon-passive"><!----></span>
Deleted files
</button></li>
<li class="oc-files-context-action oc-px-s"><button type="button" class="oc-button oc-rounded oc-button-m oc-button-justify-content-left oc-button-gap-m oc-button-passive oc-button-passive-raw"><span class="oc-flex oc-icon oc-icon-m oc-icon-passive"><!----></span>
Details
</button></li>
</ul>
<div>
<div id="oc-files-context-menu">
<ul id="oc-files-context-actions-members" class="oc-list oc-my-rm oc-mx-rm oc-files-context-actions oc-pb-s oc-files-context-actions-border">
<li class="oc-files-context-action oc-px-s oc-rounded"><button type="button" class="oc-button oc-rounded oc-button-s oc-button-justify-content-center oc-button-gap-m oc-button-passive oc-button-passive-raw oc-files-actions-show-details-trigger action-menu-item" data-testid="action-handler"><span class="oc-icon oc-icon-m oc-icon-passive" data-testid="action-icon"><!----></span> <span data-testid="action-label" class="oc-files-context-action-label">Members</span>
<!---->
</button></li>
</ul>
<ul id="oc-files-context-actions-trashBin" class="oc-list oc-my-rm oc-mx-rm oc-files-context-actions oc-pb-s oc-pt-s oc-files-context-actions-border">
<li class="oc-files-context-action oc-px-s oc-rounded"><button type="button" class="oc-button oc-rounded oc-button-s oc-button-justify-content-center oc-button-gap-m oc-button-passive oc-button-passive-raw oc-files-actions-delete-trigger action-menu-item" data-testid="action-handler"><span class="oc-icon oc-icon-m oc-icon-passive" data-testid="action-icon"><!----></span> <span data-testid="action-label" class="oc-files-context-action-label">Deleted files</span>
<!---->
</button></li>
</ul>
<ul id="oc-files-context-actions-sidebar" class="oc-list oc-my-rm oc-mx-rm oc-files-context-actions oc-pt-s">
<li class="oc-files-context-action oc-px-s oc-rounded"><button type="button" class="oc-button oc-rounded oc-button-s oc-button-justify-content-center oc-button-gap-m oc-button-passive oc-button-passive-raw oc-files-actions-show-details-trigger action-menu-item" data-testid="action-handler"><span class="oc-icon oc-icon-m oc-icon-passive" data-testid="action-icon"><!----></span> <span data-testid="action-label" class="oc-files-context-action-label">Details</span>
<!---->
</button></li>
</ul>
</div>
<!---->
<!----> <input id="space-image-upload-input" type="file" name="file" multiple="multiple" tabindex="-1" accept="image/*">
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 2d7173b

Please sign in to comment.