mirror of https://github.com/nextcloud/contacts
Add testing
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
This commit is contained in:
parent
026ef7e01b
commit
9b82bd312b
|
@ -51,3 +51,7 @@ jobs:
|
|||
run: |
|
||||
git status
|
||||
git --no-pager diff
|
||||
|
||||
- name: Testing
|
||||
run: |
|
||||
npm run test --if-present
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
const esModules = ['p-limit', 'yocto-queue'].join('|')
|
||||
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
moduleFileExtensions: ['js', 'vue', 'ts'],
|
||||
collectCoverageFrom: [
|
||||
'src/**/*.{js,vue}',
|
||||
'!**/node_modules/**',
|
||||
],
|
||||
coverageReporters: [
|
||||
'html',
|
||||
'text-summary',
|
||||
],
|
||||
setupFilesAfterEnv: [
|
||||
'<rootDir>/tests/setup.js',
|
||||
],
|
||||
testEnvironment: 'jsdom',
|
||||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest',
|
||||
'^.+\\.js$': 'babel-jest',
|
||||
'^.+\\.vue$': '@vue/vue2-jest',
|
||||
},
|
||||
transformIgnorePatterns: [`/node_modules/(?!${esModules})`],
|
||||
}
|
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
|
@ -30,7 +30,10 @@
|
|||
"lint": "eslint --ext .js,.vue src",
|
||||
"lint:fix": "eslint --ext .js,.vue src --fix",
|
||||
"stylelint": "stylelint src",
|
||||
"stylelint:fix": "stylelint src --fix"
|
||||
"stylelint:fix": "stylelint src --fix",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"test:coverage": "jest --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@mattkrick/sanitize-svg": "^0.3.1",
|
||||
|
@ -81,8 +84,13 @@
|
|||
"@nextcloud/stylelint-config": "^1.0.0-beta.0",
|
||||
"@nextcloud/typings": "^1.3.0",
|
||||
"@nextcloud/webpack-vue-config": "^4.3.2",
|
||||
"@types/jest": "^27.4.1",
|
||||
"@typescript-eslint/parser": "^5.12.1",
|
||||
"@vue/vue2-jest": "^27.0.0-alpha.4",
|
||||
"babel-jest": "^27.5.1",
|
||||
"eslint-import-resolver-typescript": "^2.5.0",
|
||||
"jest": "^27.5.1",
|
||||
"ts-jest": "^27.1.3",
|
||||
"ts-loader": "^9.2.6",
|
||||
"typescript": "^4.5.5"
|
||||
},
|
||||
|
|
|
@ -135,7 +135,7 @@ export default {
|
|||
/**
|
||||
* Open mailto: for contacts in a group
|
||||
*
|
||||
* @param {Object} group of contacts to be emailed
|
||||
* @param {object} group of contacts to be emailed
|
||||
*/
|
||||
emailGroup(group) {
|
||||
const emails = []
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
<template>
|
||||
<AppContentList>
|
||||
<div class="contacts-list__header"></div>
|
||||
<div class="contacts-list__header" />
|
||||
<VirtualList ref="scroller"
|
||||
class="contacts-list"
|
||||
data-key="key"
|
||||
|
|
|
@ -567,8 +567,9 @@ export default class Contact {
|
|||
}
|
||||
|
||||
toStringStripQuotes() {
|
||||
const regexp = /TYPE="([a-zA-Z-,]+)"/gm
|
||||
const regexp = /TYPE="([a-zA-Z-,]+)"/gmi
|
||||
const card = this.vCard.toString()
|
||||
return card.replaceAll(regexp, 'TYPE=$1')
|
||||
return card.replace(regexp, 'TYPE=$1')
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,8 +27,8 @@ import ActionToggleYear from '../components/Actions/ActionToggleYear'
|
|||
import zones from './zones'
|
||||
|
||||
// Load the default profile (for example, home or work) configured by the user
|
||||
const defaultProfileState = loadState('contacts', 'defaultProfile')
|
||||
const localesState = loadState('contacts', 'locales')
|
||||
const defaultProfileState = loadState('contacts', 'defaultProfile', 'HOME')
|
||||
const localesState = loadState('contacts', 'locales', false)
|
||||
const locales = localesState
|
||||
? localesState.map(({ code, name }) => ({
|
||||
id: code.toLowerCase().replace('_', '-'),
|
||||
|
|
|
@ -67,7 +67,7 @@ const addGroupedProperties = vCard => {
|
|||
* Fixes misbehaviour with TYPE quotes and separated commas
|
||||
* Seems to have been introduced with https://github.com/mozilla-comm/ical.js/pull/387
|
||||
*
|
||||
* @returns {Boolean} Whether or not the design set has been altered.
|
||||
* @return {boolean} Whether or not the design set has been altered.
|
||||
*/
|
||||
const setTypeMultiValueSeparateDQuote = () => {
|
||||
if (
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
import Contact from '../../../src/models/contact'
|
||||
import { Property } from 'ical.js'
|
||||
|
||||
const getPropertyLines = (property, vcard) => {
|
||||
return vcard.match(new RegExp(`^${property}[;:].*`, 'gmi'))
|
||||
}
|
||||
|
||||
describe('Test stripping quotes from TYPE', () => {
|
||||
|
||||
let contact
|
||||
let property
|
||||
|
||||
beforeEach(() => {
|
||||
contact = new Contact(`
|
||||
BEGIN:VCARD
|
||||
VERSION:3.0
|
||||
UID:123456789-123465-123456-123456789
|
||||
FN:Test contact
|
||||
END:VCARD`.replace(/\t/gmi, '')
|
||||
)
|
||||
property = contact.vCard.addPropertyWithValue('TEl', '+00 123 456 789')
|
||||
})
|
||||
|
||||
test('Test stripping quotes from SINGLE TYPE', (done) => {
|
||||
property.setParameter('type', ['VOICE'])
|
||||
const line = getPropertyLines('TEL', contact.toStringStripQuotes())[0]
|
||||
|
||||
expect(line).toStrictEqual('TEL;TYPE=VOICE:+00 123 456 789')
|
||||
done()
|
||||
})
|
||||
|
||||
test('Test stripping quotes from MULTIPLE TYPES', (done) => {
|
||||
property.setParameter('type', ['WORK', 'VOICE'])
|
||||
const line = getPropertyLines('TEL', contact.toStringStripQuotes())[0]
|
||||
|
||||
expect(line).toStrictEqual('TEL;TYPE=WORK,VOICE:+00 123 456 789')
|
||||
done()
|
||||
})
|
||||
|
||||
test('Test stripping quotes from MULTIPLE SPLIT TYPES', (done) => {
|
||||
property.setParameter('type', ['WORK,VOICE'])
|
||||
const line = getPropertyLines('TEL', contact.toStringStripQuotes())[0]
|
||||
|
||||
expect(line).toStrictEqual('TEL;TYPE=WORK,VOICE:+00 123 456 789')
|
||||
done()
|
||||
})
|
||||
|
||||
test('Test stripping quotes from MULTIPLE SPLIT TYPES and MULTIPLE PROPERTIES', (done) => {
|
||||
const property2 = contact.vCard.addPropertyWithValue('TEl', '+99 876 543 210')
|
||||
property.setParameter('type', ['WORK,VOICE'])
|
||||
property2.setParameter('type', ['HOME'])
|
||||
|
||||
const lines = getPropertyLines('TEL', contact.toStringStripQuotes())
|
||||
|
||||
expect(lines).toStrictEqual([
|
||||
'TEL;TYPE=WORK,VOICE:+00 123 456 789',
|
||||
'TEL;TYPE=HOME:+99 876 543 210',
|
||||
])
|
||||
done()
|
||||
})
|
||||
|
||||
})
|
|
@ -0,0 +1,52 @@
|
|||
// eslint-disable-next-line node/no-extraneous-import
|
||||
import 'regenerator-runtime/runtime'
|
||||
import Vue from 'vue'
|
||||
|
||||
jest.mock('@nextcloud/l10n', () => ({
|
||||
translate: (app, text) => text,
|
||||
translatePlural: (app, text) => text,
|
||||
}))
|
||||
|
||||
jest.mock('@nextcloud/initial-state', () => ({
|
||||
loadState: (app, key, fallback) => fallback,
|
||||
}))
|
||||
|
||||
global.appName = 'contacts'
|
||||
|
||||
global.OC = {
|
||||
requestToken: '123',
|
||||
webroot: '/nc-webroot',
|
||||
coreApps: [
|
||||
'core',
|
||||
],
|
||||
config: {
|
||||
modRewriteWorking: true,
|
||||
},
|
||||
dialogs: {
|
||||
},
|
||||
isUserAdmin() {
|
||||
return true
|
||||
},
|
||||
getLanguage() {
|
||||
return 'en-GB'
|
||||
},
|
||||
getLocale() {
|
||||
return 'en_GB'
|
||||
},
|
||||
|
||||
MimeType: {
|
||||
getIconUrl: jest.fn(),
|
||||
},
|
||||
}
|
||||
|
||||
global.OCA = {}
|
||||
global.OCP = {}
|
||||
|
||||
// TODO: use nextcloud-l10n lib once https://github.com/nextcloud/nextcloud-l10n/issues/271 is solved
|
||||
global.t = jest.fn().mockImplementation((app, text) => text)
|
||||
global.n = jest.fn().mockImplementation((app, text) => text)
|
||||
|
||||
Vue.prototype.t = global.t
|
||||
Vue.prototype.n = global.n
|
||||
Vue.prototype.OC = OC
|
||||
Vue.prototype.OCA = OCA
|
Loading…
Reference in New Issue