Skip to content

Commit

Permalink
Adjust and add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Mar 8, 2022
1 parent f174a27 commit 2c4f1ac
Show file tree
Hide file tree
Showing 12 changed files with 292 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@ function createStore(state = { selected: [], currentFolder: {} }, fileHandlers =
return new Vuex.Store({
getters: {
getToken: jest.fn(),
quota: jest.fn()
quota: jest.fn(),
user: function () {
return { id: 'alice' }
}
},
modules: {
Files: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ function getWrapper(route, { filename, extension, type = '', mimeType }, availab
$route: route,
publicPage: () => false
},
provide: {
currentSpace: {
value: {}
}
},
propsData: {
items: [
{
Expand Down
45 changes: 39 additions & 6 deletions packages/web-app-files/tests/unit/mixins/spaces/delete.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { mount, createLocalVue } from '@vue/test-utils'
import Delete from '@files/src/mixins/spaces/actions/delete.js'
import { createLocationSpaces } from '../../../../src/router'
import mockAxios from 'jest-mock-axios'
import { buildSpace } from '../../../../src/helpers/resources'

const localVue = createLocalVue()
localVue.use(Vuex)
Expand All @@ -22,16 +23,42 @@ describe('delete', () => {
expect(wrapper.vm.$_delete_items[0].isEnabled({ resources: [] })).toBe(false)
})
it('should be false when the space is not disabled', () => {
const spaceMock = {
id: '1',
root: {
permissions: [{ roles: ['manager'], grantedTo: [{ user: { id: 1 } }] }]
}
}
const wrapper = getWrapper()
expect(
wrapper.vm.$_delete_items[0].isEnabled({ resources: [{ id: 1, disabled: false }] })
).toBe(false)
expect(wrapper.vm.$_delete_items[0].isEnabled({ resources: [buildSpace(spaceMock)] })).toBe(
false
)
})
it('should be true when the space is disabled', () => {
const spaceMock = {
id: '1',
root: {
permissions: [{ roles: ['manager'], grantedTo: [{ user: { id: 1 } }] }],
deleted: { state: 'trashed' }
}
}
const wrapper = getWrapper()
expect(
wrapper.vm.$_delete_items[0].isEnabled({ resources: [{ id: 1, disabled: true }] })
).toBe(true)
expect(wrapper.vm.$_delete_items[0].isEnabled({ resources: [buildSpace(spaceMock)] })).toBe(
true
)
})
it('should be false when the current user is a viewer', () => {
const spaceMock = {
id: '1',
root: {
permissions: [{ roles: ['viewer'], grantedTo: [{ user: { id: 1 } }] }],
deleted: { state: 'trashed' }
}
}
const wrapper = getWrapper()
expect(wrapper.vm.$_delete_items[0].isEnabled({ resources: [buildSpace(spaceMock)] })).toBe(
false
)
})
})

Expand Down Expand Up @@ -105,6 +132,12 @@ function getWrapper() {
getToken: () => 'token'
},
modules: {
user: {
state: {
id: 'alice',
uuid: 1
}
},
Files: {
namespaced: true,
mutations: {
Expand Down
44 changes: 38 additions & 6 deletions packages/web-app-files/tests/unit/mixins/spaces/disable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { mount, createLocalVue } from '@vue/test-utils'
import disable from '@files/src/mixins/spaces/actions/disable.js'
import { createLocationSpaces } from '../../../../src/router'
import mockAxios from 'jest-mock-axios'
import { buildSpace } from '../../../../src/helpers/resources'

const localVue = createLocalVue()
localVue.use(Vuex)
Expand All @@ -22,16 +23,41 @@ describe('disable', () => {
expect(wrapper.vm.$_disable_items[0].isEnabled({ resources: [] })).toBe(false)
})
it('should be true when the space is not disabled', () => {
const spaceMock = {
id: '1',
root: {
permissions: [{ roles: ['manager'], grantedTo: [{ user: { id: 1 } }] }]
}
}
const wrapper = getWrapper()
expect(
wrapper.vm.$_disable_items[0].isEnabled({ resources: [{ id: 1, disabled: false }] })
).toBe(true)
expect(wrapper.vm.$_disable_items[0].isEnabled({ resources: [buildSpace(spaceMock)] })).toBe(
true
)
})
it('should be false when the space is disabled', () => {
const spaceMock = {
id: '1',
root: {
permissions: [{ roles: ['manager'], grantedTo: [{ user: { id: 1 } }] }],
deleted: { state: 'trashed' }
}
}
const wrapper = getWrapper()
expect(
wrapper.vm.$_disable_items[0].isEnabled({ resources: [{ id: 1, disabled: true }] })
).toBe(false)
expect(wrapper.vm.$_disable_items[0].isEnabled({ resources: [buildSpace(spaceMock)] })).toBe(
false
)
})
it('should be false when current user is a viewer', () => {
const spaceMock = {
id: '1',
root: {
permissions: [{ roles: ['viewer'], grantedTo: [{ user: { id: 1 } }] }]
}
}
const wrapper = getWrapper()
expect(wrapper.vm.$_disable_items[0].isEnabled({ resources: [buildSpace(spaceMock)] })).toBe(
false
)
})
})

Expand Down Expand Up @@ -106,6 +132,12 @@ function getWrapper() {
getToken: () => 'token'
},
modules: {
user: {
state: {
id: 'alice',
uuid: 1
}
},
Files: {
namespaced: true,
mutations: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Vuex from 'vuex'
import { mount, createLocalVue } from '@vue/test-utils'
import EditQuota from '@files/src/mixins/spaces/actions/editQuota.js'
import { buildSpace } from '../../../../src/helpers/resources'
import { createStore } from 'vuex-extensions'

const localVue = createLocalVue()
localVue.use(Vuex)
Expand All @@ -18,11 +20,47 @@ describe('editQuota', () => {
const wrapper = getWrapper()
expect(wrapper.vm.$_editQuota_items[0].isEnabled({ resources: [] })).toBe(false)
})
it('should be true when the current user is a manager', () => {
const spaceMock = {
id: '1',
quota: {},
root: {
permissions: [{ roles: ['manager'], grantedTo: [{ user: { id: 1 } }] }]
}
}
const wrapper = getWrapper()
expect(
wrapper.vm.$_editQuota_items[0].isEnabled({ resources: [buildSpace(spaceMock)] })
).toBe(true)
})
it('should be false when the current user is a viewer', () => {
const spaceMock = {
id: '1',
quota: {},
root: {
permissions: [{ roles: ['viewer'], grantedTo: [{ user: { id: 1 } }] }]
}
}
const wrapper = getWrapper()
expect(
wrapper.vm.$_editQuota_items[0].isEnabled({ resources: [buildSpace(spaceMock)] })
).toBe(false)
})
})
})

function getWrapper() {
return mount(Component, {
localVue
localVue,
store: createStore(Vuex.Store, {
modules: {
user: {
state: {
id: 'alice',
uuid: 1
}
}
}
})
})
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Vuex from 'vuex'
import { mount, createLocalVue } from '@vue/test-utils'
import editReadmeContent from '@files/src/mixins/spaces/actions/editReadmeContent.js'
import { buildSpace } from '../../../../src/helpers/resources'

const localVue = createLocalVue()
localVue.use(Vuex)
Expand All @@ -13,15 +14,47 @@ afterEach(() => jest.clearAllMocks())

describe('editReadmeContent', () => {
describe('isEnabled property', () => {
it('should be true for space managers', () => {
const spaceMock = {
id: '1',
root: { permissions: [{ roles: ['manager'], grantedTo: [{ user: { id: 1 } }] }] },
special: [{ specialFolder: { name: 'readme' } }]
}

const wrapper = getWrapper()
expect(
wrapper.vm.$_editReadmeContent_items[0].isEnabled({
resources: [buildSpace(spaceMock)]
})
).toBe(true)
})
it('should be false when not resource given', () => {
const wrapper = getWrapper()
expect(wrapper.vm.$_editReadmeContent_items[0].isEnabled({ resources: [] })).toBe(false)
})
it('should be false when spaceReadmeData does not exist', () => {
const spaceMock = {
id: '1',
root: { permissions: [{ roles: ['manager'], grantedTo: [{ user: { id: 1 } }] }] }
}

const wrapper = getWrapper()
expect(
wrapper.vm.$_editReadmeContent_items[0].isEnabled({
resources: [{ id: 1 }]
resources: [buildSpace(spaceMock)]
})
).toBe(false)
})
it('should be false when the current user is a viewer', () => {
const spaceMock = {
id: '1',
root: { permissions: [{ roles: ['viewer'], grantedTo: [{ user: { id: 1 } }] }] }
}

const wrapper = getWrapper()
expect(
wrapper.vm.$_editReadmeContent_items[0].isEnabled({
resources: [buildSpace(spaceMock)]
})
).toBe(false)
})
Expand All @@ -30,6 +63,16 @@ describe('editReadmeContent', () => {

function getWrapper() {
return mount(Component, {
localVue
localVue,
store: new Vuex.Store({
modules: {
user: {
state: {
id: 'alice',
uuid: 1
}
}
}
})
})
}
45 changes: 39 additions & 6 deletions packages/web-app-files/tests/unit/mixins/spaces/restore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { mount, createLocalVue } from '@vue/test-utils'
import restore from '@files/src/mixins/spaces/actions/restore.js'
import { createLocationSpaces } from '../../../../src/router'
import mockAxios from 'jest-mock-axios'
import { buildSpace } from '../../../../src/helpers/resources'

const localVue = createLocalVue()
localVue.use(Vuex)
Expand All @@ -22,16 +23,42 @@ describe('restore', () => {
expect(wrapper.vm.$_restore_items[0].isEnabled({ resources: [] })).toBe(false)
})
it('should be false when the space is not disabled', () => {
const spaceMock = {
id: '1',
root: {
permissions: [{ roles: ['manager'], grantedTo: [{ user: { id: 1 } }] }]
}
}
const wrapper = getWrapper()
expect(
wrapper.vm.$_restore_items[0].isEnabled({ resources: [{ id: 1, disabled: false }] })
).toBe(false)
expect(wrapper.vm.$_restore_items[0].isEnabled({ resources: [buildSpace(spaceMock)] })).toBe(
false
)
})
it('should be true when the space is disabled', () => {
const spaceMock = {
id: '1',
root: {
permissions: [{ roles: ['manager'], grantedTo: [{ user: { id: 1 } }] }],
deleted: { state: 'trashed' }
}
}
const wrapper = getWrapper()
expect(
wrapper.vm.$_restore_items[0].isEnabled({ resources: [{ id: 1, disabled: true }] })
).toBe(true)
expect(wrapper.vm.$_restore_items[0].isEnabled({ resources: [buildSpace(spaceMock)] })).toBe(
true
)
})
it('should be false when the current user is a viewer', () => {
const spaceMock = {
id: '1',
root: {
permissions: [{ roles: ['viewer'], grantedTo: [{ user: { id: 1 } }] }],
deleted: { state: 'trashed' }
}
}
const wrapper = getWrapper()
expect(wrapper.vm.$_restore_items[0].isEnabled({ resources: [buildSpace(spaceMock)] })).toBe(
false
)
})
})

Expand Down Expand Up @@ -106,6 +133,12 @@ function getWrapper() {
getToken: () => 'token'
},
modules: {
user: {
state: {
id: 'alice',
uuid: 1
}
},
Files: {
namespaced: true,
mutations: {
Expand Down
Loading

0 comments on commit 2c4f1ac

Please sign in to comment.