-
Notifications
You must be signed in to change notification settings - Fork 155
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
JanAckermann
committed
Apr 7, 2022
1 parent
afc9523
commit f2a06ad
Showing
10 changed files
with
275 additions
and
33 deletions.
There are no files selected for viewing
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
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
54 changes: 54 additions & 0 deletions
54
packages/web-app-user-management/tests/unit/components/CompareSaveDialog.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,54 @@ | ||
import Vuex from 'vuex' | ||
import { mount, createLocalVue } from '@vue/test-utils' | ||
import CompareSaveDialog from '../../../src/components/CompareSaveDialog.vue' | ||
|
||
const localVue = createLocalVue() | ||
localVue.use(Vuex) | ||
|
||
afterEach(() => jest.clearAllMocks()) | ||
|
||
describe('CompareSaveDialog', () => { | ||
describe('computed method "unsavedChanges"', () => { | ||
it('should be false if objects are equal', () => { | ||
const wrapper = getWrapper({ | ||
propsData: { | ||
originalObject: { id: '1', displayName: 'jan' }, | ||
compareObject: { id: '1', displayName: 'jan' } | ||
} | ||
}) | ||
expect(wrapper.vm.unsavedChanges).toBeFalsy() | ||
}) | ||
|
||
it('should be true if objects are not equal', () => { | ||
const wrapper = getWrapper({ | ||
propsData: { | ||
originalObject: { id: '1', displayName: 'jan' }, | ||
compareObject: { id: '1', displayName: 'janina' } | ||
} | ||
}) | ||
expect(wrapper.vm.unsavedChanges).toBeTruthy() | ||
}) | ||
}) | ||
}) | ||
|
||
function getWrapper({ propsData = {} } = {}) { | ||
return mount(CompareSaveDialog, { | ||
localVue, | ||
directives: { | ||
translate: jest.fn() | ||
}, | ||
mocks: { | ||
$gettext: jest.fn(), | ||
$gettextInterpolate: jest.fn() | ||
}, | ||
propsData: { | ||
originalObject: {}, | ||
compareObject: {}, | ||
...propsData | ||
}, | ||
stubs: { | ||
'oc-button': true, | ||
translate: true | ||
} | ||
}) | ||
} |
86 changes: 86 additions & 0 deletions
86
packages/web-app-user-management/tests/unit/components/Groups/SideBar/EditPanel.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,86 @@ | ||
import Vuex from 'vuex' | ||
import { mount, createLocalVue } from '@vue/test-utils' | ||
import EditPanel from '../../../../../src/components/Groups/SideBar/EditPanel.vue' | ||
|
||
const localVue = createLocalVue() | ||
localVue.use(Vuex) | ||
|
||
afterEach(() => jest.clearAllMocks()) | ||
|
||
describe('EditPanel', () => { | ||
describe('method "revertChanges"', () => { | ||
it('should revert changes on property editGroup', () => { | ||
const wrapper = getWrapper({ | ||
propsData: { | ||
group: { displayName: 'group' } | ||
} | ||
}) | ||
wrapper.vm.editGroup = { displayName: 'my group' } | ||
wrapper.vm.revertChanges() | ||
expect(wrapper.vm.editGroup).toEqual({ displayName: 'group' }) | ||
}) | ||
it('should revert changes on property formData', () => { | ||
const wrapper = getWrapper({ | ||
propsData: { | ||
group: { displayName: 'group' } | ||
} | ||
}) | ||
wrapper.vm.formData.displayName.valid = false | ||
wrapper.vm.formData.displayName.errorMessage = 'error' | ||
wrapper.vm.revertChanges() | ||
expect(wrapper.vm.formData.displayName.valid).toBeTruthy() | ||
expect(wrapper.vm.formData.displayName.errorMessage).toEqual('') | ||
}) | ||
}) | ||
|
||
describe('method "validateDisplayName"', () => { | ||
it('should return true if displayName is valid', () => { | ||
const wrapper = getWrapper() | ||
wrapper.vm.editGroup.displayName = 'jan' | ||
expect(wrapper.vm.validateDisplayName()).toBeTruthy() | ||
expect(wrapper.vm.formData.displayName.valid).toBeTruthy() | ||
}) | ||
it('should return false if displayName is not valid', () => { | ||
const wrapper = getWrapper() | ||
wrapper.vm.editGroup.displayName = '' | ||
expect(wrapper.vm.validateDisplayName()).toBeFalsy() | ||
expect(wrapper.vm.formData.displayName.valid).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe('computed method "invalidFormData"', () => { | ||
it('should be false if formData is invalid', () => { | ||
const wrapper = getWrapper() | ||
wrapper.vm.formData.displayName.valid = true | ||
expect(wrapper.vm.invalidFormData).toBeFalsy() | ||
}) | ||
it('should be true if formData is valid', () => { | ||
const wrapper = getWrapper() | ||
wrapper.vm.formData.displayName.valid = false | ||
expect(wrapper.vm.invalidFormData).toBeTruthy() | ||
}) | ||
}) | ||
}) | ||
|
||
function getWrapper({ propsData = {} } = {}) { | ||
return mount(EditPanel, { | ||
localVue, | ||
directives: { | ||
translate: jest.fn() | ||
}, | ||
mocks: { | ||
$gettext: jest.fn(), | ||
$gettextInterpolate: jest.fn() | ||
}, | ||
propsData: { | ||
group: { displayName: 'group' }, | ||
...propsData | ||
}, | ||
stubs: { | ||
'oc-text-input': true, | ||
'avatar-image': true, | ||
'oc-button': true, | ||
translate: true | ||
} | ||
}) | ||
} |
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
106 changes: 106 additions & 0 deletions
106
packages/web-app-user-management/tests/unit/components/Users/SideBar/EditPanel.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,106 @@ | ||
import Vuex from 'vuex' | ||
import { mount, createLocalVue } from '@vue/test-utils' | ||
import EditPanel from '../../../../../src/components/Users/SideBar/EditPanel.vue' | ||
|
||
const localVue = createLocalVue() | ||
localVue.use(Vuex) | ||
|
||
afterEach(() => jest.clearAllMocks()) | ||
|
||
describe('EditPanel', () => { | ||
describe('method "revertChanges"', () => { | ||
it('should revert changes on property editUser', () => { | ||
const wrapper = getWrapper({ | ||
propsData: { | ||
user: { displayName: 'jan', mail: '[email protected]' } | ||
} | ||
}) | ||
wrapper.vm.editUser.displayName = 'jana' | ||
wrapper.vm.editUser.mail = '[email protected]' | ||
wrapper.vm.revertChanges() | ||
expect(wrapper.vm.editUser.displayName).toEqual('jan') | ||
expect(wrapper.vm.editUser.mail).toEqual('[email protected]') | ||
}) | ||
it('should revert changes on property formData', () => { | ||
const wrapper = getWrapper({ | ||
propsData: { | ||
group: { displayName: 'jan' } | ||
} | ||
}) | ||
wrapper.vm.formData.displayName.valid = false | ||
wrapper.vm.formData.displayName.errorMessage = 'error' | ||
wrapper.vm.revertChanges() | ||
expect(wrapper.vm.formData.displayName.valid).toBeTruthy() | ||
expect(wrapper.vm.formData.displayName.errorMessage).toEqual('') | ||
}) | ||
}) | ||
|
||
describe('method "validateDisplayName"', () => { | ||
it('should return true if displayName is valid', () => { | ||
const wrapper = getWrapper() | ||
wrapper.vm.editUser.displayName = 'jan' | ||
expect(wrapper.vm.validateDisplayName()).toBeTruthy() | ||
expect(wrapper.vm.formData.displayName.valid).toBeTruthy() | ||
}) | ||
it('should return false if displayName is not valid', () => { | ||
const wrapper = getWrapper() | ||
wrapper.vm.editUser.displayName = '' | ||
expect(wrapper.vm.validateDisplayName()).toBeFalsy() | ||
expect(wrapper.vm.formData.displayName.valid).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe('method "validateEmail"', () => { | ||
it('should return true if email is valid', () => { | ||
const wrapper = getWrapper() | ||
wrapper.vm.editUser.mail = '[email protected]' | ||
expect(wrapper.vm.validateEmail()).toBeTruthy() | ||
expect(wrapper.vm.formData.email.valid).toBeTruthy() | ||
}) | ||
it('should return false if email is not valid', () => { | ||
const wrapper = getWrapper() | ||
wrapper.vm.editUser.mail = '' | ||
expect(wrapper.vm.validateEmail()).toBeFalsy() | ||
expect(wrapper.vm.formData.email.valid).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe('computed method "invalidFormData"', () => { | ||
it('should be false if formData is invalid', () => { | ||
const wrapper = getWrapper() | ||
wrapper.vm.formData.displayName.valid = true | ||
expect(wrapper.vm.invalidFormData).toBeFalsy() | ||
}) | ||
it('should be true if formData is valid', () => { | ||
const wrapper = getWrapper() | ||
wrapper.vm.formData.displayName.valid = false | ||
expect(wrapper.vm.invalidFormData).toBeTruthy() | ||
}) | ||
}) | ||
}) | ||
|
||
function getWrapper({ propsData = {} } = {}) { | ||
return mount(EditPanel, { | ||
localVue, | ||
directives: { | ||
translate: jest.fn() | ||
}, | ||
mocks: { | ||
$gettext: jest.fn(), | ||
$gettextInterpolate: jest.fn() | ||
}, | ||
propsData: { | ||
user: { displayName: 'jan', mail: '[email protected]' }, | ||
roles: [{ id: '1', displayName: 'admin' }], | ||
userRole: { id: '1', displayName: 'admin' }, | ||
...propsData | ||
}, | ||
stubs: { | ||
'oc-text-input': true, | ||
'avatar-image': true, | ||
'oc-button': true, | ||
'oc-select': true, | ||
translate: true | ||
} | ||
}) | ||
} |
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
Oops, something went wrong.