Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[unit-tests] added unit tests for the AdminSettings component #66

Merged
merged 1 commit into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/components/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ export default {
SettingsTitle,
},

props: [],

data() {
return {
state: loadState('integration_openproject', 'admin-config'),
Expand All @@ -71,12 +69,6 @@ export default {
}
},

watch: {
},

mounted() {
},

methods: {
onInput() {
const that = this
Expand All @@ -103,8 +95,6 @@ export default {
+ ': ' + error.response.request.responseText
)
})
.then(() => {
})
},
},
}
Expand Down
75 changes: 75 additions & 0 deletions tests/jest/components/AdminSettings.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* jshint esversion: 8 */

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

const localVue = createLocalVue()

const selectors = {
oauthInstance: '#openproject-oauth-instance',
oauthClientId: '#openproject-client-id',
oauthClientSecret: '#openproject-client-secret',
}

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

describe('AdminSettings', () => {
describe('input readonly attribute on focus', () => {
it.each([
selectors.oauthClientId,
selectors.oauthClientSecret,
])('should have on readonly attribute after the input is focused', async (inputSelector) => {
const wrapper = getWrapper()
const inputField = wrapper.find(inputSelector)
expect(inputField.attributes().readonly).toBeTruthy()

await inputField.trigger('focus')

expect(inputField.attributes().readonly).toBeFalsy()

await inputField.trigger('blur')

expect(inputField.attributes().readonly).toBeFalsy()
})
})
describe('on input event', () => {
beforeEach(() => {
jest.clearAllMocks()
})
it.each([
selectors.oauthInstance,
selectors.oauthClientId,
selectors.oauthClientId,
])('should call "onInput" method', async (inputSelector) => {
const onInputSpy = jest.spyOn(AdminSettings.methods, 'onInput')
.mockImplementationOnce(() => {
})
const wrapper = getWrapper()
const inputField = wrapper.find(inputSelector)

await inputField.trigger('input')

expect(onInputSpy).toHaveBeenCalledTimes(1)
})
})
})

function getWrapper() {
return shallowMount(AdminSettings, {
localVue,
mocks: {
t: (app, msg) => msg,
generateUrl() {
return '/'
},
},
})
}