From 9b82bd312be8dadc3179dd7e3f818fd31c03ba90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Tue, 15 Mar 2022 16:32:00 +0100 Subject: Add testing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ --- tests/javascript/models/contact.test.js | 62 +++++++++++++++++++++++++++++++++ tests/setup.js | 52 +++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 tests/javascript/models/contact.test.js create mode 100644 tests/setup.js (limited to 'tests') diff --git a/tests/javascript/models/contact.test.js b/tests/javascript/models/contact.test.js new file mode 100644 index 00000000..3a313b11 --- /dev/null +++ b/tests/javascript/models/contact.test.js @@ -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() + }) + +}) diff --git a/tests/setup.js b/tests/setup.js new file mode 100644 index 00000000..52d298e1 --- /dev/null +++ b/tests/setup.js @@ -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 -- cgit v1.2.3