summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@protonmail.com>2022-03-15 16:32:00 +0100
committerJohn Molakvoæ <skjnldsv@protonmail.com>2022-03-15 17:08:58 +0100
commit9b82bd312be8dadc3179dd7e3f818fd31c03ba90 (patch)
tree3b52c0c320d88bf36de51d661e318e40130c10f3 /tests
parent026ef7e01b48051d35ef97b018584884b5db9911 (diff)
Add testing
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/javascript/models/contact.test.js62
-rw-r--r--tests/setup.js52
2 files changed, 114 insertions, 0 deletions
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