Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/tasks.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tests/javascript')
-rw-r--r--tests/javascript/unit/OC.js11
-rw-r--r--tests/javascript/unit/components/Colorpicker.spec.js11
-rw-r--r--tests/javascript/unit/models/task.spec.js108
-rw-r--r--tests/javascript/unit/setup.js1
-rw-r--r--tests/javascript/unit/store/storeHelper.spec.js49
5 files changed, 180 insertions, 0 deletions
diff --git a/tests/javascript/unit/OC.js b/tests/javascript/unit/OC.js
new file mode 100644
index 00000000..fbf1fe97
--- /dev/null
+++ b/tests/javascript/unit/OC.js
@@ -0,0 +1,11 @@
+export class OC {
+
+ generateUrl(url) {
+ return ''
+ }
+
+ imagePath(app, img) {
+ return ''
+ }
+
+}
diff --git a/tests/javascript/unit/components/Colorpicker.spec.js b/tests/javascript/unit/components/Colorpicker.spec.js
new file mode 100644
index 00000000..485f0ba2
--- /dev/null
+++ b/tests/javascript/unit/components/Colorpicker.spec.js
@@ -0,0 +1,11 @@
+// import { shallowMount } from '@vue/test-utils'
+// import Colorpicker from '../../src/components/Colorpicker'
+
+describe('colorpicker.vue', () => {
+ 'use strict'
+
+ it('simulates test', () => {
+ // const wrapper = shallowMount(Colorpicker)
+ expect(true).toBe(true)
+ })
+})
diff --git a/tests/javascript/unit/models/task.spec.js b/tests/javascript/unit/models/task.spec.js
new file mode 100644
index 00000000..e3bbd717
--- /dev/null
+++ b/tests/javascript/unit/models/task.spec.js
@@ -0,0 +1,108 @@
+import Task from '../../../../src/models/task'
+
+describe('task', () => {
+ 'use strict'
+
+ const vCalendar = `
+ BEGIN:VCALENDAR\n
+ VERSION:2.0\n
+ PRODID:-//Nextcloud Tasks 0.11.3\n
+ BEGIN:VTODO\n
+ CREATED:20181119T183919\n
+ DTSTAMP:20190918T095816\n
+ LAST-MODIFIED:20190918T095816\n
+ UID:pwen4kz18g\n
+ SUMMARY:Test 1\n
+ END:VTODO\n
+ END:VCALENDAR`
+
+ it('Should set status to "COMPLETED" on completion.', () => {
+ const task = new Task(vCalendar, {})
+ task.complete = 100
+ expect(task.status).toEqual('COMPLETED')
+ expect(task.completed).toEqual(true)
+ expect(task.completedDate).not.toEqual(null)
+ })
+
+ it('Should set status to "NEEDS-ACTION" when complete is 0.', () => {
+ const task = new Task(vCalendar, {})
+ task.complete = 0
+ expect(task.status).toEqual('NEEDS-ACTION')
+ expect(task.completed).toEqual(false)
+ expect(task.completedDate).toEqual(null)
+ })
+
+ it('Should set status to "IN-PROCESS" when complete is >0 and <100.', () => {
+ const task = new Task(vCalendar, {})
+ task.complete = 50
+ expect(task.status).toEqual('IN-PROCESS')
+ expect(task.completed).toEqual(false)
+ expect(task.completedDate).toEqual(null)
+ })
+
+ it('Should set complete to 100 when status is "COMPLETED".', () => {
+ const task = new Task(vCalendar, {})
+ task.status = 'COMPLETED'
+ expect(task.complete).toEqual(100)
+ expect(task.completed).toEqual(true)
+ expect(task.completedDate).not.toEqual(null)
+ })
+
+ it('Should set complete to 0 when status is "NEEDS-ACTION".', () => {
+ const task = new Task(vCalendar, {})
+ task.complete = 100
+ task.status = 'NEEDS-ACTION'
+ expect(task.complete).toEqual(0)
+ expect(task.completed).toEqual(false)
+ expect(task.completedDate).toEqual(null)
+ })
+
+ it('Should set complete to >0 and <100 when status is "IN-PROCESS".', () => {
+ const task = new Task(vCalendar, {})
+ task.complete = 100
+ task.status = 'IN-PROCESS'
+ expect(task.complete).toBeGreaterThan(0)
+ expect(task.complete).toBeLessThan(100)
+ expect(task.completed).toEqual(false)
+ expect(task.completedDate).toEqual(null)
+ })
+
+ it('Should set complete to <100 when setting completed to false.', () => {
+ const task = new Task(vCalendar, {})
+ task.complete = 100
+ task.completed = false
+ expect(task.status).toEqual('IN-PROCESS')
+ expect(task.complete).toBeLessThan(100)
+ expect(task.completedDate).toEqual(null)
+ })
+
+ it('Should set complete to 100 when setting completed to true.', () => {
+ const task = new Task(vCalendar, {})
+ task.complete = 0
+ task.completed = true
+ expect(task.status).toEqual('COMPLETED')
+ expect(task.complete).toEqual(100)
+ expect(task.completedDate).not.toEqual(null)
+ })
+
+ it('Should set and get the uid', () => {
+ const task = new Task(vCalendar, {})
+ expect(task.uid).toEqual('pwen4kz18g')
+ task.uid = 'pwen4kz19g'
+ expect(task.uid).toEqual('pwen4kz19g')
+ })
+
+ it('Should set and get the summary', () => {
+ const task = new Task(vCalendar, {})
+ expect(task.summary).toEqual('Test 1')
+ task.summary = 'Test 2'
+ expect(task.summary).toEqual('Test 2')
+ })
+
+ it('Should set and get the priority', () => {
+ const task = new Task(vCalendar, {})
+ expect(task.priority).toEqual(null)
+ task.priority = 1
+ expect(task.priority).toEqual(1)
+ })
+})
diff --git a/tests/javascript/unit/setup.js b/tests/javascript/unit/setup.js
new file mode 100644
index 00000000..bbd0e636
--- /dev/null
+++ b/tests/javascript/unit/setup.js
@@ -0,0 +1 @@
+require('jsdom-global')()
diff --git a/tests/javascript/unit/store/storeHelper.spec.js b/tests/javascript/unit/store/storeHelper.spec.js
new file mode 100644
index 00000000..39c7a9f2
--- /dev/null
+++ b/tests/javascript/unit/store/storeHelper.spec.js
@@ -0,0 +1,49 @@
+import moment from 'moment'
+import MockDate from 'mockdate'
+import { sort } from '../../../../src/store/storeHelper'
+
+global.moment = moment
+
+const tasks = [
+ {
+ id: 1,
+ due: '20191119T183901'
+ },
+ {
+ id: 2,
+ due: '20181119T183901'
+ },
+ {
+ id: 3,
+ due: null
+ },
+ {
+ id: 4,
+ due: '20151119T183901'
+ },
+]
+
+describe('storeHelper', () => {
+ 'use strict'
+
+ it('Tests descending sort by due date.', () => {
+ const clonedTasks = tasks.slice(0)
+ const expectedTasks = [tasks[3], tasks[1], tasks[0], tasks[2]]
+ const receivedTasks = sort(clonedTasks, 'due', 0)
+ expect(receivedTasks).toEqual(expectedTasks)
+ })
+
+ it('Tests ascending sort by due date.', () => {
+ const clonedTasks = tasks.slice(0)
+ const expectedTasks = [tasks[2], tasks[0], tasks[1], tasks[3]]
+ const receivedTasks = sort(clonedTasks, 'due', 1)
+ expect(receivedTasks).toEqual(expectedTasks)
+ })
+
+ it("Tests if correct tasks are found for the 'current' collection.", () => {
+ // Set date to fixed value
+ MockDate.set(moment('20190101T123456', 'YYYYMMDDTHHmmss'))
+
+ MockDate.reset()
+ })
+})