Skip to content

Commit

Permalink
Fix failing vue unit tests due to changes
Browse files Browse the repository at this point in the history
Signed-off-by: Sagar <sagargurung1001@gmail.com>
  • Loading branch information
SagarGi committed Dec 16, 2024
1 parent cd4a717 commit 5a0c40a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"lint:fix": "eslint --ext .js,.vue src tests --fix",
"stylelint": "stylelint css src",
"stylelint:fix": "stylelint css src --fix",
"test:unit": "jest --silent",
"test:unit": "jest",
"test:unit:watch": "jest --watch --no-coverage"
},
"repository": {
Expand Down
23 changes: 16 additions & 7 deletions src/components/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ export default {
if (this.state.openproject_instance_url && this.state.openproject_client_id && this.state.openproject_client_secret && this.state.nc_oauth_client) {
this.showDefaultManagedProjectFolders = true
}
if (this.state.openproject_instance_url && this.state.authorization_settings.oidc_provider && this.state.authorization_settings.targeted_audience_client_id) {
if (this.state.authorization_method === AUTH_METHOD.OIDC && this.state.openproject_instance_url && this.state.authorization_settings.oidc_provider && this.state.authorization_settings.targeted_audience_client_id) {
this.showDefaultManagedProjectFolders = true
}
if (this.state.fresh_project_folder_setup === false) {
Expand All @@ -873,7 +873,7 @@ export default {
this.isFormCompleted.authorizationMethod = true
this.authorizationMethod.authorizationMethodSet = this.authorizationMethod.currentAuthorizationMethodSelected = this.state.authorization_method
}
if (this.state.authorization_settings.oidc_provider !== '' && this.state.authorization_settings.targeted_audience_client_id !== '') {
if (this.state.authorization_method === AUTH_METHOD.OIDC && this.state.authorization_settings.oidc_provider !== '' && this.state.authorization_settings.targeted_audience_client_id !== '') {
this.formMode.authorizationSetting = F_MODES.VIEW
this.isFormCompleted.authorizationSetting = true
this.authorizationSetting.oidcProviderSet = this.authorizationSetting.currentOIDCProviderSelected = this.state.authorization_settings.oidc_provider
Expand All @@ -889,11 +889,20 @@ export default {
}
}
if (this.state.openproject_instance_url && this.state.authorization_method) {
if (!this.state.openproject_client_id || !this.state.openproject_client_secret) {
if (!this.state.openproject_client_id && !this.state.openproject_client_secret) {
this.formMode.opOauth = F_MODES.EDIT
}
if (!this.state.authorization_settings.oidc_provider || !this.state.authorization_settings.targeted_audience_client_id) {
this.formMode.authorizationSetting = F_MODES.EDIT
}
if (this.state.openproject_instance_url && this.state.authorization_method) {
if (this.state.authorization_method === AUTH_METHOD.OAUTH2) {
if (!this.state.openproject_client_id || !this.state.openproject_client_secret) {
this.formMode.authorizationSetting = F_MODES.EDIT
}
}
if (this.state.authorization_method === AUTH_METHOD.OIDC) {
if (!this.state.authorization_settings.oidc_provider || !this.state.authorization_settings.targeted_audience_client_id) {
this.formMode.authorizationSetting = F_MODES.EDIT
}
}
}
if (this.state.nc_oauth_client) {
Expand Down Expand Up @@ -1193,9 +1202,9 @@ export default {
this.state.openproject_client_secret = null
this.state.default_enable_navigation = false
this.state.openproject_instance_url = null
this.authorizationMethod.authorizationMethodSet = null
this.authorizationSetting.currentOIDCProviderSelected = null
this.state.authorization_settings.targeted_audience_client_id = null
this.authorizationSetting.currentOIDCProviderSelected = null
this.authorizationMethod.authorizationMethodSet = null
this.state.default_enable_unified_search = false
this.oPUserAppPassword = null
await this.saveOPOptions()
Expand Down
26 changes: 22 additions & 4 deletions tests/jest/components/AdminSettings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import axios from '@nextcloud/axios'
import { createLocalVue, shallowMount, mount } from '@vue/test-utils'
import AdminSettings from '../../../src/components/AdminSettings.vue'
import { F_MODES } from '../../../src/utils.js'
import { F_MODES, AUTH_METHOD } from '../../../src/utils.js'
import * as dialogs from '@nextcloud/dialogs'

jest.mock('@nextcloud/axios', () => {
Expand Down Expand Up @@ -97,6 +97,7 @@ const selectors = {

const completeIntegrationState = {
openproject_instance_url: 'http://openproject.com',
authorization_method: AUTH_METHOD.OAUTH2,
openproject_client_id: 'some-client-id-for-op',
openproject_client_secret: 'some-client-secret-for-op',
nc_oauth_client: {
Expand Down Expand Up @@ -140,6 +141,7 @@ describe('AdminSettings.vue', () => {
'with incomplete OpenProject OAuth values',
{
openproject_instance_url: 'https://openproject.example.com',
authorization_method: AUTH_METHOD.OAUTH2,
openproject_client_id: null,
openproject_client_secret: null,
nc_oauth_client: null,
Expand Down Expand Up @@ -187,6 +189,7 @@ describe('AdminSettings.vue', () => {
'with everything but empty OpenProject OAuth values',
{
openproject_instance_url: 'https://openproject.example.com',
authorization_method: 'oauth2',
openproject_client_id: null,
openproject_client_secret: null,
nc_oauth_client: {
Expand Down Expand Up @@ -476,7 +479,7 @@ describe('AdminSettings.vue', () => {

expect(wrapper.vm.formMode.server).toBe(F_MODES.EDIT)
expect(wrapper.vm.isOpenProjectInstanceValid).toBe(null)
expect(wrapper.vm.formMode.opOauth).toBe(F_MODES.DISABLE)
expect(wrapper.vm.formMode.authorizationMethod).toBe(F_MODES.DISABLE)

serverHostForm = wrapper.find(selectors.serverHostForm)
await serverHostForm.find('input').setValue('http://openproject.com')
Expand All @@ -492,7 +495,7 @@ describe('AdminSettings.vue', () => {
expect(wrapper.vm.isFormCompleted.server).toBe(true)
expect(setAdminConfigAPISpy).toBeCalledTimes(1)
// should set the OpenProject OAuth Values form to edit mode
expect(wrapper.vm.formMode.opOauth).toBe(F_MODES.EDIT)
expect(wrapper.vm.formMode.authorizationMethod).toBe(F_MODES.EDIT)
})
})
describe('disabled state', () => {
Expand Down Expand Up @@ -556,6 +559,7 @@ describe('AdminSettings.vue', () => {
wrapper = getMountedWrapper({
state: {
openproject_instance_url: 'http://openproject.com',
authorization_method: AUTH_METHOD.OAUTH2,
openproject_client_id: 'openproject-client-id',
openproject_client_secret: 'openproject-client-secret',
nc_oauth_client: null,
Expand Down Expand Up @@ -616,6 +620,7 @@ describe('AdminSettings.vue', () => {
wrapper = getMountedWrapper({
state: {
openproject_instance_url: 'http://openproject.com',
authorization_method: AUTH_METHOD.OAUTH2,
openproject_client_id: '',
openproject_client_secret: '',
nc_oauth_client: null,
Expand Down Expand Up @@ -669,6 +674,7 @@ describe('AdminSettings.vue', () => {
const wrapper = getMountedWrapper({
state: {
openproject_instance_url: 'http://openproject.com',
authorization_method: AUTH_METHOD.OAUTH2,
openproject_client_id: '',
openproject_client_secret: '',
nc_oauth_client: {
Expand Down Expand Up @@ -1640,6 +1646,9 @@ describe('AdminSettings.vue', () => {
nextcloud_client_id: 'something',
nextcloud_client_secret: 'something-else',
},
authorization_settings: {
targeted_audience_client_id: null,
},
},
})
confirmSpy = jest.spyOn(global.OC.dialogs, 'confirmDestructive')
Expand Down Expand Up @@ -1683,10 +1692,13 @@ describe('AdminSettings.vue', () => {
openproject_client_id: null,
openproject_client_secret: null,
openproject_instance_url: null,
authorization_method: null,
default_enable_navigation: false,
default_enable_unified_search: false,
setup_app_password: false,
oidc_provider: null,
setup_project_folder: false,
setup_app_password: false,
targeted_audience_client_id: null,
},
},
)
Expand All @@ -1703,6 +1715,9 @@ describe('AdminSettings.vue', () => {
nextcloud_client_id: 'something',
nextcloud_client_secret: 'something-else',
},
authorization_settings: {
targeted_audience_client_id: null,
},
app_password_set: true,
},
oPUserAppPassword: 'oPUserAppPassword',
Expand All @@ -1719,10 +1734,13 @@ describe('AdminSettings.vue', () => {
openproject_client_id: null,
openproject_client_secret: null,
openproject_instance_url: null,
authorization_method: null,
default_enable_navigation: false,
default_enable_unified_search: false,
oidc_provider: null,
setup_project_folder: false,
setup_app_password: false,
targeted_audience_client_id: null,
},
},
)
Expand Down
3 changes: 2 additions & 1 deletion tests/jest/components/PersonalSettings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { shallowMount, createLocalVue, mount } from '@vue/test-utils'
import PersonalSettings from '../../../src/components/PersonalSettings.vue'
import * as dialogs from '@nextcloud/dialogs'
import axios from '@nextcloud/axios'
import { AUTH_METHOD } from '../../../src/utils.js'

const localVue = createLocalVue()

Expand Down Expand Up @@ -90,7 +91,7 @@ describe('PersonalSettings.vue', () => {
describe('when username and token are given', () => {
beforeEach(async () => {
await wrapper.setData({
state: { user_name: 'test', token: '123', admin_config_ok: true },
state: { user_name: 'test', token: '123', admin_config_ok: true, authorization_method: AUTH_METHOD.OAUTH2 },
})
})
it('oAuth connect button is not displayed', () => {
Expand Down
3 changes: 2 additions & 1 deletion tests/jest/components/tab/EmptyContent.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* jshint esversion: 8 */
import { shallowMount, createLocalVue } from '@vue/test-utils'
import EmptyContent from '../../../../src/components/tab/EmptyContent.vue'
import { STATE } from '../../../../src/utils.js'
import { AUTH_METHOD, STATE } from '../../../../src/utils.js'
const localVue = createLocalVue()

describe('EmptyContent.vue', () => {
Expand Down Expand Up @@ -55,6 +55,7 @@ function getWrapper(propsData = {}) {
propsData: {
state: 'ok',
isAdminConfigOk: true,
authMethod: AUTH_METHOD.OAUTH2,
...propsData,
},
})
Expand Down

0 comments on commit 5a0c40a

Please sign in to comment.