Skip to content

Commit

Permalink
Fix unit test UI vue
Browse files Browse the repository at this point in the history
Signed-off-by: sagargurung1001@gmail.com <sagargurung1001@gmail.com>
  • Loading branch information
SagarGi committed Jul 2, 2024
1 parent 2d6eb10 commit 374abcd
Show file tree
Hide file tree
Showing 20 changed files with 2,483 additions and 2,420 deletions.
3,586 changes: 1,953 additions & 1,633 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "integration_openproject",
"version": "0.0.1",
"version": "2.6.3",
"description": "OpenProject Integration",
"main": "index.js",
"directories": {
Expand All @@ -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",
"test:unit": "jest --silent",
"test:unit:watch": "jest --watch --no-coverage"
},
"repository": {
Expand All @@ -38,7 +38,7 @@
"npm": "^8.0.0"
},
"dependencies": {
"@mdi/svg": "^7.3.67",
"@mdi/svg": "^7.3.67",
"@nextcloud/auth": "^2.3.0",
"@nextcloud/axios": "^2.5.0",
"@nextcloud/dialogs": "^5.3.4",
Expand All @@ -53,18 +53,18 @@
"vue": "^2.7.16",
"vue-material-design-icons": "^5.3.0"
},
"devDependencies": {
"devDependencies": {
"@babel/core": "^7.24.3",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/preset-env": "^7.24.3",
"@nextcloud/browserslist-config": "^3.0.0",
"@nextcloud/eslint-config": "^8.3.0",
"@nextcloud/stylelint-config": "^2.2.0",
"@nextcloud/webpack-vue-config": "^5.3.0",
"@nextcloud/browserslist-config": "^3.0.0",
"@nextcloud/eslint-config": "^8.4.1",
"@nextcloud/stylelint-config": "^2.3.0",
"@nextcloud/webpack-vue-config": "^6.0.1",
"@vue/test-utils": "^1.3.6",
"@vue/vue2-jest": "^29.2.6",
"eslint-webpack-plugin": "^4.0.1",
"stylelint-webpack-plugin": "^4.1.1",
"eslint-webpack-plugin": "^4.2.0",
"stylelint-webpack-plugin": "^5.0.1",
"vue-template-compiler": "^2.7.16",
"babel-jest": "^29.0.0",
"jest-environment-jsdom": "^29.7.0",
Expand Down
41 changes: 29 additions & 12 deletions tests/jest/components/AdminSettings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
import axios from '@nextcloud/axios'
import { createLocalVue, shallowMount, mount } from '@vue/test-utils'
import AdminSettings from '../../../src/components/AdminSettings.vue'
import * as initialState from '@nextcloud/initial-state'
import { F_MODES } from '../../../src/utils.js'
import * as dialogs from '@nextcloud/dialogs'

jest.mock('@nextcloud/axios')
jest.mock('@nextcloud/axios', () => {
const originalModule = jest.requireActual('@nextcloud/axios')
return {
__esModule: true,
...originalModule,
default: {
get: jest.fn(),
put: jest.fn(),
post: jest.fn(),
},
}
})
jest.mock('@nextcloud/l10n', () => ({
translate: jest.fn((app, msg) => msg),
getLanguage: jest.fn(() => ''),
Expand All @@ -18,6 +28,22 @@ jest.mock('@nextcloud/dialogs', () => ({
showSuccess: jest.fn(),
}))

jest.mock('@nextcloud/initial-state', () => {
const originalModule = jest.requireActual('@nextcloud/initial-state')
return {
__esModule: true,
...originalModule,
default: jest.fn(),
loadState: jest.fn(() => {
return {
openproject_instance_url: null,
oauth_client_id: null,
oauth_client_secret: null,
}
}),
}
})

const localVue = createLocalVue()

global.OC = {
Expand Down Expand Up @@ -56,7 +82,7 @@ const selectors = {
resetAllAppSettingsButton: '#reset-all-app-settings-btn',
defaultUserConfigurationsForm: '.default-prefs',
defaultEnableNavigation: '#default-prefs--link',
projectFolderSetupSwitch: '.checkbox-radio-switch__label',
projectFolderSetupSwitch: '[type="checkbox"]',
completeProjectFolderSetupWithGroupFolderButton: '[data-test-id="complete-with-project-folders-form-btn"]',
completeWithoutProjectFolderSetupButton: '[data-test-id="complete-without-project-folder-form-btn"]',
editProjectFolderSetup: '[data-test-id="edit-project-folder-setup"]',
Expand All @@ -77,15 +103,6 @@ const completeIntegrationState = {
},
}

// eslint-disable-next-line no-import-assign,import/namespace
initialState.loadState = jest.fn(() => {
return {
openproject_instance_url: null,
oauth_client_id: null,
oauth_client_secret: null,
}
})

describe('AdminSettings.vue', () => {
afterEach(() => {
jest.restoreAllMocks()
Expand Down
2 changes: 0 additions & 2 deletions tests/jest/components/OAuthConnectButton.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import OAuthConnectButton from '../../../src/components/OAuthConnectButton.vue'
// mocks
jest.mock('@nextcloud/axios', () => {
const originalModule = jest.requireActual('@nextcloud/axios')

return {
__esModule: true,
...originalModule,
Expand Down Expand Up @@ -101,7 +100,6 @@ describe('OAuthConnectButton.vue', () => {
axios.get.mockRejectedValueOnce(err)
})
it('shows an error', async () => {
console.log(wrapper.html())
dialogs.showError.mockImplementationOnce()
wrapper.find('button').trigger('click')
await localVue.nextTick()
Expand Down
16 changes: 12 additions & 4 deletions tests/jest/components/PersonalSettings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@

import { shallowMount, createLocalVue, mount } from '@vue/test-utils'
import PersonalSettings from '../../../src/components/PersonalSettings.vue'
import * as initialState from '@nextcloud/initial-state'
import * as dialogs from '@nextcloud/dialogs'
import axios from '@nextcloud/axios'

const localVue = createLocalVue()

// eslint-disable-next-line no-import-assign,import/namespace
initialState.loadState = jest.fn(() => {
jest.mock('@nextcloud/initial-state', () => {
const originalModule = jest.requireActual('@nextcloud/initial-state')
return {
admin_config_ok: true,
__esModule: true,
...originalModule,
default: jest.fn(),
loadState: jest.fn(() => {
return {
openproject_instance_url: null,
oauth_client_id: null,
oauth_client_secret: null,
}
}),
}
})

Expand Down
Loading

0 comments on commit 374abcd

Please sign in to comment.