Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan committed Sep 12, 2022
1 parent b0c189d commit 0be9a7a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exports[`SharesNavigation component renders a shares navigation for both mobile
<oc-icon-stub name="arrow-down-s" filltype="line" accessiblelabel="" type="span" size="small" variation="passive" color=""></oc-icon-stub>
</oc-button-stub>
<div id="oc-drop-4" class="oc-drop oc-box-shadow-medium oc-rounded">
<div class="oc-card oc-card-body oc-background-secondary oc-p-s">
<div class="oc-card oc-card-body oc-rounded oc-background-secondary oc-p-s">
<ul class="oc-list oc-my-rm oc-mx-rm">
<li>
<oc-button-stub type="router-link" size="medium" to="/files/shares/with-me/" submit="button" variation="passive" appearance="raw" justifycontent="center" gapsize="medium" class="oc-my-xs shares-nav-mobile"><span class="icon-box"><oc-icon-stub name="info" filltype="fill" accessiblelabel="" type="span" size="medium" variation="passive" color=""></oc-icon-stub></span> <span>Shared with me</span></oc-button-stub>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ describe('Preview component', () => {
expect(ocResource.exists()).toBeTruthy()
expect(ocResource.props().resource).toMatchObject(wrapper.vm.searchResult.data)
})
describe('computed folderLink and parentFolderLink', () => {
describe('computed parentFolderLink', () => {
it('should be empty if no resource target location given', () => {
const wrapper = getWrapper({ resourceTargetLocation: null })
expect(wrapper.vm.folderLink).toEqual({})
expect(wrapper.vm.parentFolderLink).toEqual({})
})
it('should use the items storageId for the resource target location if present', () => {
const wrapper = getWrapper({ resourceTargetLocation: { name: 'some-route' } })
expect(wrapper.vm.folderLink.params.storageId).toEqual('1')
expect(wrapper.vm.parentFolderLink.params.storageId).toEqual('1')
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { buildResource, renameResource } from '@files/src/helpers/resources'
import InnerSideBar from 'web-pkg/src/components/sideBar/SideBar.vue'
import SideBar from '@files/src/components/SideBar/SideBar.vue'
import { createLocationSpaces } from '../../../../src/router'
import { clientService } from 'web-pkg/src/services'

jest.mock('web-pkg/src/observer')
jest.mock('@files/src/helpers/resources', () => {
Expand Down Expand Up @@ -170,6 +171,7 @@ describe('SideBar', () => {

function createWrapper({ item, selectedItems, mocks, currentRouteName = 'files-spaces-personal' }) {
const localVue = createLocalVue()
localVue.prototype.$clientService = clientService
localVue.use(Vuex)
localVue.use(VueCompositionAPI)
localVue.use(GetTextPlugin, {
Expand All @@ -190,6 +192,9 @@ function createWrapper({ item, selectedItems, mocks, currentRouteName = 'files-s
api_enabled: true,
public: { enabled: true }
}
}),
configuration: () => ({
server: 'https://example.com'
})
},
modules: {
Expand All @@ -205,12 +210,19 @@ function createWrapper({ item, selectedItems, mocks, currentRouteName = 'files-s
},
getters: {
highlightedFile: (state) => state.highlightedFile,
selectedFiles: () => selectedItems
selectedFiles: () => selectedItems,
currentFolder: () => simpleOwnFolder
},
mutations: {
SET_HIGHLIGHTED_FILE(state, file) {
state.highlightedFile = file
}
},
actions: {
loadCurrentFileOutgoingShares: jest.fn(),
loadIncomingShares: jest.fn(),
loadSharesTree: jest.fn(),
deleteShare: jest.fn()
}
},
runtime: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ exports[`Spaces projects view should list spaces 1`] = `
<div><button aria-label="Show members" 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"><span class="oc-icon oc-icon-m oc-icon-passive"><!----></span></button></div>
<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-background-secondary oc-p-s">
<div class="oc-card oc-card-body oc-rounded oc-background-secondary oc-p-s">
<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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function getMountedWrapper({ propsData = {} } = {}) {
'avatar-image': true,
'oc-checkbox': true,
'oc-button': true,
'oc-text-input': true,
'oc-table': { template: '<div></div>' }
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function getWrapper({ propsData = {} } = {}) {
'avatar-image': true,
'oc-checkbox': true,
'oc-button': true,
'oc-text-input': true,
'oc-table': { template: '<div></div>' }
}
})
Expand Down
26 changes: 12 additions & 14 deletions packages/web-runtime/tests/unit/pages/account.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ describe('account page', () => {
server: 'http://server/address/',
isAccountEditingEnabled: true
})
const wrapper = getWrapper(store)
await wrapper.setData({ loadingGroups: false })
const wrapper = getWrapper({ store, data: { loadingGroups: false } })
const editUrlButton = wrapper.find(selectors.editUrlButton)
const editRouteButton = wrapper.find(selectors.editRouteButton)
expect(editUrlButton).toMatchSnapshot()
Expand All @@ -66,8 +65,7 @@ describe('account page', () => {
server: 'http://server/address/',
isAccountEditingEnabled: false
})
const wrapper = getWrapper(store)
await wrapper.setData({ loadingGroups: false })
const wrapper = getWrapper({ store, data: { loadingGroups: false } })
const editUrlButton = wrapper.find(selectors.editUrlButton)
expect(editUrlButton.exists()).toBeFalsy()
})
Expand All @@ -78,8 +76,7 @@ describe('account page', () => {
isAccountEditingEnabled: false,
getNavItemsByExtension: jest.fn(() => [{ route: 'some-route' }])
})
const wrapper = getWrapper(store)
await wrapper.setData({ loadingGroups: false })
const wrapper = getWrapper({ store, data: { loadingGroups: false } })
const editRouteButton = wrapper.find(selectors.editRouteButton)
expect(editRouteButton).toMatchSnapshot()
})
Expand All @@ -96,7 +93,7 @@ describe('account page', () => {
email: 'some-email'
}
})
const wrapper = getWrapper(store)
const wrapper = getWrapper({ store })

const accountPageInfo = wrapper.find(selectors.accountPageInfo)
expect(accountPageInfo).toMatchSnapshot()
Expand All @@ -105,14 +102,14 @@ describe('account page', () => {
describe('group membership', () => {
it('displays message if not member of any groups', async () => {
const store = getStore({ user: { groups: [] } })
const wrapper = getWrapper(store)
const wrapper = getWrapper({ store })

const groupNamesEmpty = wrapper.find(selectors.groupNamesEmpty)
expect(groupNamesEmpty.exists()).toBeTruthy()
})
it('displays group names', async () => {
const store = getStore({ user: { groups: ['one', 'two', 'three'] } })
const wrapper = getWrapper(store)
const wrapper = getWrapper({ store })

const groupNames = wrapper.find(selectors.groupNames)
expect(groupNames).toMatchSnapshot()
Expand All @@ -126,7 +123,7 @@ describe('account page', () => {
return Promise.resolve()
})
const store = getStore({ server: 'https://example.com' })
const wrapper = getWrapper(store)
const wrapper = getWrapper({ store })

const showMessageStub = jest.spyOn(wrapper.vm, 'showMessage')

Expand All @@ -140,7 +137,7 @@ describe('account page', () => {
return Promise.reject(new Error())
})
const store = getStore({ server: 'https://example.com' })
const wrapper = getWrapper(store)
const wrapper = getWrapper({ store })

jest.spyOn(console, 'error').mockImplementation(() => {})
const showMessageStub = jest.spyOn(wrapper.vm, 'showMessage')
Expand All @@ -154,18 +151,18 @@ describe('account page', () => {
describe('computed method "isChangePasswordEnabled"', () => {
it('should be true if capability is enabled', () => {
const store = getStore({ capabilities: { spaces: { enabled: true } } })
const wrapper = getWrapper(store)
const wrapper = getWrapper({ store })
expect(wrapper.vm.isChangePasswordEnabled).toBeTruthy()
})
it('should be false if capability is not enabled', () => {
const store = getStore()
const wrapper = getWrapper(store)
const wrapper = getWrapper({ store })
expect(wrapper.vm.isChangePasswordEnabled).toBeFalsy()
})
})
})

function getWrapper(store = getStore()) {
function getWrapper({ store = getStore(), data = {} } = {}) {
const component = {
...account,
mounted: jest.fn()
Expand All @@ -179,6 +176,7 @@ function getWrapper(store = getStore()) {
'oc-button': true,
'oc-icon': true
},
data: () => data,
store
}
return shallowMount(component, opts)
Expand Down

0 comments on commit 0be9a7a

Please sign in to comment.