-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e06753
commit 2d7173b
Showing
7 changed files
with
199 additions
and
44 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
packages/web-app-files/tests/unit/components/ContextActionMenu.spec.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,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 | ||
} | ||
}) | ||
} |
51 changes: 51 additions & 0 deletions
51
packages/web-app-files/tests/unit/components/Spaces/SpaceContextActions.spec.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,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({}) | ||
} |
25 changes: 25 additions & 0 deletions
25
...web-app-files/tests/unit/components/Spaces/__snapshots__/SpaceContextActions.spec.js.snap
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,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> | ||
`; |
8 changes: 8 additions & 0 deletions
8
packages/web-app-files/tests/unit/components/__snapshots__/ContextActionMenu.spec.js.snap
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,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> | ||
`; |
55 changes: 55 additions & 0 deletions
55
packages/web-app-files/tests/unit/mixins/spaces/showMembers.spec.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,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() | ||
} | ||
} | ||
} | ||
}) | ||
}) | ||
} |
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